Skip to content

Commit

Permalink
[Fixes #11320] API V1 delivers information on users that shouldn't be… (
Browse files Browse the repository at this point in the history
#11321)

* [Fixes #11320] API V1 delivers information on users that shouldn't be visible

* Fix black and flake8

* Fix black and flake8

* Fix black and flake8

* Fix black and flake8

* [Fixes #11320] API V1 delivers information on users that shouldn't be visible

---------

Co-authored-by: Giovanni Allegri <[email protected]>
  • Loading branch information
mattiagiupponi and giohappy authored Aug 16, 2023
1 parent 3fa9a86 commit c84f55e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions geonode/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ class OwnersResource(TypeFilteredResource):

full_name = fields.CharField(null=True)

def apply_filters(self, request, applicable_filters):
"""filter by group if applicable by group functionality"""

semi_filtered = super().apply_filters(request, applicable_filters)

if request.user and not request.user.is_superuser:
semi_filtered = get_available_users(request.user)

return semi_filtered

def dehydrate_full_name(self, bundle):
return bundle.obj.get_full_name() or bundle.obj.username

Expand Down
8 changes: 7 additions & 1 deletion geonode/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_owners_lockdown(self):
self.api_client.client.login(username="bobby", password="bob")
resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)["objects"]), 9)
self.assertEqual(len(self.deserialize(resp)["objects"]), 6)
# Returns limitted info about other users
bobby = get_user_model().objects.get(username="bobby")
owners = self.deserialize(resp)["objects"]
Expand All @@ -332,6 +332,12 @@ def test_owners_lockdown(self):
self.assertIsNone(owner.get("email"))
self.assertIsNone(owner.get("first_name"))

# now test with logged in admin
self.api_client.client.login(username="admin", password="admin")
resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)["objects"]), 9)

@override_settings(API_LOCKDOWN=True)
def test_groups_lockdown(self):
groups_list_url = reverse("api_dispatch_list", kwargs={"api_name": "api", "resource_name": "groups"})
Expand Down

0 comments on commit c84f55e

Please sign in to comment.