# 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"
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/speechki-book/drf-permission-rules",
"name": "drf-permission-rules",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "django,restframework,policy,authorization,declaritive",
"author": "Pavel Maltsev",
"author_email": "pavel@speechki.org",
"download_url": "https://files.pythonhosted.org/packages/58/c5/c858cb698b20618945803a1b5bb9b8e1d2b7706fc1ee2db6173187443d84/drf_permission_rules-0.4.5.tar.gz",
"platform": null,
"description": "# drf-permission-rules\npermission rules for DRF base on drf access policy\n\n## Installation\n\n```\npip install drf-permission-rules\n```\n\n## Usage\n\n### ViewSet permissions\n```\nclass UserViewSet(ModelViewSet, PermissionsActionMixin):\n ...\n\n @action(methods=[\"GET\", \"POST\"], detail=False)\n def some_action(self, request, *args, **kwargs):\n ...\n\n\nGET /api/users/permissions\nResponse:\n{\n \"create\": true,\n \"list\": true,\n \"some_action\": false\n}\n```\n\n### Multiple ViewSet permissions\n\n```\n# views.py\nclass UserViewSet(ModelViewSet, PermissionsActionMixin):\n ...\n\nclass BookViewSet(ModelViewSet, PermissionsActionMixin):\n ...\n\nclass AuthorViewSet(ModelViewSet, PermissionsActionMixin):\n ...\n\n\n# urls.py\nurlpatterns = [\n ...\n path(\"api/\", include(\"permission_rules.urls\")),\n]\n\n\nGET /api/users/permissions\nResponse:\n{\n \"User\": {\n \"create\": true\n \"list\": true,\n \"some_action\": false\n }\n \"Book\": {\n \"create\": true,\n \"list\": true\n },\n \"Author\": {\n \"create\": false,\n \"list\": true\n }\n}\n```\n\n\n## Speedup\n\nYou can get permissions from a file instead of a database.\n\n```\n# settings.py\n\n\nPERMISSION_RULES_SETTINGS = {\n \"use_file_instead_db\": true,\n \"permission_rules_file_path\": \"/path/to/permissions.json\"\n}\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Declarative access policies/permissions modeled after AWS' IAM policies.",
"version": "0.4.5",
"project_urls": {
"Homepage": "https://github.com/speechki-book/drf-permission-rules"
},
"split_keywords": [
"django",
"restframework",
"policy",
"authorization",
"declaritive"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "941e2a23fbc6a3173b10b82c8904a7503633da7e0e108575817b13d11d85fc9c",
"md5": "4026cd2f6faeb7044d12fbf3686a4609",
"sha256": "714a9acf2f70f5318713ca9b4935fdba30c7d92b5462fe2dab0b1a28a540762c"
},
"downloads": -1,
"filename": "drf_permission_rules-0.4.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4026cd2f6faeb7044d12fbf3686a4609",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 14836,
"upload_time": "2023-10-31T11:39:21",
"upload_time_iso_8601": "2023-10-31T11:39:21.856218Z",
"url": "https://files.pythonhosted.org/packages/94/1e/2a23fbc6a3173b10b82c8904a7503633da7e0e108575817b13d11d85fc9c/drf_permission_rules-0.4.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "58c5c858cb698b20618945803a1b5bb9b8e1d2b7706fc1ee2db6173187443d84",
"md5": "5158e416f64ed3a00deb16496bcdea1c",
"sha256": "bbf36db0384424d01b18c15e4b41517d34724d66fc046939af253aae8fe2ac59"
},
"downloads": -1,
"filename": "drf_permission_rules-0.4.5.tar.gz",
"has_sig": false,
"md5_digest": "5158e416f64ed3a00deb16496bcdea1c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 9842,
"upload_time": "2023-10-31T11:39:26",
"upload_time_iso_8601": "2023-10-31T11:39:26.710094Z",
"url": "https://files.pythonhosted.org/packages/58/c5/c858cb698b20618945803a1b5bb9b8e1d2b7706fc1ee2db6173187443d84/drf_permission_rules-0.4.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-31 11:39:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "speechki-book",
"github_project": "drf-permission-rules",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "drf-permission-rules"
}