mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
refactor(routes): update document file access functions to use auth context instead of user variable
This commit is contained in:
parent
8e50871d43
commit
14cb0a22e9
1 changed files with 4 additions and 6 deletions
|
|
@ -10,7 +10,7 @@ from sqlalchemy import select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.auth.context import AuthContext
|
from app.auth.context import AuthContext
|
||||||
from app.db import Document, Permission, User, get_async_session
|
from app.db import Document, Permission, get_async_session
|
||||||
from app.file_storage.persistence.enums import DocumentFileKind
|
from app.file_storage.persistence.enums import DocumentFileKind
|
||||||
from app.file_storage.schemas import DocumentFileRead
|
from app.file_storage.schemas import DocumentFileRead
|
||||||
from app.file_storage.service import (
|
from app.file_storage.service import (
|
||||||
|
|
@ -25,7 +25,7 @@ router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
async def _load_readable_document(
|
async def _load_readable_document(
|
||||||
*, document_id: int, session: AsyncSession, user: User
|
*, document_id: int, session: AsyncSession, auth: AuthContext
|
||||||
) -> Document:
|
) -> Document:
|
||||||
"""Load a document the user may read, or raise 404/403."""
|
"""Load a document the user may read, or raise 404/403."""
|
||||||
document = (
|
document = (
|
||||||
|
|
@ -60,9 +60,8 @@ async def read_document_files(
|
||||||
session: AsyncSession = Depends(get_async_session),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
auth: AuthContext = Depends(get_auth_context),
|
auth: AuthContext = Depends(get_auth_context),
|
||||||
) -> list[DocumentFileRead]:
|
) -> list[DocumentFileRead]:
|
||||||
user = auth.user
|
|
||||||
"""Return metadata for every stored file of a document (gates the UI)."""
|
"""Return metadata for every stored file of a document (gates the UI)."""
|
||||||
await _load_readable_document(document_id=document_id, session=session, user=user)
|
await _load_readable_document(document_id=document_id, session=session, auth=auth)
|
||||||
records = await list_document_files(session, document_id=document_id)
|
records = await list_document_files(session, document_id=document_id)
|
||||||
return [DocumentFileRead.model_validate(r) for r in records]
|
return [DocumentFileRead.model_validate(r) for r in records]
|
||||||
|
|
||||||
|
|
@ -73,9 +72,8 @@ async def download_original_document_file(
|
||||||
session: AsyncSession = Depends(get_async_session),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
auth: AuthContext = Depends(get_auth_context),
|
auth: AuthContext = Depends(get_auth_context),
|
||||||
) -> StreamingResponse:
|
) -> StreamingResponse:
|
||||||
user = auth.user
|
|
||||||
"""Stream the document's original uploaded file."""
|
"""Stream the document's original uploaded file."""
|
||||||
await _load_readable_document(document_id=document_id, session=session, user=user)
|
await _load_readable_document(document_id=document_id, session=session, auth=auth)
|
||||||
|
|
||||||
record = await get_document_file(
|
record = await get_document_file(
|
||||||
session, document_id=document_id, kind=DocumentFileKind.ORIGINAL
|
session, document_id=document_id, kind=DocumentFileKind.ORIGINAL
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue