Open
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
Small refactor: extract a -> method to allow to extend/change the permissions for a user.
Problem
I'd like to implement some hierarchy for the permissions which requires some post-work with the explicitly set permissions. Now I have to rewrite the whole _get_permissions
method in a subclass, while I just need the explicitly set permissions to know what other permissions I should add there.
Request or proposal
proposal
Additional Details
No response
Implementation Suggestions
At this code: https://github.com/django/django/blob/23529b662793cdf4725d5f8ff58f0df94b343365/django/contrib/auth/backends.py#L119
Instead of this:
...
perms = perms.values_list("content_type__app_label", "codename").order_by()
setattr(
user_obj, perm_cache_name, {"%s.%s" % (ct, name) for ct, name in perms}
)
...
Extract the conversion to a new method:
def _permission_strings(self, permission_queryset):
perms = permission_queryset.values_list("content_type__app_label", "codename").order_by()
return {f"{ct}.{name}" for ct, name in perms}
...
setattr(
user_obj, perm_cache_name, self._permission_strings(perms)
)
...
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Idea