From b2c41f13dead6960246d880dd9fc13e9f95e3f1c Mon Sep 17 00:00:00 2001 From: RegisSinjari Date: Tue, 19 Mar 2024 15:20:29 +0100 Subject: [PATCH] [FIXES #11995] Implement endpoint to unregister as a project manager --- geonode/people/tests.py | 6 +++++- geonode/people/views.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/geonode/people/tests.py b/geonode/people/tests.py index dba1ee65cdf..78aeb3067b9 100644 --- a/geonode/people/tests.py +++ b/geonode/people/tests.py @@ -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 @@ -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 @@ -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"]) @@ -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"]) diff --git a/geonode/people/views.py b/geonode/people/views.py index e677982eb35..94eb749e6d8 100644 --- a/geonode/people/views.py +++ b/geonode/people/views.py @@ -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))