Inline media stream for Discussion attachments.
(fid: int)
| 13018 | return redirect(url_for("admin_panel")) |
| 13019 | # Do not promote self redundantly |
| 13020 | conn = db_connect() |
| 13021 | row = conn.execute("SELECT is_admin FROM users WHERE username=?", (u,)).fetchone() |
| 13022 | if not row: |
| 13023 | conn.close() |
| 13024 | flash("User not found.") |
| 13025 | return redirect(url_for("admin_panel")) |
| 13026 | if int(row["is_admin"]) == 1: |
| 13027 | conn.close() |
| 13028 | flash("User is already an admin.") |
| 13029 | return redirect(url_for("admin_panel")) |
| 13030 | |
| 13031 | # Promote + bind to this device (admin actions are allowed only locally on the host device) |
| 13032 | conn.execute("UPDATE users SET is_admin=1, admin_device_id=? WHERE username=?", (DEVICE_ID, u)) |
| 13033 | conn.commit() |
| 13034 | conn.close() |
| 13035 | flash(f"Promoted @{u} to admin.") |
| 13036 | return redirect(url_for("admin_panel")) |
| 13037 | |
| 13038 | @app.route("/admin/demote", methods=["POST"]) |
| 13039 | @login_required |
| 13040 | def admin_demote(): |
| 13041 | """admin_demote. |
| 13042 | |
| 13043 | Admin-only route handler. |
| 13044 | |
| 13045 | This docstring was expanded to make future maintenance easier. |
| 13046 | |
| 13047 | Returns: |
| 13048 | Varies. |
| 13049 | """ |
| 13050 | require_admin() |
| 13051 | try: |
| 13052 | log_security_event("admin_action", detail="demote_user", username=current_user(), level="info") |
| 13053 | except Exception: |
| 13054 | pass |
| 13055 | u = (request.form.get("username") or "").strip() |
| 13056 | if not u: |
| 13057 | return redirect(url_for("admin_panel")) |
| 13058 | if u == current_user(): |
| 13059 | flash("You cannot demote yourself here.") |
| 13060 | return redirect(url_for("admin_panel")) |
| 13061 | |
| 13062 | conn = db_connect() |
| 13063 | # Ensure we don't remove the last admin |
nothing calls this directly
no test coverage detected