aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend/src/dto/users.py
diff options
context:
space:
mode:
Diffstat (limited to 'thallium-backend/src/dto/users.py')
-rw-r--r--thallium-backend/src/dto/users.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/thallium-backend/src/dto/users.py b/thallium-backend/src/dto/users.py
new file mode 100644
index 0000000..0d1cdac
--- /dev/null
+++ b/thallium-backend/src/dto/users.py
@@ -0,0 +1,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