Projects such as Django-guardian and django-permissions enables you to have object level permissions. However, if two objects are related to each other by a parent-child relationship, is there any way for the child object to inherit permission from the parent object unless otherwise specified? For instance, a subfolder
should inherit permission from parent folder
unless a user explicitly assigns a different permission for the subfolder.
What's the best way to accomplish this using Django, in particular, the Django-guardian module?
When you check if a user has permissions on an object, and doesn't, then you can check if it has permission on its parent.
You might even want to make your own function, for example:
def your_has_perm(user, perm, obj):
has = user.has_perm(perm, obj)
if not has and hasattr(obj, 'parent'):
return your_has_perm(user, perm, obj.parent)
return has
This should traverse parents until it finds a permission for a parent or return False.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With