diff --git a/backend/app/routes/admin.py b/backend/app/routes/admin.py index 1d86ed0..3edd262 100644 --- a/backend/app/routes/admin.py +++ b/backend/app/routes/admin.py @@ -166,7 +166,12 @@ def set_user_role( raise HTTPException(status_code=400, detail="The demo account's role can't be changed.") if target.id == admin.id: raise HTTPException(status_code=400, detail="You can't change your own role.") - if target.role == "admin" and role == "user" and count_admins(db) <= 1: + if ( + target.role == "admin" + and role == "user" + and not target.is_suspended + and count_admins(db, active_only=True) <= 1 + ): raise HTTPException(status_code=400, detail="Can't remove the last admin.") changed = target.role != role target.role = role @@ -233,7 +238,7 @@ def admin_delete_user( raise HTTPException( status_code=400, detail="Delete your own account from Settings → Account." ) - if target.role == "admin" and count_admins(db) <= 1: + if target.role == "admin" and not target.is_suspended and count_admins(db, active_only=True) <= 1: raise HTTPException(status_code=400, detail="Can't delete the last admin.") purge_user(db, target, background) return {"deleted": user_id}