Skip to main content

Declarative access policies/permissions modeled after AWS' IAM policies.

Project description

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"
}

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

drf_permission_rules-0.4.6.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_permission_rules-0.4.6-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file drf_permission_rules-0.4.6.tar.gz.

File metadata

  • Download URL: drf_permission_rules-0.4.6.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.2 Linux/6.5.0-1025-azure

File hashes

Hashes for drf_permission_rules-0.4.6.tar.gz
Algorithm Hash digest
SHA256 d74177b6308843e53ff09c7a54bea11d722662c6b035baabf8613d66dc1ed076
MD5 48550e4421778ed2e0176fa24fbdd090
BLAKE2b-256 99955dcc8daaaf5e170433bbfa094bb3063606cc3a62d05c555c63981635f000

See more details on using hashes here.

File details

Details for the file drf_permission_rules-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: drf_permission_rules-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.2 Linux/6.5.0-1025-azure

File hashes

Hashes for drf_permission_rules-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4466bc36fbc5e80b44b530e8662c449b27eab108e43714cb1fc6f36bb7819d
MD5 3887d307351e3baee3e6e1ea8e5671aa
BLAKE2b-256 cd9b96a42e54a0160484df07f58f87a6df850bd9c9b147001d64fd804ded5c93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page