isDriOrReadOnly.py 471 Bytes
Newer Older
1
from rest_framework import permissions
Florent Chehab's avatar
Florent Chehab committed
2
from backend_app.utils import is_member
3
4
5
6


class IsDriOrReadOnly(permissions.BasePermission):
    """
Florent Chehab's avatar
Florent Chehab committed
7
8
    Permission to make a viewset readonly unless the request user
    is a member of the DRI group or staff.
9
10
11
12
13
14
15
    """

    def has_permission(self, request, view):
        if request.method in permissions.SAFE_METHODS:
            return True
        else:
            return is_member("DRI", request.user) or request.user.is_staff