экспорт маппинга
This commit is contained in:
30
app.py
30
app.py
@@ -29,7 +29,7 @@ from ui_builder import install_ui_builder
|
||||
from khl_site.khl_data_center import APP as khl_site_app
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
BUILD_VERSION = "2026.08.19.26"
|
||||
BUILD_VERSION = "2026.08.19.28"
|
||||
# compatibility: BUILD_VERSION = "2026.08.19.24"
|
||||
# compatibility: BUILD_VERSION = "2026.08.19.22"
|
||||
load_dotenv(BASE_DIR / ".env.local", override=False)
|
||||
@@ -66,23 +66,33 @@ async def hockey_mapping_auto_refresh_shutdown() -> None:
|
||||
|
||||
@app.middleware("http")
|
||||
async def hockey_runtime_auth(request: Request, call_next):
|
||||
"""Protect runtime and prevent stale operator-interface assets."""
|
||||
if request.url.path == "/" or request.url.path.startswith("/khl-site"):
|
||||
"""Protect runtime/editor and prevent stale operator-interface assets."""
|
||||
path = request.url.path
|
||||
editor_path = (
|
||||
path == "/editor"
|
||||
or path.startswith("/api/ui-builder/editor/")
|
||||
or path.startswith("/api/ui-builder/auth/")
|
||||
)
|
||||
khl_admin_path = path.startswith("/khl-site")
|
||||
protected_path = path == "/" or khl_admin_path or editor_path
|
||||
|
||||
if protected_path:
|
||||
try:
|
||||
user = await hockey_auth.optional_user(request)
|
||||
except HTTPException as error:
|
||||
return JSONResponse({"detail": error.detail}, status_code=error.status_code)
|
||||
if user is None:
|
||||
if request.url.path.startswith("/khl-site"):
|
||||
return JSONResponse({"detail": "Требуется вход"}, status_code=401)
|
||||
return RedirectResponse("/login?reason=expired", status_code=303)
|
||||
if request.url.path.startswith("/khl-site") and not user.is_admin:
|
||||
return JSONResponse({"detail": "Раздел КХЛ доступен только администратору"}, status_code=403)
|
||||
if path in {"/", "/editor"}:
|
||||
return RedirectResponse("/login?reason=expired", status_code=303)
|
||||
return JSONResponse({"detail": "Требуется вход"}, status_code=401)
|
||||
if (khl_admin_path or editor_path) and not user.is_admin:
|
||||
if path == "/editor":
|
||||
return RedirectResponse("/", status_code=303)
|
||||
return JSONResponse({"detail": "Раздел доступен только администратору"}, status_code=403)
|
||||
request.state.wfl_user = user
|
||||
response = await call_next(request)
|
||||
path = request.url.path
|
||||
if (
|
||||
path == "/"
|
||||
path in {"/", "/editor"}
|
||||
or path.startswith("/ui-builder-assets/")
|
||||
or path.startswith("/hockey-assets/")
|
||||
or path.startswith("/api/ui-builder/runtime/")
|
||||
|
||||
Reference in New Issue
Block a user