Fix team add/invite logic around when an invite is required

We were accidentally skipping the invite if the user was a member of *any* organization, rather than the specific organization (as intended)

Fixes https://jira.coreos.com/browse/QUAY-880
This commit is contained in:
Joseph Schorr 2018-03-16 17:13:27 -04:00
parent 019ad01e70
commit c4debe011c
2 changed files with 48 additions and 5 deletions

View file

@ -128,11 +128,13 @@ def add_or_invite_to_team(inviter, team, user_obj=None, email=None, requires_inv
raise InvalidTeamMemberException('Cannot add the specified robot to this team, ' +
'as it is not a member of the organization')
else:
Org = User.alias()
found = User.select(User.username)
found = found.where(User.username == user_obj.username).join(TeamMember).join(Team)
found = found.join(Org, on=(Org.username == orgname)).limit(1)
requires_invite = not any(found)
query = (TeamMember
.select()
.where(TeamMember.user == user_obj)
.join(Team)
.join(User)
.where(User.username == orgname, User.organization == True))
requires_invite = not any(query)
# If we have a valid user and no invite is required, simply add the user to the team.
if user_obj and not requires_invite: