Archived
Simplify admin operator UI
This commit is contained in:
1 parent
0fc220b90b
commit
30aef1fee8
7 files changed
+393
-105
No files matched your search
+21
-10
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
|
||||
from fastapi.responses import HTMLResponse, PlainTextResponse, RedirectResponse
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
@@ -15,7 +17,8 @@ from ..security import client_ip, require_admin_csrf
|
||||
from ..services.ddns import normalize_hostname
|
||||
from ..web.components import _copy_row
|
||||
from ..web.forms import first_form_value, request_form
|
||||
from ..web.templates_admin import _admin_secret_panel, _render_admin_page
|
||||
from ..web.html_utils import SafeHtml
|
||||
from ..web.templates_admin import _admin_notice, _admin_secret_panel, _render_admin_page
|
||||
|
||||
ADMIN_TABLE_LIMIT = 100
|
||||
ADMIN_JSON_OFFSET_CAP = 10_000
|
||||
@@ -29,7 +32,7 @@ def make_router(admin_path: str = "/admin") -> APIRouter:
|
||||
settings: SettingsDep,
|
||||
store: StoreDep,
|
||||
table_offsets: dict[str, int] | None = None,
|
||||
notice: str | None = None,
|
||||
notice: SafeHtml | None = None,
|
||||
) -> str:
|
||||
table_offsets = table_offsets or {}
|
||||
return _render_admin_page(
|
||||
@@ -59,7 +62,15 @@ def make_router(admin_path: str = "/admin") -> APIRouter:
|
||||
accounts_offset: int = Query(0, ge=0),
|
||||
cleanup_runs_offset: int = Query(0, ge=0),
|
||||
update_events_offset: int = Query(0, ge=0),
|
||||
cleanup_done: bool = Query(False),
|
||||
cleanup_unused: int = Query(0, ge=0),
|
||||
cleanup_events: int = Query(0, ge=0),
|
||||
) -> str:
|
||||
notice = (
|
||||
_admin_notice("success", f"Cleanup finished. Removed {cleanup_unused} hostnames and {cleanup_events} old events.")
|
||||
if cleanup_done
|
||||
else None
|
||||
)
|
||||
return render_admin(
|
||||
service,
|
||||
settings,
|
||||
@@ -69,6 +80,7 @@ def make_router(admin_path: str = "/admin") -> APIRouter:
|
||||
"cleanup_runs": cleanup_runs_offset,
|
||||
"update_events": update_events_offset,
|
||||
},
|
||||
notice,
|
||||
)
|
||||
|
||||
@router.post(f"{admin_path}/hostnames/delete", include_in_schema=False)
|
||||
@@ -160,15 +172,14 @@ def make_router(admin_path: str = "/admin") -> APIRouter:
|
||||
settings.cleanup_event_history_hours,
|
||||
settings.cleanup_pending_account_hours,
|
||||
)
|
||||
notice = _admin_secret_panel(
|
||||
"Cleanup done",
|
||||
[
|
||||
_copy_row("Unused hostnames removed", str(result["unused_accounts"])),
|
||||
_copy_row("Old update events removed", str(result["update_events"])),
|
||||
],
|
||||
redirect_query = urlencode(
|
||||
{
|
||||
"cleanup_done": "1",
|
||||
"cleanup_unused": result["unused_accounts"],
|
||||
"cleanup_events": result["update_events"],
|
||||
}
|
||||
)
|
||||
page = await run_in_threadpool(render_admin, service, settings, store, None, notice)
|
||||
return HTMLResponse(page)
|
||||
return RedirectResponse(f"{admin_path}?{redirect_query}", status_code=303)
|
||||
|
||||
return router
|
||||
|
||||
|
||||
Reference in new issue
Block a user