Authorization Backend Proposals for Utility Methods

31 views
Skip to first unread message

Mehmet Dogan

unread,
Jan 19, 2018, 11:37:16 AM1/19/18
to Django developers (Contributions to Django itself)
Hello All,

I would like to get your opinions on what seemed to me useful additions to the `auth.backends.ModelBackend`. These are polled by the `auth.models` and not every backend has to implement them.

1) clear_cache()

default backend caches permissions at `user._user_perm_cache`, `user._group_perm_cache` and cumulatively: `user._perm_cache`. Most other backends also do things similar. If an app uses 2-3 backends, resetting cache after adding a permission becomes a chore. 

2) has_perms_any ()

we have one (has_perms) that requires all permissions given, why not any? If this makes it, the other may also be renamed to has_perms_all ()

3) get_permisson_objects ()

guardian has something like this, and i think it would be nice if the default backend also provided similar. if it did, it would be either Model.objects.all() or Model.objects.none(); does not look much useful, however if one uses say 3 backends, it does seem useful. If implemented, due to diverse nature of backends it may be hard, if at all possible, to implement lazy loading, thus, may incur performance costs. If you think this is useful, please also share if you have design ideas. 

4) get_backends ()

this is not really a utility method, but a move request. It is currently under auth.__init__(); I think if it was moved to somewhere that could be overrided, it would allow one to pick and choose backends locally from the code if needed. 

Regards,

Mehmet
Reply all
Reply to author
Forward
0 new messages