aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api/admin.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/admin.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/admin.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/admin.py b/packages/meshbay-hub/src/meshbay_hub/api/admin.py
index c3fa8c2..88e231a 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/admin.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/admin.py
@@ -134,11 +134,17 @@ async def admin_patch_user(
if user.id == current_user.id:
raise HTTPException(status_code=400, detail="Cannot modify your own account")
+ from meshbay_hub.api.notifications import create_notification
+
if body.role is not None:
if body.role not in ("user", "moderator", "admin"):
raise HTTPException(status_code=422, detail="role must be user, moderator, or admin")
user.role = body.role
log.info("User %s role changed to %s by %s", user.username, body.role, current_user.username)
+ await create_notification(
+ db, user.id, "role_change",
+ f"Your role has been changed to {body.role}",
+ )
if body.status is not None:
if body.status not in ("active", "suspended", "revoked"):
@@ -146,6 +152,16 @@ async def admin_patch_user(
user.status = body.status
log.info("User %s status changed to %s by %s",
user.username, body.status, current_user.username)
+ if body.status == "suspended":
+ await create_notification(
+ db, user.id, "account_suspended",
+ "Your account has been suspended",
+ )
+ elif body.status == "active":
+ await create_notification(
+ db, user.id, "account_restored",
+ "Your account has been restored",
+ )
db.add(IPLog(
user_id=current_user.id,