blob: 0d1cdacb960ae8e3ff1d6d1bae0ca0a171bc485e (
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
|
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**1
VIEW_PRODUCTS = 2**2
MANAGE_USERS = 2**3
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
|