Skip to content

Instantly share code, notes, and snippets.

@Dimitrionian
Last active October 20, 2021 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimitrionian/40be4cfd25bd28116d90f2cb6c034ba5 to your computer and use it in GitHub Desktop.
Save Dimitrionian/40be4cfd25bd28116d90f2cb6c034ba5 to your computer and use it in GitHub Desktop.
Permission class for checking previously assigned permissions
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