feat(storage): add local storage framework
This commit is contained in:
parent
228da8f814
commit
964b545bc5
24 changed files with 890 additions and 98 deletions
|
|
@ -54,6 +54,8 @@ def can_read_activity(action: str, permissions: set[str]) -> bool:
|
|||
return "customers.read" in permissions
|
||||
if action.startswith("roles."):
|
||||
return "roles.read" in permissions
|
||||
if action.startswith("knowledge."):
|
||||
return "knowledge.read" in permissions
|
||||
if action.startswith("audit_logs."):
|
||||
return "audit_logs.read" in permissions
|
||||
if action.startswith("auth."):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Response, UploadFile, status
|
||||
from fastapi.responses import FileResponse
|
||||
|
|
@ -30,7 +29,7 @@ from app.schemas.knowledge import (
|
|||
normalize_tags,
|
||||
)
|
||||
from app.services.audit_service import sanitize, write_audit_log
|
||||
from app.services.knowledge_service import KnowledgeService, assert_safe_path
|
||||
from app.services.knowledge_service import KnowledgeService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -256,7 +255,10 @@ def delete_document(document_id: int, request: Request, db: Session = Depends(ge
|
|||
document = get_document_or_404(db, document_id)
|
||||
before_data = sanitize(document)
|
||||
label = document.title
|
||||
file_path = document.file_path
|
||||
delete_or_conflict(db, document)
|
||||
if file_path:
|
||||
KnowledgeService.delete_storage_key(file_path)
|
||||
write_audit_log(db, action="knowledge.documents.delete", entity_type="knowledge_documents", entity_id=document_id, entity_label=label, actor=current_user, request=request, before_data=before_data)
|
||||
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
|
@ -264,11 +266,7 @@ def delete_document(document_id: int, request: Request, db: Session = Depends(ge
|
|||
@router.get("/documents/{document_id:int}/download")
|
||||
def download_document(document_id: int, db: Session = Depends(get_db), current_user: User = Depends(require_permission("knowledge.download"))):
|
||||
document = get_document_or_404(db, document_id)
|
||||
if not document.file_path:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Dokument hat keine lokale Datei")
|
||||
path = assert_safe_path(Path(document.file_path))
|
||||
if not path.exists() or not path.is_file():
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Datei nicht gefunden")
|
||||
path = KnowledgeService.open_document_file(document)
|
||||
logger.info("knowledge.documents.download", extra={"actor_user_id": current_user.id, "target_document_id": document_id})
|
||||
return FileResponse(path, media_type=document.mime_type or "application/octet-stream", filename=document.file_name)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue