===============
Complex permissions flow for `django-rest-framework`_.
Installation
------------
The easiest way to install the latest version is by using
pip/easy\_install to pull it from PyPI:
::
pip install rest_condition
You may also use Git to clone the repository from Github and install it
manually:
::
git clone https://github.com/caxap/rest_condition.git
python setup.py install
Example
-------
.. code:: python
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import BasePermission
from rest_condition import ConditionalPermission, C, And, Or, Not
class Perm1(BasePermission):
def has_permission(self, request, view):
# You permissions check here
return True
class Perm2(BasePermission):
def has_permission(self, request, view):
# You permissions check here
return False
# Example of possible expressions
expr1 = Or(Perm1, Perm2) # same as: C(Perm1) | Perm2
expr2 = And(Perm1, Perm2) # same as: C(Perm1) & Perm2
expr3 = Not(Perm1) # same as: ~C(Perm1)
expr4 = And(Not(Perm1), Or(Perm1, Not(Perm2))) # same as: ~C(Perm1) & (C(Perm1) | ~C(Perm2))
# Using expressions in API views
class ExampleView(APIView):
permission_classes = [Or(And(Perm1, Perm2), Not(Perm2)), ]
# Or just simple:
# permission_classes = [C(Perm1) & Perm2 | ~C(Perm2), ]
def get(self, request, format=None):
content = {'status': 'request was permitted'}
return Response(content)
class OtherExampleView(ExampleView):
# Using ConditionalPermission class
permission_classes = [ConditionalPermission, ]
permission_condition = (C(Perm1) & Perm2) | (~C(Perm1) & ~C(Perm2))
License
-------
The MIT License (MIT)
Contributed by `Max Kamenkov`_
.. _django-rest-framework: http://django-rest-framework.org/
.. _Maxim Kamenkov: https://github.com/caxap/
Metadata
Release files for rest_condition 1.0.3
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 | |
|---|---|---|---|---|
| rest_condition-1.0.3.tar.gz | 4.9 kB | Without provenance | Details |
Release files / rest_condition-1.0.3.tar.gz
| Download URL | rest_condition-1.0.3.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f47ed11a6519260b3f6248a2b6d6bf127ea7d9e04155fcf1e546bb561295af8
|
|
BLAKE2b-256 checksum How to use checksums |
f2e89f46207275f33df32a36d3755d5da8b551de053c61ec4cad8f71fe6e411f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for rest_condition 1.0.3
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.