2022-10-08 11:21:53 +03:00
|
|
|
from rest_framework import permissions
|
|
|
|
|
|
|
|
|
2022-10-08 19:31:01 +03:00
|
|
|
class IsWorker(permissions.BasePermission):
|
|
|
|
"""
|
|
|
|
Checks if request user is worker(not hr or admin)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
|
|
|
if request.method in permissions.SAFE_METHODS:
|
|
|
|
return True
|
|
|
|
return not request.user.is_manager
|
|
|
|
|
|
|
|
|
2022-10-08 11:21:53 +03:00
|
|
|
class IsManager(permissions.BasePermission):
|
|
|
|
"""
|
|
|
|
Checks if request user is an admin or hr
|
|
|
|
"""
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
|
|
|
if request.method in permissions.SAFE_METHODS:
|
|
|
|
return True
|
|
|
|
return request.user.is_manager
|
|
|
|
|
|
|
|
|
|
|
|
class IsAdmin(permissions.BasePermission):
|
|
|
|
"""
|
2022-10-08 19:31:01 +03:00
|
|
|
Checks if request user is an admin
|
2022-10-08 11:21:53 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
|
|
|
if request.method in permissions.SAFE_METHODS:
|
|
|
|
return True
|
|
|
|
return request.user.is_admin
|