Skip to content

permissions

CanEditReport

Bases: permissions.BasePermission

Custom permission to only allow owners of an object to edit it.

Source code in reports/permissions.py
18
19
20
21
22
23
24
25
26
27
class CanEditReport(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """

    def has_permission(self, request, view):
        return request.user and request.user.is_authenticated

    def has_object_permission(self, request, view, obj: Report):
        return obj.can_edit(request.user)

has_object_permission(request, view, obj)

Source code in reports/permissions.py
26
27
def has_object_permission(self, request, view, obj: Report):
    return obj.can_edit(request.user)

has_permission(request, view)

Source code in reports/permissions.py
23
24
def has_permission(self, request, view):
    return request.user and request.user.is_authenticated

CanViewReport

Bases: permissions.BasePermission

Custom permission to only allow owners of an object to edit it.

Source code in reports/permissions.py
 6
 7
 8
 9
10
11
12
13
14
15
class CanViewReport(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """

    def has_permission(self, request, view):
        return request.user and request.user.is_authenticated

    def has_object_permission(self, request, view, obj: Report):
        return obj.can_view(request.user)

has_object_permission(request, view, obj)

Source code in reports/permissions.py
14
15
def has_object_permission(self, request, view, obj: Report):
    return obj.can_view(request.user)

has_permission(request, view)

Source code in reports/permissions.py
11
12
def has_permission(self, request, view):
    return request.user and request.user.is_authenticated