Declarative access policies/permissions modeled after AWS' IAM policies.
Project description
drf-permission-rules
permission rules for DRF base on drf access policy
Installation
pip install drf-permission-rules
Usage
ViewSet permissions
class UserViewSet(ModelViewSet, PermissionsActionMixin):
...
@action(methods=["GET", "POST"], detail=False)
def some_action(self, request, *args, **kwargs):
...
GET /api/users/permissions
Response:
{
"create": true,
"list": true,
"some_action": false
}
Multiple ViewSet permissions
# views.py
class UserViewSet(ModelViewSet, PermissionsActionMixin):
...
class BookViewSet(ModelViewSet, PermissionsActionMixin):
...
class AuthorViewSet(ModelViewSet, PermissionsActionMixin):
...
# urls.py
urlpatterns = [
...
path("api/", include("permission_rules.urls")),
]
GET /api/users/permissions
Response:
{
"User": {
"create": true
"list": true,
"some_action": false
}
"Book": {
"create": true,
"list": true
},
"Author": {
"create": false,
"list": true
}
}
Speedup
You can get permissions from a file instead of a database.
# settings.py
PERMISSION_RULES_SETTINGS = {
"use_file_instead_db": true,
"permission_rules_file_path": "/path/to/permissions.json"
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for drf_permission_rules-0.4.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbf36db0384424d01b18c15e4b41517d34724d66fc046939af253aae8fe2ac59 |
|
MD5 | 5158e416f64ed3a00deb16496bcdea1c |
|
BLAKE2b-256 | 58c5c858cb698b20618945803a1b5bb9b8e1d2b7706fc1ee2db6173187443d84 |
Close
Hashes for drf_permission_rules-0.4.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 714a9acf2f70f5318713ca9b4935fdba30c7d92b5462fe2dab0b1a28a540762c |
|
MD5 | 4026cd2f6faeb7044d12fbf3686a4609 |
|
BLAKE2b-256 | 941e2a23fbc6a3173b10b82c8904a7503633da7e0e108575817b13d11d85fc9c |