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.5.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

drf_permission_rules-0.4.5-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf_permission_rules-0.4.5.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.2 Linux/6.2.0-1015-azure

File hashes

Hashes for drf_permission_rules-0.4.5.tar.gz
Algorithm Hash digest
SHA256 bbf36db0384424d01b18c15e4b41517d34724d66fc046939af253aae8fe2ac59
MD5 5158e416f64ed3a00deb16496bcdea1c
BLAKE2b-256 58c5c858cb698b20618945803a1b5bb9b8e1d2b7706fc1ee2db6173187443d84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_permission_rules-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 714a9acf2f70f5318713ca9b4935fdba30c7d92b5462fe2dab0b1a28a540762c
MD5 4026cd2f6faeb7044d12fbf3686a4609
BLAKE2b-256 941e2a23fbc6a3173b10b82c8904a7503633da7e0e108575817b13d11d85fc9c

See more details on using hashes here.

Supported by

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