Skip to content

[change] Remove redundant code for checking view permissions #111

@ManishShah120

Description

@ManishShah120

class HasGetMethodPermission(BasePermission):
def has_permission(self, request, view):
return self.check_permission(request)
def has_object_permission(self, request, view, obj):
return self.check_permission(request)
def check_permission(self, request):
user = request.user
app_label = Topology._meta.app_label.lower()
model = Topology._meta.object_name.lower()
change_perm = f'{app_label}.change_{model}'
view_perm = f'{app_label}.view_{model}'
if user.is_authenticated:
if user.is_superuser or request.method != 'GET':
return True
if request.method == 'GET' and (
user.has_permission(change_perm) or user.has_permission(view_perm)
):
return True
return False

I guess, this portion of code does the same thing as what we did recently in this PR openwisp/openwisp-users#251

So, will it not better if we simply import it from there?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions