blob: f5aea0a4e549dafe91491b9bd05c2519501d302d (
plain) (
blame)
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
|
from enum import IntFlag
from uuid import UUID
from pydantic import BaseModel
class UserPermission(IntFlag):
"""The permissions a user has."""
VIEW_VOUCHERS = 2**0
ISSUE_VOUCHERS = 2**1
REVOKE_VOUCHERS = 2**2
MANAGE_USERS = 2**3
VIEW_TEMPLATES = 2**4
UPDATE_TEMPLATES = 2**5
class User(BaseModel):
"""An user authenticated with the backend."""
id: UUID
permissions: int
def has_permission(self, permission: UserPermission) -> bool:
"""Whether the user has the given permission."""
return (self.permissions & permission) == permission
|