diff --git a/app.py b/app.py index 1351c0a..9d6b5de 100644 --- a/app.py +++ b/app.py @@ -120,6 +120,11 @@ def admin(): user = User.query.get(user_id) if user and user != current_user: # Prevent self-modification + if action in ['demote', 'delete'] and user.admin: + admin_count = User.query.filter_by(admin=True).count() + if admin_count == 1: + abort(400, description="Cannot remove last admin") + if action == "promote": user.admin = True elif action == "demote": diff --git a/templates/dashboard.html b/templates/dashboard.html index 7f712ca..ded32b7 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -21,7 +21,7 @@