Skip to content

Commit

Permalink
[FIXES #11995] Implement endpoint to unregister as a project manager
Browse files Browse the repository at this point in the history
  • Loading branch information
RegisSinjari committed Mar 19, 2024
1 parent 2a6e4ab commit b2c41f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion geonode/people/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ def test_remove_self_from_group_manager_all(self):
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": "ALL"},
content_type="application/json",
)
self.assertTrue(response.status_code == 200)
# check that bobby is manager no more
Expand Down Expand Up @@ -959,6 +960,7 @@ def test_remove_self_as_group_manager_list(self):
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": [group.group_id for group in self.group_profiles[:3]]},
content_type="application/json",
)
self.assertTrue(response.status_code == 200)
# check that bobby is no more manager in the first groups
Expand Down Expand Up @@ -989,6 +991,7 @@ def test_remove_user_as_group_manager_empty(self):
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": ""},
content_type="application/json",
)
self.assertTrue(response.status_code == 400)
self.assertTrue("No groups IDs were provided" in response.json()["error"])
Expand Down Expand Up @@ -1017,11 +1020,12 @@ def test_remove_user_as_group_manager_of_invalid_groups(self):
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": [newgroup.group_id]},
content_type="application/json",
)
self.assertTrue(response.status_code == 400)
# check that bobby is still manager at all groups
for group in self.group_profiles:
self.assertTrue(bobby in group.get_managers())
# assert the invalid group is in the payload
self.assertTrue("Following groups were invalid" in response.json()["error"])
self.assertTrue("User is not manager of the following groups" in response.json()["error"])
self.assertTrue(f"{newgroup.group_id}" in response.json()["error"])
2 changes: 1 addition & 1 deletion geonode/people/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def remove_from_group_manager(self, request, pk=None):
if target_ids == "ALL":
user_groups = GroupProfile.groups_for_user(user)
else:
# target_ids = set(map(int, target_ids.split(",")))
target_ids = set(target_ids)
user_groups = GroupProfile.groups_for_user(user).filter(group_id__in=target_ids)
# check for groups that user is not part of:
invalid_groups.extend(target_ids - set(ug.group_id for ug in user_groups))
Expand Down

0 comments on commit b2c41f1

Please sign in to comment.