fixup! ♻️(backend) extract role resolution into a permissions backend

This commit is contained in:
Nicolas Clerc
2026-08-13 18:01:04 +02:00
parent ccb9fc1ecd
commit f3f9c90102
2 changed files with 4 additions and 8 deletions
@@ -25,14 +25,14 @@ class PermissionsBackend(ABC):
def roles_at(self, user: models.User | AnonymousUser, path: str) -> QuerySet[str]:
"""Return the roles the user holds at the given path, direct or inherited."""
@abstractmethod
def roles_for(self, user: models.User | AnonymousUser, item: models.Item) -> QuerySet[str]:
"""Return the roles the user holds on the item, direct or inherited."""
@abstractmethod
def abilities(self, user: models.User | AnonymousUser, item: models.Item) -> dict:
"""Compute and return abilities for a given user on the item."""
def roles_for(self, user: models.User | AnonymousUser, item: models.Item) -> QuerySet[str]:
"""Return the roles the user holds on the item, direct or inherited."""
return self.roles_at(user, item.path)
def role_at(self, user: models.User | AnonymousUser, path: str) -> str | None:
"""Return the highest role the user holds at the given path."""
return RoleChoices.max(*self.roles_at(user, path))
@@ -216,10 +216,6 @@ class RolePermissionsBackend(PermissionsBackend):
item__path__ancestors=path,
).values_list("role", flat=True)
def roles_for(self, user: models.User | AnonymousUser, item: models.Item) -> QuerySet[str]:
"""Return the roles the user holds on the item, direct or inherited."""
return self.roles_at(user, item.path)
def abilities(
self, user: models.User | AnonymousUser, item: models.Item
) -> dict[str, bool | dict[str, list[str]]]: