-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPIpermissions.py
33 lines (26 loc) · 999 Bytes
/
APIpermissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from rest_framework.permissions import BasePermission
from .serializers import Project
class ProjectPermission(BasePermission):
def has_permission(self, request, view):
"""
Should simply return, or raise a 403 response.
"""
is_authorized = False
project = Project.objects.get(pk=view.kwargs["project_pk"])
# TODO: Check users project roles.
if request.user == project.owner:
is_authorized = True
elif request.user in project.authorized.all():
is_authorized = True
print("Is authorized: {}".format(is_authorized))
return is_authorized
class AdminPermission(BasePermission):
def has_permission(self, request, view):
"""
Should simply return, or raise a 403 response.
"""
is_authorized = False
if request.user.is_superuser:
is_authorized = True
print("Is authorized: {}".format(is_authorized))
return is_authorized