Django field permission package
Project description
DFPermission
Installation
pip install df-permission
Configuration
INSTALLED_APPS = [
...,
'df_permission'
]
Generate permissions
For model fields:
./manage.py generate_model_field_permissions
For serializer fields (not include model fields):
./manage.py generate_serializer_field_permissions
Attributes
df_method
- Method of action
- Valid values are
create
,update
,retrieve
,list
,destroy
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_method = 'create'
...
or
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_method = DFMethods.CREATE
...
df_model
- Model
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_model = MyModel
...
df_fields
- Fields
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_fields = ['field1', 'field2', ...]
...
df_permissions
- Permissions
- type:
string
,list
,tuple
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_permissions = ['permission1', 'permission2', ...]
...
or
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_permissions = 'permission1'
...
df_allow_superuser
- Allow superuser if value is True
- Type:
boolean
- Default:
False
Methods
get_df_permissions
- Customize df_permissions
class MyView(CreateAPIView):
permission_classes = [DFPermission]
def get_df_permissions(self):
# write your logic code
return # single permission or permissions
How does it work?
First, find df_permissions
attribute. If it
does not exist, find get_df_permissions
method.
If it does not exist too, generate permissions.
First for this, collect fields that are permission
required. Find df_fields
, if it exist. Else get
serializer class to get fields and get intersection
with model fields.
Then, generate required perms using fields and df_method
.
Finally, user's permissions are checked.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file df-permission-0.1.9.tar.gz
.
File metadata
- Download URL: df-permission-0.1.9.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3226619641b7eddc8ee66ea710b434932d7fb83e6da8ca8847ed7ea9863cfda6 |
|
MD5 | 5e49494de8866bcda729f3f97632c174 |
|
BLAKE2b-256 | 931c45889dec3c5dcb35fe49c098ce406fef26a7c95c8ec18cc78125c1bae810 |
File details
Details for the file df_permission-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: df_permission-0.1.9-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e9645813edbd424a494f54ccd2ef41aad4e02ca14a22ec9e4020701877a035a |
|
MD5 | 4494858b37ef5ab8ff598651df4879b0 |
|
BLAKE2b-256 | 242c9a3409ecb9d375103cd3e168e9523fefe9caf4fc6456f2824fee53dc4bb8 |