bridgekeeper icon indicating copy to clipboard operation
bridgekeeper copied to clipboard

Add shorthand to visible_to helper

Open daisylb opened this issue 7 years ago • 0 comments

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).

daisylb avatar Mar 23 '18 02:03 daisylb