Skip to content

Commit

Permalink
[FIXES #11995] Implement endpoint to unregister as a project managerg…
Browse files Browse the repository at this point in the history
…roup.group_id
  • Loading branch information
RegisSinjari committed Mar 19, 2024
1 parent d17a86c commit 2a6e4ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions geonode/people/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def test_remove_self_as_group_manager_list(self):
# call the api that removes him from all assigned groups as manager
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": ",".join([str(group.group_id) for group in self.group_profiles[:3]])},
data={"groups": [group.group_id for group in self.group_profiles[:3]]},
)
self.assertTrue(response.status_code == 200)
# check that bobby is no more manager in the first groups
Expand Down Expand Up @@ -991,7 +991,7 @@ def test_remove_user_as_group_manager_empty(self):
data={"groups": ""},
)
self.assertTrue(response.status_code == 400)
self.assertTrue("Empty payload" in response.json()["error"])
self.assertTrue("No groups IDs were provided" in response.json()["error"])
# check that bobby is still manager at all groups
for group in self.group_profiles:
self.assertTrue(bobby in group.get_managers())
Expand All @@ -1016,7 +1016,7 @@ def test_remove_user_as_group_manager_of_invalid_groups(self):
# call the api that removes him from all assigned groups as manager"
response = self.client.post(
path=f"{reverse('users-list')}/{bobby.pk}/remove_from_group_manager",
data={"groups": newgroup.group_id},
data={"groups": [newgroup.group_id]},
)
self.assertTrue(response.status_code == 400)
# check that bobby is still manager at all groups
Expand Down
10 changes: 5 additions & 5 deletions geonode/people/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,19 @@ def groups(self, request, pk=None):
@action(detail=True, methods=["post"])
def remove_from_group_manager(self, request, pk=None):
user = self.get_object() # admini
target_ids = request.data.get("groups", "")
target_ids = request.data.get("groups", [])
user_groups = []
invalid_groups = []

if not target_ids:
return Response({"error": "Empty payload"}, status=400)
return Response({"error": "No groups IDs were provided"}, status=400)

if target_ids == "ALL":
user_groups = GroupProfile.groups_for_user(user)
else:
target_ids = set(map(int, target_ids.split(",")))
# target_ids = set(map(int, target_ids.split(",")))
user_groups = GroupProfile.groups_for_user(user).filter(group_id__in=target_ids)
# check for invalid groups:
# check for groups that user is not part of:
invalid_groups.extend(target_ids - set(ug.group_id for ug in user_groups))

for group in user_groups:
Expand All @@ -276,7 +276,7 @@ def remove_from_group_manager(self, request, pk=None):
payload = {"success": f"User removed as a group manager from : {', '.join(group_names)}"}

if invalid_groups:
payload["error"] = f"Following groups were invalid : {invalid_groups}"
payload["error"] = f"User is not manager of the following groups: : {invalid_groups}"
return Response(payload, status=400)
return Response(payload, status=200)

Expand Down

0 comments on commit 2a6e4ab

Please sign in to comment.