Add publisher dashboard routes
This commit is contained in:
parent
96551c2788
commit
e4a5246ab3
31 changed files with 1603 additions and 516 deletions
29
repub/web/publisher/__init__.py
Normal file
29
repub/web/publisher/__init__.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
|
||||
from quart import Quart
|
||||
|
||||
from repub.web.publisher.actions import register_publisher_actions
|
||||
from repub.web.publisher.pages.dashboard import register_publisher_dashboard_routes
|
||||
|
||||
RouteGuard = Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]
|
||||
|
||||
|
||||
def register_publisher_routes(
|
||||
app: Quart,
|
||||
*,
|
||||
publisher_required: RouteGuard,
|
||||
admin_required: RouteGuard,
|
||||
) -> None:
|
||||
register_publisher_dashboard_routes(
|
||||
app,
|
||||
publisher_required=publisher_required,
|
||||
admin_required=admin_required,
|
||||
)
|
||||
register_publisher_actions(
|
||||
app,
|
||||
publisher_required=publisher_required,
|
||||
admin_required=admin_required,
|
||||
)
|
||||
27
repub/web/publisher/actions.py
Normal file
27
repub/web/publisher/actions.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
|
||||
from quart import Quart, Response
|
||||
|
||||
from repub.web.app import run_job_now_response
|
||||
|
||||
RouteGuard = Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]
|
||||
|
||||
|
||||
def register_publisher_actions(
|
||||
app: Quart,
|
||||
*,
|
||||
publisher_required: RouteGuard,
|
||||
admin_required: RouteGuard,
|
||||
) -> None:
|
||||
@app.post("/publisher/actions/jobs/<int:job_id>/run-now")
|
||||
@publisher_required
|
||||
async def publisher_run_job_now_action(job_id: int) -> Response:
|
||||
return run_job_now_response(app, job_id)
|
||||
|
||||
@app.post("/admin/publisher/actions/jobs/<int:job_id>/run-now")
|
||||
@admin_required
|
||||
async def admin_publisher_run_job_now_action(job_id: int) -> Response:
|
||||
return run_job_now_response(app, job_id)
|
||||
1
repub/web/publisher/pages/__init__.py
Normal file
1
repub/web/publisher/pages/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from __future__ import annotations
|
||||
57
repub/web/publisher/pages/dashboard.py
Normal file
57
repub/web/publisher/pages/dashboard.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
|
||||
from datastar_py.quart import DatastarResponse
|
||||
from quart import Quart, Response
|
||||
|
||||
from repub.web.app import _page_patch_response, _shim_page_response, render_publisher
|
||||
|
||||
RouteGuard = Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]
|
||||
|
||||
|
||||
def register_publisher_dashboard_routes(
|
||||
app: Quart,
|
||||
*,
|
||||
publisher_required: RouteGuard,
|
||||
admin_required: RouteGuard,
|
||||
) -> None:
|
||||
@app.get("/publisher")
|
||||
@publisher_required
|
||||
async def publisher_home() -> Response:
|
||||
return _shim_page_response(
|
||||
current_path="/publisher", static_prefix="/publisher"
|
||||
)
|
||||
|
||||
@app.post("/publisher")
|
||||
@publisher_required
|
||||
async def publisher_patch() -> DatastarResponse:
|
||||
return await _page_patch_response(
|
||||
app,
|
||||
lambda _tab_id: render_publisher(
|
||||
app,
|
||||
current_path="/publisher",
|
||||
path_prefix="/publisher",
|
||||
),
|
||||
)
|
||||
|
||||
@app.get("/admin/publisher")
|
||||
@admin_required
|
||||
async def admin_publisher_home() -> Response:
|
||||
return _shim_page_response(
|
||||
current_path="/admin/publisher",
|
||||
static_prefix="/admin",
|
||||
)
|
||||
|
||||
@app.post("/admin/publisher")
|
||||
@admin_required
|
||||
async def admin_publisher_patch() -> DatastarResponse:
|
||||
return await _page_patch_response(
|
||||
app,
|
||||
lambda _tab_id: render_publisher(
|
||||
app,
|
||||
current_path="/admin/publisher",
|
||||
path_prefix="/admin/publisher",
|
||||
),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue