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 6m4s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m6s
In Revisão the card gets "Revisar": a photo or a video of up to 30 s of the printed sheet, from the computer's or the phone's camera in the browser, or a file already recorded. It is attached to the order as DTF-<n>-revisao-<seq> with when and who, kept 180 days, and copied by the computers with the order folders to Kanban/Revisões/. A photo needs 1600 px on its longer side. An order above 1 m cannot reach Finalizado without one. In Finalizado the customer's order page shows the photo. The Revisor, Gestão and the administrators take it (capability "inspect"). Dialogs opened from a card's face or the board (Revisar, Editar tempos) now show over the page when the order panel is closed; inside the closed panel they were invisible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
4.3 KiB
Python
99 lines
4.3 KiB
Python
"""Routes of the review photo or video (Fase 2, front 2, app/reviews.py)."""
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import Field
|
|
|
|
from .. import reviews
|
|
from ..core import db
|
|
from ..core.auth import audit, can, operator, owner
|
|
from ..core.models import StrictModel
|
|
from ..runtime import operator_identity, owned_order, storage, upload_row
|
|
from ..scanning import require_clean
|
|
from .uploads import begin_upload
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class ReviewUploadStart(StrictModel):
|
|
"""The same shape as UploadStart, without its artwork-extension rule: a
|
|
review carries a photo or a video, not an artwork."""
|
|
name: str = Field(min_length=1, max_length=200, pattern=r'^[^/\\\x00-\x1f]+$')
|
|
size: int = Field(gt=0, strict=True)
|
|
|
|
|
|
class ReviewAdd(StrictModel):
|
|
upload_id: UUID
|
|
|
|
|
|
@router.post('/api/operator/orders/{uid}/reviews/uploads')
|
|
def start_review_upload(uid: UUID, body: ReviewUploadStart, user=Depends(can('inspect'))):
|
|
reviews.kind_of(body.name, body.size)
|
|
return begin_upload(body, session_id=operator_identity(user))
|
|
|
|
|
|
@router.post('/api/operator/orders/{uid}/reviews')
|
|
def add_review(uid: UUID, body: ReviewAdd, user=Depends(can('inspect'))):
|
|
with db.connect() as c:
|
|
order = c.execute('SELECT * FROM dtf_local.orders WHERE id=%s', (uid,)).fetchone()
|
|
if not order:
|
|
raise HTTPException(404, 'Pedido não encontrado.')
|
|
if order.get('cancelled_at'):
|
|
raise HTTPException(409, 'Pedido cancelado.')
|
|
if order['state'] != 'rev':
|
|
raise HTTPException(409, 'A revisão só entra com o pedido em Revisão.')
|
|
upload = upload_row(c, body.upload_id, operator_identity(user), lock=True)
|
|
if not upload['complete']:
|
|
raise HTTPException(409, 'Espere o envio terminar.')
|
|
require_clean(upload)
|
|
kind, ext, width, height = reviews.check(storage, upload)
|
|
row = reviews.attach(c, order, upload, kind, ext, width, height, user)
|
|
audit('order_review_added', order=str(uid), review=row['id'], kind=kind, operator=user)
|
|
return row
|
|
|
|
|
|
@router.post('/api/operator/orders/{uid}/reviews/{rid}/remove')
|
|
def remove_review(uid: UUID, rid: int, user=Depends(can('inspect'))):
|
|
with db.connect() as c:
|
|
order = c.execute('SELECT state FROM dtf_local.orders WHERE id=%s FOR UPDATE', (uid,)).fetchone()
|
|
if not order:
|
|
raise HTTPException(404, 'Pedido não encontrado.')
|
|
if order['state'] != 'rev':
|
|
raise HTTPException(409, 'A revisão só sai com o pedido ainda em Revisão.')
|
|
row = c.execute('DELETE FROM dtf_local.order_reviews WHERE id=%s AND order_id=%s RETURNING upload_id',
|
|
(rid, uid)).fetchone()
|
|
if not row:
|
|
raise HTTPException(404, 'Revisão não encontrada.')
|
|
c.execute('UPDATE dtf_local.uploads SET expires_at=now() WHERE id=%s', (row['upload_id'],))
|
|
audit('order_review_removed', order=str(uid), review=rid, operator=user)
|
|
return {'ok': True}
|
|
|
|
|
|
def _mime(name):
|
|
return reviews.FORMATS[name.rsplit('.', 1)[-1].lower()][1]
|
|
|
|
|
|
@router.get('/api/operator/orders/{uid}/reviews/{rid}/view')
|
|
def view_review(uid: UUID, rid: int, user=Depends(operator)):
|
|
with db.connect() as c:
|
|
row = c.execute('''SELECT r.kind,u.object_key,u.name FROM dtf_local.order_reviews r
|
|
JOIN dtf_local.uploads u ON u.id=r.upload_id WHERE r.id=%s AND r.order_id=%s''',
|
|
(rid, uid)).fetchone()
|
|
if not row:
|
|
raise HTTPException(404, 'Revisão não encontrada.')
|
|
return {'url': storage.view(row['object_key'], _mime(row['name'])), 'name': row['name'], 'kind': row['kind']}
|
|
|
|
|
|
@router.get('/api/customer/orders/{oid}/reviews/{rid}/view')
|
|
def customer_view_review(oid: UUID, rid: int, identity=Depends(owner)):
|
|
with db.connect() as c:
|
|
owned_order(c, oid, identity)
|
|
row = c.execute('''SELECT u.object_key,u.name FROM dtf_local.order_reviews r
|
|
JOIN dtf_local.uploads u ON u.id=r.upload_id
|
|
JOIN dtf_local.orders o ON o.id=r.order_id
|
|
WHERE r.id=%s AND r.order_id=%s AND o.state='fin' AND r.kind='photo' ''',
|
|
(rid, oid)).fetchone()
|
|
if not row:
|
|
raise HTTPException(404, 'Foto não encontrada.')
|
|
return {'url': storage.view(row['object_key'], _mime(row['name'])), 'name': row['name'], 'kind': 'photo'}
|