blob: 8faf4e7c61238c6d1cf8d0f6a11ddc44c04006a8 (
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**1
MANAGE_USERS = 2**2
VIEW_TEMPLATES = 2**3
UPDATE_TEMPLATES = 2**4
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
|