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


class IsDriOrNoPost(permissions.BasePermission):
    """
Florent Chehab's avatar
Florent Chehab committed
7
8
    Permission to disallow POST to viewset if request user is not a
    member of the DRI group or a staff.
Florent Chehab's avatar
Florent Chehab committed
9
10
11
    """

    def has_permission(self, request, view):
12
        if request.method == "POST":
Florent Chehab's avatar
Florent Chehab committed
13
14
15
            return is_member("DRI", request.user) or request.user.is_staff

        return True