daisylb / bridgekeeper

Django permissions, but with QuerySets
https://bridgekeeper.leigh.party/
MIT License
41 stars 14 forks source link

Add shorthand to visible_to helper #5

Open daisylb opened 6 years ago

daisylb commented 6 years ago

Currently, calls to visible_to look like this:

Shrubbery.objects.visible_to(user, 'shrubberies.change_shrubbery')

I'd like to change the signature to visible_to(user, *, using, action), so that the above call looks like one of the following:

Shrubbery.objects.visible_to(user, using='shrubberies.change_shrubbery')
Shrubbery.objects.visible_to(user, action='change')

We could even go further for the three conventional actions for which it makes sense to filter QuerySets:

Shrubbery.objects.viewable_by(user)
Shrubbery.objects.changeable_by(user)
Shrubbery.objects.deleteable_by(user)

The permission used by the short forms would be looked up in the registry in much the same way as it already is, but the name to look up would be autogenerated in much the same way that the Django REST Framework integration works, by extracting the app and model name from the QuerySet, and substituting in the supplied action (or constants in the last three cases).