Files
Alexis 58f164b036 feat(download-tracking): implementar seguimiento de descargas por usuario en el dashboard
Se añaden funciones para marcar publicaciones y resultados de grupo como descargados en los componentes DashboardPage y GroupResultsPage. Se optimiza la lógica de carga de publicaciones para incluir un control de estado que evita la descarga innecesaria. Además, se actualizan los mocks de publicaciones para reflejar el estado de descarga. Se mejora la presentación del texto en el componente PublicationsTable.
2026-06-03 12:27:57 +02:00

42 lines
1.2 KiB
Python

"""
Autorización para exportaciones.
Permite descargas desde la web (proxy inyecta X-API-Key) o con JWT de usuario,
pero bloquea llamadas directas anónimas sin credenciales.
"""
from __future__ import annotations
from fastapi import Depends, HTTPException, status
from app.db.models import Researcher
from app.security.api_key import api_key_header, is_valid_api_key
from app.security.jwt import get_optional_current_researcher
def require_export_access(
api_key: str | None = Depends(api_key_header),
current: Researcher | None = Depends(get_optional_current_researcher),
) -> Researcher | None:
"""
Allow export when the proxy supplies a valid API key and/or the user
sends a valid Bearer token. Prefer returning `current` when both are
present so per-user download tracking is recorded on export.
"""
if api_key is not None and not is_valid_api_key(api_key):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid API key",
)
if current is not None:
return current
if api_key is not None:
return None
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid or missing API key",
)