The Site's page sat at the repository root while its scripts lived in local/static, a split with no reason behind it. They are together in web/ now, with the page as index.html, which is also what the image serves. app.py held the adapters, the configuration, the shared query helpers and nineteen routes; customer.py held fourteen more but could not import from it without a cycle, so it was wired by passing nine callables into install_routes. Configuration and shared helpers move to local/runtime.py, the rules for attaching artwork to an order move to local/artwork.py where a customer correction and an operator final-file set can share them, and the routes become seven routers under local/api. app.py is 48 lines that create the application, apply the middleware and include them. Routers import downwards only. Three faults came out of the extraction and are worth recording, because each passed a check that looked sufficient. ast reports a function's line at the def, so every decorator on the line above fell outside the extracted range: twelve routes and the security middleware were defined but never registered, and the files still imported and parsed cleanly. Names the old closure renamed on the way in, and a Jsonb import, were missing in three modules. A name-resolution pass over every new module found those; the route count matching the original exactly, 32, is what confirmed the first. The release gate's marker for the fake payment adapter pointed at app.py and the adapter moved to runtime.py, so the gate passed while the condition it guards was unchanged. That is the same silent decay 2.5 set out to fix. A test now asserts every marker still matches something in its file, so the next move fails loudly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
50 lines
2.1 KiB
Python
50 lines
2.1 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 .. import db
|
|
from ..artwork import submit_files
|
|
from ..auth import operator
|
|
from ..models import ArtworkSubmission, UploadStart
|
|
from ..runtime import file_rows, operator_identity
|
|
from .uploads import begin_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(operator)):
|
|
with db.connect() as c:
|
|
row = c.execute('SELECT state FROM dtf_local.orders WHERE id=%s', (oid,)).fetchone()
|
|
if not row: raise HTTPException(404, 'Order not found')
|
|
if row['state'] not in ('rec','tra','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))
|
|
|
|
@router.post('/api/operator/uploads/{uid}/parts/{number}')
|
|
def final_part(uid: UUID, number: int, user=Depends(operator)):
|
|
return part_url(uid,number,session_id=operator_identity(user))
|
|
|
|
@router.post('/api/operator/uploads/{uid}/complete')
|
|
def final_complete(uid: UUID, user=Depends(operator)):
|
|
return complete_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(operator)):
|
|
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')
|
|
return submit_files(c,order,body,operator_identity(user),'final',user)
|