drf-action-permissions
| Release | CI | Coverage |
|---|---|---|
Flexible ability to add action permissions on view level for Django REST framework. Permissions can be as complex or simple as you want. It can be a plain string or a function.
Requirements
- Python (3.6+)
- Django (1.11.x, 2.0+)
- Django REST Framework (3.7+)
Installation
$ pip install drf-common-exceptions
You cound define common permissions class for whole project:
REST_FRAMEWORK = {
...
"DEFAULT_PERMISSION_CLASSES": (
"drf_action_permissions.DjangoActionPermissions",
)
...
}
Or use it just for particular viewset in combination with others:
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet
from drf_action_permissions import DjangoActionPermissions
class MyView(viewsets.ModelViewSet):
permission_classes = (IsAuthenticated, DjangoActionPermissions)
perms_map_action = {
'retrieve': ['users.view_user'],
}
Usage examples
Permission as string template or plain string:
class PostViewSet(ModelViewSet):
permission_classes = (IsAuthenticated, DjangoActionPermissions)
perms_map_action = {
'likes': ['%(app_label)s.view_%(model_name)s_list',
'%(app_label)s.view_like_list'],
}
Permission as function with current object access:
def can_view_application(user, _view, obj):
"""Can view only archived applications."""
if obj.is_archived:
return user.has_perm('applications.view_archived_application')
return user.has_perm('applications.view_application')
class ApplicationView(ModelViewSet):
permission_classes = (IsAuthenticated, DjangoActionPermissions)
perms_map_action_obj = {
'retrieve': [can_view_application],
}
Development
Install poetry and requirements:
$ curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
$ python3 -m venv path/to/venv
$ source path/to/venv/bin/activate
$ poetry install
Run main commands:
$ make test
$ make watch
$ make clean
$ make lint
Publish to pypi by default patch version:
$ make publish
or any level you want:
$ make publish minor
Metadata
Release files for drf-action-permissions 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf-action-permissions-0.1.1.tar.gz | 4.0 kB | Without provenance | Details for drf-action-permissions-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_action_permissions-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for drf_action_permissions-0.1.1-py3-none-any.whl |
Total release size: 7.8 kB
Release files / drf-action-permissions-0.1.1.tar.gz
| Download URL | drf-action-permissions-0.1.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d5cc71c71200255e0cf5d340d2476c1b5b0886047af443614c953c8cde04643
|
|
BLAKE2b-256 checksum How to use checksums |
00aa7551f506a0cb1716cb8100e45ed65cf3e153f738879992164680009f7e1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.2 CPython/3.6.9 Linux/5.0.0-37-generic
|
Release files / drf_action_permissions-0.1.1-py3-none-any.whl
| Download URL | drf_action_permissions-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
386e6dca7ac914844deb781022b5c7b59a16d09cde78cfefee92c1ec55eb31b5
|
|
BLAKE2b-256 checksum How to use checksums |
29b1d0ee7af178b7bcf00146bd5082ac976abf9a7a288030207819bcb5ad1828
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.2 CPython/3.6.9 Linux/5.0.0-37-generic
|
Security for drf-action-permissions 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.