fix: platform admin authentication and UserContext completeness

Issues fixed:
- Platform selection returned LoginResponse requiring user timestamps,
  but UserContext doesn't have created_at/updated_at. Created dedicated
  PlatformSelectResponse that returns only token and platform info.

- UserContext was missing platform context fields (token_platform_id,
  token_platform_code). JWT token included them but they weren't
  extracted into UserContext, causing fallback warnings.

- admin_menu_config.py accessed admin_platforms (SQLAlchemy relationship)
  on UserContext (Pydantic schema). Changed to use accessible_platform_ids.

- Static file mount order in main.py caused 404 for locale files.
  More specific paths (/static/modules/X/locales) must be mounted
  before less specific paths (/static/modules/X).

Changes:
- models/schema/auth.py: Add PlatformSelectResponse, token_platform_id,
  token_platform_code, can_access_platform(), get_accessible_platform_ids()
- admin_auth.py: Use PlatformSelectResponse for select-platform endpoint
- admin_platform_service.py: Accept User | UserContext in validation
- admin_menu_config.py: Use accessible_platform_ids instead of admin_platforms
- main.py: Mount locales before static for correct path priority

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 22:31:35 +01:00
parent 9a0dd84035
commit b935592430
6 changed files with 344 additions and 20 deletions

18
main.py
View File

@@ -183,6 +183,7 @@ logger.info("=" * 80)
# Module static files must be mounted before the main /static mount
# Mount module static files FIRST (self-contained modules)
# NOTE: More specific paths must be mounted BEFORE less specific paths
MODULES_DIR = BASE_DIR / "app" / "modules"
if MODULES_DIR.exists():
for module_dir in sorted(MODULES_DIR.iterdir()):
@@ -191,20 +192,21 @@ if MODULES_DIR.exists():
module_name = module_dir.name
# Mount module static files
module_static = module_dir / "static"
if module_static.exists():
mount_path = f"/static/modules/{module_name}"
app.mount(mount_path, StaticFiles(directory=str(module_static)), name=f"{module_name}_static")
logger.info(f"Mounted module static files: {mount_path} -> {module_static}")
# Mount module locale files (for JS i18n)
# Mount module locale files FIRST (more specific path)
# Must come before static mount to avoid being intercepted
module_locales = module_dir / "locales"
if module_locales.exists():
mount_path = f"/static/modules/{module_name}/locales"
app.mount(mount_path, StaticFiles(directory=str(module_locales)), name=f"{module_name}_locales")
logger.info(f"Mounted module locales: {mount_path} -> {module_locales}")
# Mount module static files (less specific path)
module_static = module_dir / "static"
if module_static.exists():
mount_path = f"/static/modules/{module_name}"
app.mount(mount_path, StaticFiles(directory=str(module_static)), name=f"{module_name}_static")
logger.info(f"Mounted module static files: {mount_path} -> {module_static}")
# Mount main static directory AFTER module statics
if STATIC_DIR.exists():
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")