-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(organization): assign invitations to members correctly TASK-1600 (#…
…5541) ### 📣 Summary Fixed an issue where invitations were not properly assigned to the correct organization members and ensured that invitations reflect the intended recipient and organization. ### 📖 Description An issue caused invitations to be incorrectly assigned, leading to inconsistencies in organization membership management. This fix ensures that invitations are correctly linked to the intended recipients, preventing access errors or misdirected invitations.
- Loading branch information
1 parent
aa138a9
commit 9fb0cdb
Showing
4 changed files
with
125 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,11 +60,11 @@ def setUp(self): | |
'invitees': ['bob', '[email protected]'] | ||
} | ||
|
||
def _create_invite(self, user): | ||
def _create_invite(self, invited_by): | ||
""" | ||
Helper method to create invitations | ||
""" | ||
self.client.force_login(user) | ||
self.client.force_login(invited_by) | ||
return self.client.post(self.list_url, data=self.invitation_data) | ||
|
||
def _update_invite(self, user, guid, status): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,18 +43,22 @@ def setUp(self): | |
}, | ||
) | ||
|
||
def _create_invite(self, user): | ||
def _create_invite(self, invited_by: 'User', invitees=None): | ||
""" | ||
Helper method to create and accept invitations | ||
""" | ||
invitation_data = { | ||
'invitees': ['registered_invitee', '[email protected]'] | ||
} | ||
if not invitees: | ||
invitation_data = { | ||
'invitees': ['registered_invitee', '[email protected]'] | ||
} | ||
else: | ||
invitation_data = {'invitees': invitees} | ||
|
||
list_url = reverse( | ||
self._get_endpoint('organization-invites-list'), | ||
kwargs={'organization_id': self.organization.id}, | ||
) | ||
self.client.force_login(user) | ||
self.client.force_login(invited_by) | ||
self.client.post(list_url, data=invitation_data) | ||
|
||
@data( | ||
|
@@ -192,3 +196,37 @@ def test_post_request_is_not_allowed(self, user_role, expected_status): | |
data = {'role': 'admin'} | ||
response = self.client.post(self.list_url, data) | ||
self.assertEqual(response.status_code, expected_status) | ||
|
||
def test_invitation_is_correctly_assigned_in_member_list(self): | ||
|
||
bob_org = self.bob.organization | ||
bob_org.mmo_override = True | ||
bob_org.save(update_fields=['mmo_override']) | ||
|
||
# Let someuser invite bob to join their org | ||
self._create_invite(invited_by=self.someuser, invitees=['bob']) | ||
|
||
# Look at bob's membership detail endpoint in bob's org, | ||
# someuser's invite should not be there | ||
self.client.force_login(self.bob) | ||
bob_org_members_list_url = reverse( | ||
self._get_endpoint('organization-members-list'), | ||
kwargs={'organization_id': bob_org.id}, | ||
) | ||
response = self.client.get(bob_org_members_list_url) | ||
# The first member should be bob | ||
assert response.data['results'][0]['user__username'] == 'bob' | ||
assert response.data['results'][0]['invite'] == {} | ||
|
||
# Look at bob's membership detail endpoint in someother's org, | ||
# someuser's invite should **BE** there | ||
self.client.force_login(self.someuser) | ||
someuser_org_members_list_url = reverse( | ||
self._get_endpoint('organization-members-list'), | ||
kwargs={'organization_id': self.organization.id}, | ||
) | ||
response = self.client.get(someuser_org_members_list_url) | ||
|
||
# The last invite should be bob's one | ||
assert response.data['results'][-1]['invite']['invitee'] == 'bob' | ||
assert response.data['results'][-1]['invite']['status'] == 'pending' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters