FJNR-inc / dry-rest-permissions

Rules based permissions for the Django Rest Framework
ISC License
78 stars 11 forks source link

add DRYGlobalPermissionsField #8

Closed RignonNoel closed 4 years ago

RignonNoel commented 4 years ago

Description

Add a field to see all global permissions on all models that define a permission method.

The field will return a dictionary with a key for EACH model defining at least one global permission, each of these key representing a model will contain a dictionary of the format {"permission_name": permission value}

Example

Example of usage:

from dry_rest_permissions.generics import DRYGlobalPermissionsField

class ProjectSerializer(serializers.ModelSerializer):
    permissions = DRYGlobalPermissionsField()

    class Meta:
        model = Project
        fields = ('id', 'owner', 'permissions')

Example of return:

{
    "id": 1,
    "owner": 100,
    "permissions": {
        "Project": {
            "read": true,
            "write": false
        },
        "MyOtherModel": {
            "create": true,
            "destroy": false
        }
    }
}

Details of the feature

Checklist