-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add group admin to list groups (#4779)
- Loading branch information
1 parent
a1600c5
commit 391b377
Showing
3 changed files
with
93 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,12 @@ | |
from integrations.lead_tracking.hubspot.constants import HUBSPOT_COOKIE_NAME | ||
from organisations.invites.models import Invite, InviteLink | ||
from organisations.models import Organisation, OrganisationRole | ||
from users.models import FFAdminUser, HubspotTracker, UserPermissionGroup | ||
from users.models import ( | ||
FFAdminUser, | ||
HubspotTracker, | ||
UserPermissionGroup, | ||
UserPermissionGroupMembership, | ||
) | ||
|
||
|
||
def test_join_organisation( | ||
|
@@ -867,3 +872,61 @@ def test_send_reset_password_emails_rate_limit_resets_after_password_reset( | |
|
||
# Then - we should receive another email | ||
assert len(mail.outbox) == 1 | ||
|
||
|
||
def test_list_user_groups( | ||
organisation: Organisation, | ||
admin_client: APIClient, | ||
django_assert_num_queries: DjangoAssertNumQueries, | ||
) -> None: | ||
# Given | ||
user1 = FFAdminUser.objects.create(email="[email protected]") | ||
user2 = FFAdminUser.objects.create(email="[email protected]") | ||
|
||
user1.add_organisation(organisation) | ||
user2.add_organisation(organisation) | ||
|
||
user_permission_group_1 = UserPermissionGroup.objects.create( | ||
organisation=organisation, name="group1" | ||
) | ||
user_permission_group_2 = UserPermissionGroup.objects.create( | ||
organisation=organisation, name="group2" | ||
) | ||
|
||
UserPermissionGroupMembership.objects.create( | ||
ffadminuser=user1, userpermissiongroup=user_permission_group_1, group_admin=True | ||
) | ||
UserPermissionGroupMembership.objects.create( | ||
ffadminuser=user2, userpermissiongroup=user_permission_group_2, group_admin=True | ||
) | ||
UserPermissionGroupMembership.objects.create( | ||
ffadminuser=user1, userpermissiongroup=user_permission_group_2 | ||
) | ||
|
||
url = reverse( | ||
"api-v1:organisations:organisation-groups-list", args=[organisation.id] | ||
) | ||
|
||
# When | ||
with django_assert_num_queries(7): | ||
response = admin_client.get(url) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
response_json = response.json() | ||
assert response_json["count"] == 2 | ||
|
||
group_1 = response_json["results"][0] | ||
group_1_users = group_1["users"] | ||
assert len(group_1_users) == 1 | ||
assert group_1_users[0]["id"] == user1.pk | ||
assert group_1_users[0]["group_admin"] is True | ||
|
||
group_2 = response_json["results"][1] | ||
group_2_users = group_2["users"] | ||
assert len(group_2_users) == 2 | ||
assert tuple((user["id"], user["group_admin"]) for user in group_2_users) == ( | ||
(user1.pk, False), | ||
(user2.pk, True), | ||
) |
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