aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend/src/dto/users.py
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-08-19 01:05:27 +0100
committerGravatar Chris Lovering <[email protected]>2024-08-19 01:05:27 +0100
commitfe6abd8a5719cbcab1d1207918136f19042e4fa3 (patch)
treedf09b6c83653189f668fce044c41096386e5bde0 /thallium-backend/src/dto/users.py
parentCaddy local support (diff)
Add debug endpoints and implement token auth
Co-authored-by: Joe Banks <[email protected]>
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