File: backends.py

package info (click to toggle)
python-django-braces 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: python: 2,680; makefile: 138; sh: 6
file content (28 lines) | stat: -rw-r--r-- 890 bytes parent folder | download
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
"""Testing backend for object level permissions"""
from tests.helpers import PermissionChecker


class PermissionsCheckerBackend:
    """
    Custom Permission Backend for testing Object Level Permissions.
    """
    supports_object_permissions = True
    supports_anonymous_user = True
    supports_inactive_user = True

    @staticmethod
    def authenticate():
        """Required for a backend"""
        return None

    @staticmethod
    def has_perm(user_obj, perm, obj=None):
        """Used for checking permissions using the `PermissionChecker`"""
        check = PermissionChecker(user_obj)
        return check.has_perm(perm, obj)

    @staticmethod
    def has_perms(user_obj, perms: list[str], obj=None):
        """Used for checking multiple permissions using the `PermissionChecker`"""
        check = PermissionChecker(user_obj)
        return check.has_perms(perms, obj)