You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
773 B
18 lines
773 B
from rest_framework.permissions import BasePermission
|
|
# from drf_keycloak_auth.authentication import KeycloakAuthentication
|
|
from django.conf import settings
|
|
|
|
|
|
class UserPermission(BasePermission):
|
|
def has_permission(self, request, view):
|
|
kk_profile = request.auth
|
|
kk_roles = kk_profile.get('resource_access',{}).get('postnet',{}).get('roles',[])
|
|
if request.method not in ['GET']:
|
|
# if view.action in [
|
|
# 'update_fact', 'update_postamat_id', 'update_status', 'retrieve',
|
|
# 'update', 'partial_update', 'destroy', 'create',
|
|
# ]:
|
|
return settings.KK_EDITOR_ROLE in kk_roles
|
|
else:
|
|
return settings.KK_EDITOR_ROLE in kk_roles or settings.KK_VIEWER_ROLE in kk_roles
|