aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api/deps.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/deps.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/deps.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/deps.py b/packages/meshbay-hub/src/meshbay_hub/api/deps.py
index 7a580ad..addba30 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/deps.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/deps.py
@@ -52,10 +52,21 @@ async def get_current_user(
return user
+async def require_moderator(
+ current_user: User = Depends(get_current_user),
+) -> User:
+ if current_user.role not in ("moderator", "admin") \
+ and current_user.username not in _admin_usernames:
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
+ detail="Moderator access required")
+ return current_user
+
+
async def require_admin(
current_user: User = Depends(get_current_user),
) -> User:
- if current_user.username not in _admin_usernames:
+ if current_user.role != "admin" \
+ and current_user.username not in _admin_usernames:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail="Admin access required")
return current_user