1dbf542104a2ee259d548cddbf0fbc0c8c19b4be
Risposta a richiesta Rinaldo (team BE bflows-bandi-be) per integrazione S3
folder pratica unico. Il BE scaricherà i PDF binary via nostri endpoint
e li archivierà su S3 nel folder {practice_id}/amendments/{id}/.
==ENDPOINT NUOVI (2, simmetrici)==
GET /internal/remission-amendments/{id}/document
→ PDF istruttore (amendment_document_path) binary stream
GET /internal/remission-amendments/{id}/response-document
→ PDF benef risposta (response_document_path) binary stream
Auth: X-Internal-Secret (riusa _check_internal_auth come gli altri /internal).
Risposta: application/pdf con Content-Disposition attachment + filename originale
(estratto dal pattern {sha256}-{nome} del path fisico).
==IMPLEMENTAZIONE==
- Nuovo helper _resolve_amendment_file(amendment_id, db, kind) che:
1. Carica l'amendment (404 se non esiste)
2. Seleziona il path in base al kind ('instructor' | 'response')
3. 404 se il campo è NULL (es. benef non ha ancora risposto)
4. Hardening path traversal: abs_path.resolve().relative_to(BASE_PATH)
5. 404 se file non presente su filesystem
6. Estrae safe_name dal pattern {sha}-{nome.ext}
- FileResponse streaming, media_type da amendment.*_document_type
- Import BASE_PATH + StorageError da ..storage
==TEST (8 step, /tmp/td2.py, tutti verdi)==
1. crea amendment DRAFT
2. upload PDF istruttore → HTTP 200, 526 bytes
3. GET /document → 200, byte-exact, ct=application/pdf, filename preservato
4. GET senza X-Internal-Secret → 401
5. GET amendment inesistente → 404
6. GET /response-document prima che benef allegi → 404
7. benef upload response_document
8. GET /response-document → 200, byte-exact, filename preservato
==RISPOSTA RINALDO==
- amendment_document_path NON è S3 → path FS relativo a /var/uploads
- 1 solo file per ruolo (istruttore + benef): due campi distinti in DB
- Download via questi 2 endpoint simmetrici con shared secret
- Pull-on-upload dal poller BE: dopo mark-pec-sent scarica PDF e lo archivia
S3 folder pratica; simmetrico per response_document quando il benef risponde
==NOTA MIGRAZIONE FUTURA==
app/storage.py aveva già nota 'Migrazione futura a S3/MinIO: cambiare solo
questa classe'. Questi endpoint download restano validi anche dopo migrazione
S3 lato microservizio (cambia solo impl interna di _resolve_amendment_file).
Breakdown effort a Rinaldo si aggiorna: opzione A = volume condiviso, o
opzione B = questi endpoint (ora implementati, disponibili subito).
Description
BFLOWS — gepafin-rendicontazione-api
Languages
Python
90.5%
HTML
9.2%
Dockerfile
0.3%