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
drf_permission_rules-0.4.3.tar.gz
(10.4 kB
view hashes)
Built Distribution
Close
Hashes for drf_permission_rules-0.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e40dc12cd1ace32e6c5fd26492145d5efae9bd56fa024e9abf6b09ba14f780 |
|
MD5 | 0dc46a239a029276b4e13a957ef8c9c0 |
|
BLAKE2b-256 | 67d54737ed87b6bc6691c22b46e1cb1583e19beb7e345e9cc03b50b0a805af92 |
Close
Hashes for drf_permission_rules-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eabf1cf6b8c1863aaab17ab59da4ab1308b84de2c459678146ba242ab78cda5 |
|
MD5 | 8c6871921e7dca997ae38f918377a4e2 |
|
BLAKE2b-256 | 0051094060c08df6e67a4247466253d043a347f6ca95f20840b77d7416d68054 |