feat: "Tratar a arte" on an order in Arte recebida (Dropstar's third round, item 8)
All checks were successful
Build and deploy / Integration suite on a real stack (push) Successful in 3m36s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 59s
Build and deploy / Validate source (push) Successful in 5s

The order panel shows where each item's file is in the orders folder,
with Copiar: 1. Arte recebida\DTF-N-item-K, named as the automatic
folders save it (GET /api/operator/orders/{id}/folder-files). The browser
knows only the folder's name, so each computer is told once where it is
and the whole path is copied. "Subir arte tratada" sends the file saved
over; it becomes the item's final, "Arte tratada" lights and the order
can move to Arte conferida.

Only the treated item changes: the others keep their approved final,
which the server now accepts beside a new one (still refused when
nothing is new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-29 17:24:15 -03:00
parent 7f2327aea9
commit 95e7c64501
5 changed files with 153 additions and 5 deletions

View File

@@ -217,7 +217,7 @@ def with_print_files(c, orders):
generated = c.execute('''SELECT p.order_id,p.item_index,p.status,p.upload_id,p.detail,u.name
FROM dtf_local.print_files p LEFT JOIN dtf_local.uploads u ON u.id=p.upload_id
WHERE p.order_id=ANY(%s) ORDER BY p.item_index''', (ids,)).fetchall()
finals = c.execute(f'''SELECT DISTINCT f.order_id,f.item_index FROM dtf_local.order_files f
finals = c.execute(f'''SELECT f.order_id,f.item_index,f.upload_id FROM dtf_local.order_files f
JOIN dtf_local.uploads u ON u.id=f.upload_id WHERE f.order_id=ANY(%s) AND {FINAL_OK}''', (ids,)).fetchall()
# Expired ones too: once corrected, a generated file is no longer the artwork.
fixes = c.execute('''SELECT f.order_id,f.item_index,f.upload_id,u.name,
@@ -239,7 +239,10 @@ def with_print_files(c, orders):
for order in orders:
order['correction_reason'] = reasons.get(order['id']) if order['state'] == 'cor' else None
order['print_files'] = [row for row in generated if row['order_id'] == order['id']]
order['final_items'] = sorted(row['item_index'] for row in finals if row['order_id'] == order['id'])
approved = [row for row in finals if row['order_id'] == order['id']]
order['final_items'] = sorted({row['item_index'] for row in approved})
# The approved finals themselves: "Tratar a arte" keeps those it does not replace.
order['finals'] = [{'item_index': row['item_index'], 'upload_id': row['upload_id']} for row in approved]
mine = [row for row in treated if row['order_id'] == order['id']]
order['treated'] = {'items': [row['item_index'] for row in mine], 'by': mine[0]['created_by']} if mine else None
order['corrections'] = [{k: row[k] for k in ('item_index', 'upload_id', 'name', 'expired')}
@@ -1184,6 +1187,18 @@ def print_ready(c, request, states, only=None, paid_after=None):
return [row for row in rows if row['order_id'] in mine]
@router.get('/api/operator/orders/{uid}/folder-files')
def folder_files(uid: UUID, request: Request, user=Depends(can('produce'))):
"""What each item's file is called in the order's stage folder, as the
automatic folders save it: "Tratar a arte" shows where to open it."""
with db.connect() as c:
row = c.execute('SELECT state FROM dtf_local.orders WHERE id=%s', (uid,)).fetchone()
if not row:
raise HTTPException(404, 'Pedido não encontrado.')
files = named_files(print_ready(c, request, (row['state'],), only=[uid]))
return {'state': row['state'], 'files': [{'item': f['item'], 'name': f['name']} for f in files]}
@router.get('/api/operator/queue/finals')
def queue_finals(request: Request, auto: bool = False, user=Depends(can('print'))):
"""The approved final files of every order in the print queue (Arte

View File

@@ -67,7 +67,18 @@ def submit_files(c, order, body, identity, kind, actor):
expiry = first + timedelta(days=30)
if expiry <= datetime.now(timezone.utc):
raise HTTPException(410, 'Os arquivos deste pedido expiraram (30 dias).')
# A final already approved for its item may stay as it is beside a new
# one for another item: "Tratar a arte" replaces only the item treated
# (Dropstar, 2026-10-29). Something has to change, though.
current = {(row['upload_id'], row['item_index']) for row in c.execute(
"SELECT upload_id,item_index FROM dtf_local.order_files WHERE order_id=%s AND kind='final' AND active",
(order['id'],)).fetchall()} if kind == 'final' else set()
kept = {ref.upload_id for ref in body.files if (ref.upload_id, ref.item_index) in current}
if kept and len(kept) == len(body.files):
raise HTTPException(409, 'Estes já são os arquivos finais. Envie o arquivo novo.')
for ref in body.files:
if ref.upload_id in kept:
continue
corrected = correction_owner(c, order, ref, kind)
upload = upload_row(c, ref.upload_id, corrected or generated_owner(c, order, ref, kind) or identity, lock=True)
if not upload['complete']:
@@ -84,6 +95,10 @@ def submit_files(c, order, body, identity, kind, actor):
else:
c.execute('UPDATE dtf_local.order_files SET active=false WHERE order_id=%s AND kind=%s', (order['id'],kind))
for ref in body.files:
if ref.upload_id in kept:
c.execute("UPDATE dtf_local.order_files SET active=true WHERE order_id=%s AND upload_id=%s AND kind='final'",
(order['id'], ref.upload_id))
continue
c.execute('INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by) VALUES(%s,%s,%s,%s,%s,%s,%s)',
(uuid4(),order['id'],ref.upload_id,ref.item_index,kind,body.note,actor))
# The order's window, whatever the upload's own hold was.