Backends
ObjectPermissionBackend
Django backend for checking object-level permissions.
Source code in guardian/backends.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_all_permissions(user_obj, obj=None)
Returns all permissions for a given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_obj
|
User
|
User instance. |
required |
obj
|
Model
|
Django Model instance. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[str]
|
a set of permission strings that the given |
Source code in guardian/backends.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
has_perm(user_obj, perm, obj=None)
Check if a user has the permission for a given object.
Returns True if given user_obj has perm for obj.
If no obj is given, False is returned.
The main difference between Django's ModelBackend is that we can pass
obj instance here and perm doesn't have to contain
app_label as it can be retrieved from given obj.
Inactive user support
If user is authenticated but inactive at the same time, all checks
always return False.
Note
Remember, that if user is not active, all checks would return False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_obj
|
User
|
User instance. |
required |
perm
|
str
|
Permission string. |
required |
obj
|
Model
|
Model instance. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in guardian/backends.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |