Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Foster <[email protected]>
  • Loading branch information
fosterseth authored and AlanCoding committed Jun 27, 2024
1 parent 1e653b7 commit 9ce8b88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/apps/rbac/for_app_developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,10 @@ and `Team.tracked_parents` ManyToMany relationships, respectively.
So if you have a team object, `team.users.add(user)` will also give that
user _member permission_ to that team, where those permissions are defined by the
role definition with the name "team-member".


### Role assignment callback

Apps that utilize django-ansible-base may wish to add extra validation when assigning roles to actors (users or teams).

see [Validation callback for role assignment](../../lib/validation.md)
11 changes: 10 additions & 1 deletion docs/lib/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ The signature of this callback is

`validate_role_assignment(self, actor, role_definition)`

This method is reponsible for raising the appropriate exception if necessary (e.g. DRF ValidationError or DRF PermissionDenied).
This method is reponsible for raising the appropriate exception if necessary, for example,

```python
from rest_framework.exceptions import ValidationError
class MyDjangoModel:
def validate_role_assignment(self, actor, role_definition):
raise ValidationError({'detail': 'Role assignment not allowed.'})
```

Note, if you want the exception to result in a HTTP 400 or 403 response, you can raise django rest framework exceptions instead of django exceptions.

0 comments on commit 9ce8b88

Please sign in to comment.