Implement posibility to check single right

This commit is contained in:
Sebastiaan
2025-06-07 22:39:03 +02:00
parent 7c515b8e8f
commit 48007734e5
6 changed files with 65 additions and 19 deletions

View File

@@ -138,6 +138,9 @@ class Event(mixin.RowId, EventBase, table=True):
user: User,
rights: PermissionRight | None = None,
) -> bool:
"""
Check if all rights are present for the user
"""
return any(
(
link.user == user
@@ -147,6 +150,23 @@ class Event(mixin.RowId, EventBase, table=True):
for link in self.user_links
)
def user_has_right(
self,
user: User,
rights: PermissionRight | None = None,
) -> bool:
"""
Check if at least one right is present for the user
"""
return any(
(
link.user == user
and link.rights
and (not rights or (link.rights & rights))
)
for link in self.user_links
)
# Properties to return via API, id is always required
class EventPublic(mixin.RowIdPublic, EventBase):