Last active
October 20, 2021 11:53
-
-
Save Dimitrionian/40be4cfd25bd28116d90f2cb6c034ba5 to your computer and use it in GitHub Desktop.
Permission class for checking previously assigned permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IsPermittedAccess(BasePermission): | |
@staticmethod | |
def get_code_name(view, request, permission_map): | |
model_name = view.queryset.model._meta.model_name | |
app_label = view.queryset.model._meta.app_label | |
return '{}.{}_{}'.format(app_label, | |
permission_map.get(request.method), | |
model_name) | |
def has_permission(self, request, view): | |
return request.user.has_perm( | |
IsPermittedAccess.get_code_name(view, request, PERMISSION_MAP) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment