Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #9970] User has perms return 403 #9982

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion geonode/base/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,24 @@ def __call__(self):
return self

def has_permission(self, request, view):
from geonode.base.models import ResourceBase
queryset = self._queryset(view)

if request.user.is_superuser:
return True

if view.kwargs.get('pk'):
# if a single resource is called, we check the perms for that resource
res = get_object_or_404(queryset.model, pk=view.kwargs.get('pk'))
res = get_object_or_404(ResourceBase, pk=view.kwargs.get('pk'))
# if the request is for a single resource, we take the specific or the default. If none is defined we keep the original one defined above
resource_type_specific_perms = self.perms_dict.get(res.get_real_instance().resource_type, self.perms_dict.get('default', {}))
perms = resource_type_specific_perms.get(request.method, []) or self.get_required_permissions(request.method, queryset.model)

# getting the user permission for that resource
resource_perms = list(res.get_user_perms(request.user))
if getattr(res, 'get_real_instance', None):
resource_perms.extend(list(res.get_real_instance().get_user_perms(request.user)))

groups = get_groups_with_perms(res, attach_perms=True)
# we are making this because the request.user.groups sometimes returns empty si is not fully reliable
for group, perm in groups.items():
Expand Down