Enforces client ViewSet requirements for Django Rest Framework
Project description
# django-rest-secureview
A collection of decorators to enforce conditions on [Django REST Framework](http://www.django-rest-framework.org/) API routes that are accessed by the User. At the moment, it focuses on enforcing specific model keys in POST params, or requiring that a User has a foreign key relation to a model they are accessing.
## Requirements
1. Python 2 or Python 3
2. Django
3. Django REST Framework
## Usuage
1. Install package
`pip install django-rest-secureview`
2. Import decorators
``` python
from django_rest_secureview import require_owner
```
3. Decorate ViewSets
``` python
from rest_framework.viewsets import ModelViewSet
from django_rest_secureview import require_params
class ApiEndpoint(ModelViewSet):
@require_params(params=['dog', 'cat'])
def create(self, request):
pass
```
## Decorators
1. `require_params`: Requires User to submit specific POST params when accessing an endpoint
``` python
@require_params(params=['dog', 'cat'])
def create(self, request):
pass
```
2. `require_owner`: Requires the authenticated User to have a ForeignKey relationship with the model in a detailed view
``` python
@require_owner(model=Pet)
def retrieve(self, request, pk=None):
pass
```
3. `require_owner_with_params`: Requires POST params and a ForeignKey relationship with the authenticated User and the model in a detailed view
``` python
@require_owner_with_params(model=Pet, params=['dog', 'cat'])
def update(self, request, pk=None):
pass
```
## Testing
[Tox](tox.testrun.org) should be in your virtual environment in order to run tests. Other dependencies, such as the Django REST Framework will be packaged separately in Tox's virtual testing environment.
``` sh
./run_tests.sh
```
A collection of decorators to enforce conditions on [Django REST Framework](http://www.django-rest-framework.org/) API routes that are accessed by the User. At the moment, it focuses on enforcing specific model keys in POST params, or requiring that a User has a foreign key relation to a model they are accessing.
## Requirements
1. Python 2 or Python 3
2. Django
3. Django REST Framework
## Usuage
1. Install package
`pip install django-rest-secureview`
2. Import decorators
``` python
from django_rest_secureview import require_owner
```
3. Decorate ViewSets
``` python
from rest_framework.viewsets import ModelViewSet
from django_rest_secureview import require_params
class ApiEndpoint(ModelViewSet):
@require_params(params=['dog', 'cat'])
def create(self, request):
pass
```
## Decorators
1. `require_params`: Requires User to submit specific POST params when accessing an endpoint
``` python
@require_params(params=['dog', 'cat'])
def create(self, request):
pass
```
2. `require_owner`: Requires the authenticated User to have a ForeignKey relationship with the model in a detailed view
``` python
@require_owner(model=Pet)
def retrieve(self, request, pk=None):
pass
```
3. `require_owner_with_params`: Requires POST params and a ForeignKey relationship with the authenticated User and the model in a detailed view
``` python
@require_owner_with_params(model=Pet, params=['dog', 'cat'])
def update(self, request, pk=None):
pass
```
## Testing
[Tox](tox.testrun.org) should be in your virtual environment in order to run tests. Other dependencies, such as the Django REST Framework will be packaged separately in Tox's virtual testing environment.
``` sh
./run_tests.sh
```
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
Close
Hashes for django-rest-secureview-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ed7ab01900950a43f79bb16a0793b70cff497f53aff3aae8193cf90de177b62 |
|
MD5 | 5891bee5814b9ad34a9184ce81ec087b |
|
BLAKE2b-256 | 8f6fc7d9284c5a08f5cab073acafc6d646d75cda42f8b51a84a16fd767de083c |