New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not invite manager as member when creating a team. #3308
Conversation
To solve the problem we have to make sure that the team is created properly and the manager is added as manager before inviting members from the usernames list.
@@ -56,10 +56,6 @@ def defined_with(options, inviter=nil) | |||
tags = [options[:slug], options[:name], options[:tags]].join(',') | |||
self.tags = Tag.create_from_text(tags) | |||
|
|||
users = User.find_or_create_in_usernames(potential_members(options[:usernames])) if options[:usernames] | |||
users = options[:users] if options[:users] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a place where options[:users]
were being used, so I dropped it. Thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's probably left-over from something.
@@ -29,8 +29,10 @@ def test_profile_shows_progress | |||
|
|||
def test_display_team_invites_only_in_users_own_profile | |||
new_user = create_user(username: 'new_user', github_id: 456) | |||
attributes = { slug: 'some-team', name: 'Some Name', usernames: 'new_user' } | |||
Team.by(@user).defined_with(attributes, @user).save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a good reason, but why does this* need to change?
It seems like creating a team with existing members is a useful thing to be able to do in one shot.
This would probably require different changes to lib/exercism/team.rb
but won't require changing everything else.
* In all these files, not specifically here in profile_test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like creating a team with existing members is a useful thing to be able to do in one shot.
I would say yes, but we would need to wrap things in a transaction and start rescuing from everywhere. The alternative would be checking inside the Team
class if the instance has been persisted and then invite its potential members. I don't really like this alternative because it should not be the responsibility of the team class to check for this stuff (I may be wrong in my assumption).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create the invitations using an after_save
callback?
It's probably not the responsibility of a Team
class, but that's not all it is any more.
Don't let what it's called distract you from what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I don't really like the idea that just because it is already doing too much we can just add more behaviour into the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome back @kytrinyx :)
Can I have fresh eyes on this? I like the current state of the code, but a new abstraction for creating a team and inviting members would also be valuable, I just can't come up with a good name for this "service".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, yes (sorry! it's taken forever to catch up with everything).
Looking now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of an after save, I do like the current state of the code, and agree that a new abstraction would be even better. If we could name it.
I honestly can't think of anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a more elegant solution.
(This may be an unreasonable request.)
I was tempted to delegated everything to the |
If you think your current solution is fine and you don't think the things I'm suggesting are fun or interesting, that's OK, I'll happily switch my review to 'approved.' And I don't think your current solution is "bad" but I do think it leaves the code messier than it was to start with, and down that path lies all kinds of horrible.
That seems like a step in the right direction. The trick is to not stop once you've put it in there but continue through the extraction of better defined objects. The Team class is already doing too much, putting a little more in there will hopefully make this more obvious and lead to the extraction of some more useful objects. By spreading the responsibilities out all through the test files and the controller it effectively hides the responsibilities of the ❤️ |
@Insti Do you think it is not the job of the controller to check if the team is valid and then invite it's users after persisting it? Or do you think an abstraction that deal with this would be better?
I agree and disagree at the same time. I would say the code is less practical, but more explicit. Also, right now we only try to send invites if the team is really persisted (which was not happening before).
I would say it is already obvious, right? I think that if we want to take the path to make things simpler it would be better to just extract this to a proper object (which I'm not against at all). And thank you for the amazing feedback, it really helps to have these kind of conversations. ❤️ |
I don't think it's the job of the controller to do that, the controller's job is to take the http request, send the parameters to the right object and return some kind of http response. I would prefer the team validation and invitations were dealt with by an abstraction.
This is a good change.
If you want to do it that way that's up to you. I think we both agree there are some things that need extracting here, so extract away!
❤️ |
Wanted to bump this now that the holidays are over. Is there time for this? |
Sorry for taking so long to answer, I think I can say I'm officially back. Should I close this PR and try a different approach? |
You could keep this PR and try a different approach... force push works well for this. :) Or keep this approach, name it alternative, and do another to compare with... up to you @bernardoamc so your choice. |
That's true! I don't have a good alternative so far though, what do you think @kotp? Would love to hear your opinion on a proper solution to this problem. :) |
I think we should keep what we have for now. I think it is better than it was, even though it is a bit more verbose. |
I would love to come up with a better abstraction to clean this up, but as an upside I think the code more reliable than it was. |
I think it is time for this to come in. We can think about the abstraction at some later date. Thanks @bernardoamc !! |
The tests are failing after merging this. @bernardoamc would you have a chance to look into it today? |
Weird, maybe we should have rebased before the merge? I will take a look @kytrinyx. 👍 |
I do have a branch to revert, in preparation... |
Fixes #3110
Right now the manager is already being added as a member, so we don't need to send the invite.
To solve the problem we have to make sure that the team is created properly and the manager is added as manager before inviting members from the usernames list.