mirror of
https://github.com/suitenumerique/drive.git
synced 2026-08-17 20:15:40 +02:00
fixup! ♻️(backend) extract role resolution into a permissions backend
This commit is contained in:
@@ -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]]]:
|
||||
|
||||
Reference in New Issue
Block a user