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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71af94d4a2539d40d147efcee9f2dee9b161b118ba1d06ef7a4894148a68083 |
|
MD5 | 9b59085511fc86ad6f4cb0eae2aac044 |
|
BLAKE2b-256 | 3e5ada85adbb99604a83bba528a8cccf80db4c791cf311645407bd2164ca83fa |
Close
Hashes for drf_permission_rules-0.4.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c4b93f3d7bd6ac74288cc18b193b9db1074c0cd5a5896219d7579e5a3a9bcfa |
|
MD5 | 4edb755932c5cfa0c42e5fc2b530e246 |
|
BLAKE2b-256 | 0c6b78382605457bff55f70246f039aa328ac04fb80d87f0f8dfcf211cba34f0 |