fix: before approving, the panel learns that a file cannot be a final and says to treat the art (DTF-WEB-11)
All checks were successful
Build and deploy / Validate source (push) Successful in 8s
Build and deploy / Integration suite on a real stack (push) Successful in 7m15s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 2m28s

The panel offered the customer's correction (or an original) as ready to
approve, and the server refused it as not a transparent 300 DPI PNG,
an error for Sentry. POST /orders/{id}/final-check reads the header of
the order's own files with the same check as the approval and answers
200 with the problems; "Aprovar arquivo final" asks it first and, when a
file cannot be a final, says why and to use "Tratar a arte".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-23 11:52:01 -03:00
parent 6e05dd93c2
commit d51fe24eea
4 changed files with 65 additions and 6 deletions

View File

@@ -6,13 +6,15 @@ 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 pydantic import Field
from ..core import db
from .. import proof
from ..artwork import submit_files
from ..core.auth import can, can_any, operator
from ..core.models import ArtworkSubmission, UploadStart
from ..runtime import file_rows, operator_identity
from ..core.models import ArtworkSubmission, StrictModel, UploadStart
from ..printpng_validate import final_png_problem
from ..runtime import file_rows, operator_identity, storage
from .uploads import begin_upload, cancel_upload, complete_upload, part_url, upload_status
router = APIRouter()
@@ -54,6 +56,35 @@ def operator_files(oid: UUID, user=Depends(operator)):
with db.connect() as c:
return file_rows(c,oid)
class FinalCheck(StrictModel):
uploads: list[UUID] = Field(min_length=1, max_length=400)
@router.post('/api/operator/orders/{oid}/final-check')
def final_check(oid: UUID, body: FinalCheck, user=Depends(can('produce'))):
"""Whether these files of the order can be approved as its finals, asked
before approving (Sentry DTF-WEB-11): a customer's correction or an
original may not be the transparent 300 DPI PNG a final must be. The
answer lists the problems with 200, so a file to treat is guidance in
the panel, not a refusal. Only the order's own files are read."""
with db.connect() as c:
order = c.execute('SELECT snapshot FROM dtf_local.orders WHERE id=%s', (oid,)).fetchone()
if not order:
raise HTTPException(404, 'Pedido não encontrado.')
originals = {uid for item in order['snapshot']['items'] for uid in item['uploads']}
rows = c.execute('''SELECT u.id,u.name,u.object_key FROM dtf_local.uploads u WHERE u.id=ANY(%s) AND (
u.id::text=ANY(%s)
OR EXISTS (SELECT 1 FROM dtf_local.order_files f WHERE f.order_id=%s AND f.upload_id=u.id)
OR EXISTS (SELECT 1 FROM dtf_local.print_parts p WHERE p.order_id=%s AND p.upload_id=u.id))''',
(body.uploads, list(originals), oid, oid)).fetchall()
problems = []
for row in rows:
issue = final_png_problem(storage, row)
if issue:
problems.append({'upload_id': str(row['id']), 'name': row['name'], 'message': issue})
return {'problems': problems}
@router.post('/api/operator/orders/{oid}/final-files')
def final_files(oid: UUID, body: ArtworkSubmission, user=Depends(can('produce'))):
with db.connect() as c:

View File

@@ -47,12 +47,18 @@ def final_png_issue(data):
return None
def require_final_png(storage, upload):
from fastapi import HTTPException
def final_png_problem(storage, upload):
"""Why this upload cannot be a final file, or None: its name and the
header chunks of the stored file."""
if not upload['name'].lower().endswith('.png'):
raise HTTPException(422, 'O arquivo final precisa ser PNG transparente a 300 DPI. Converta PDF/TIFF antes de enviar.')
return 'O arquivo final precisa ser PNG transparente a 300 DPI. Converta PDF/TIFF antes de enviar.'
response = storage.client.get_object(Bucket=storage.bucket, Key=upload['object_key'],
Range=f'bytes=0-{HEADER_BYTES - 1}')
issue = final_png_issue(response['Body'].read())
return final_png_issue(response['Body'].read())
def require_final_png(storage, upload):
from fastapi import HTTPException
issue = final_png_problem(storage, upload)
if issue:
raise HTTPException(422, issue)