-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuser.py
More file actions
38 lines (28 loc) · 980 Bytes
/
user.py
File metadata and controls
38 lines (28 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
logger = logging.getLogger(__name__)
class User:
_username: str
_roles: list[str]
def __init__(self, username: str, roles: list[str]):
self._username = username
self._roles = roles
@property
def username(self):
return self._username
@property
def roles(self):
return self._roles
def has_matching_role(self, requested_roles: list[str]) -> bool:
"""
Verify that the user has at least one of the requested roles.
Args:
requested_roles: The list of requested roles.
Returns:
bool: `True` only if the user has any registered role and all the given roles are registered.
"""
logger.debug(
f"Check {self.username} has all {requested_roles}: currently {self.roles}"
)
return any(role in self.roles for role in requested_roles)
def __str__(self):
return f"{self.username} ({self.roles})"