2026-06-02 10:18:59 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from collections.abc import Awaitable, Callable
|
2026-06-02 11:11:36 +02:00
|
|
|
from typing import Any, cast
|
2026-06-02 10:18:59 +02:00
|
|
|
|
|
|
|
|
from datastar_py.quart import DatastarResponse
|
2026-06-02 11:11:36 +02:00
|
|
|
from quart import Quart, Response, redirect
|
2026-06-02 10:18:59 +02:00
|
|
|
|
|
|
|
|
from repub.web.app import _page_patch_response, _shim_page_response, render_dashboard
|
|
|
|
|
|
|
|
|
|
RouteGuard = Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def register_dashboard_routes(app: Quart, *, admin_required: RouteGuard) -> None:
|
2026-06-02 11:11:36 +02:00
|
|
|
@app.get("/admin/")
|
|
|
|
|
@admin_required
|
|
|
|
|
async def admin_dashboard_trailing_slash() -> Response:
|
|
|
|
|
return cast(Response, redirect("/admin"))
|
|
|
|
|
|
2026-06-02 10:18:59 +02:00
|
|
|
@app.get("/admin")
|
|
|
|
|
@admin_required
|
|
|
|
|
async def admin_dashboard_home() -> Response:
|
|
|
|
|
return _shim_page_response(current_path="/admin", static_prefix="/admin")
|
|
|
|
|
|
|
|
|
|
@app.post("/admin")
|
|
|
|
|
@admin_required
|
|
|
|
|
async def admin_dashboard_patch() -> DatastarResponse:
|
|
|
|
|
return await _page_patch_response(
|
|
|
|
|
app,
|
|
|
|
|
lambda _tab_id: render_dashboard(app, path_prefix="/admin"),
|
|
|
|
|
)
|