All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 5m44s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m22s
67 lines
3.2 KiB
Python
67 lines
3.2 KiB
Python
"""Operator artwork handling: final files, and the uploads that carry them.
|
|
|
|
These reuse the customer upload routes with the operator's derived identity, so
|
|
one transport serves both and there is only one place where parts are signed.
|
|
"""
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ..core import db
|
|
from .. import proof
|
|
from ..artwork import submit_files
|
|
from ..core.auth import can, operator
|
|
from ..core.models import ArtworkSubmission, UploadStart
|
|
from ..runtime import file_rows, operator_identity
|
|
from .uploads import begin_upload, cancel_upload, complete_upload, part_url, upload_status
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post('/api/operator/orders/{oid}/uploads')
|
|
def begin_final(oid: UUID, body: UploadStart, user=Depends(can('produce'))):
|
|
if not body.name.lower().endswith('.png'):
|
|
raise HTTPException(422, 'O arquivo final precisa ser PNG transparente a 300 DPI. Converta PDF/TIFF antes de enviar.')
|
|
with db.connect() as c:
|
|
row = c.execute('SELECT id,state,parent_id,proof_ok_at FROM dtf_local.orders WHERE id=%s', (oid,)).fetchone()
|
|
if not row: raise HTTPException(404, 'Order not found')
|
|
if row['parent_id']:
|
|
raise HTTPException(409, 'A prova recebe o PNG final automaticamente.')
|
|
if not proof.manual_source_needed(c, row):
|
|
proof.require_unlocked(c, row)
|
|
if row['state'] not in ('rec','cor'): raise HTTPException(409, 'Order is not in artwork review')
|
|
return begin_upload(body, session_id=operator_identity(user))
|
|
|
|
@router.get('/api/operator/uploads/{uid}')
|
|
def final_status(uid: UUID, user=Depends(operator)):
|
|
return upload_status(uid,session_id=operator_identity(user))
|
|
|
|
# The parts of an upload its operator started: a final (produce) or the
|
|
# photo of a signed pickup receipt (deliver, which includes produce).
|
|
@router.post('/api/operator/uploads/{uid}/parts/{number}')
|
|
def final_part(uid: UUID, number: int, user=Depends(can('deliver'))):
|
|
return part_url(uid,number,session_id=operator_identity(user))
|
|
|
|
@router.post('/api/operator/uploads/{uid}/complete')
|
|
def final_complete(uid: UUID, user=Depends(can('deliver'))):
|
|
return complete_upload(uid,session_id=operator_identity(user))
|
|
|
|
@router.delete('/api/operator/uploads/{uid}')
|
|
def final_cancel(uid: UUID, user=Depends(can('deliver'))):
|
|
return cancel_upload(uid,session_id=operator_identity(user))
|
|
|
|
@router.get('/api/operator/orders/{oid}/files')
|
|
def operator_files(oid: UUID, user=Depends(operator)):
|
|
with db.connect() as c:
|
|
return file_rows(c,oid)
|
|
|
|
@router.post('/api/operator/orders/{oid}/final-files')
|
|
def final_files(oid: UUID, body: ArtworkSubmission, user=Depends(can('produce'))):
|
|
with db.connect() as c:
|
|
order = c.execute('SELECT * FROM dtf_local.orders WHERE id=%s FOR UPDATE', (oid,)).fetchone()
|
|
if not order: raise HTTPException(404, 'Order not found')
|
|
if order['parent_id']:
|
|
raise HTTPException(409, 'O arquivo final da prova é gerado automaticamente. Use Gerar de novo se falhar.')
|
|
if not proof.manual_source_needed(c, order):
|
|
proof.require_unlocked(c, order)
|
|
return submit_files(c,order,body,operator_identity(user),'final',user)
|