feat: a user may have more than one profile, and may do what any of them may (Marcus, 2026-11-26)
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 8m1s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m32s
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 8m1s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m32s
operators.roles holds every profile, the main one first; permissions, moves, the column order and the machine question are the sum. The operator's machine rules apply only to the moves Operador alone allows, so an Operador who is also Revisor releases any sheet (D-29 does not block, Marcus). Usuários gets "Outros perfis" chips next to the main profile. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,8 @@ from psycopg.types.json import Jsonb
|
||||
from ... import hotfolder, machine_log, machines, payments, proof, receipt, reviews
|
||||
from ...cart_pricing import needs_designer
|
||||
from ...core import db
|
||||
from ...core.auth import MOVERS, audit, can, may_move, may_reorder, operator
|
||||
from ...core.auth import (MOVERS, audit, can, machine_bound, may_move, may_reorder, operator, operator_only,
|
||||
reorder_machine_bound, roles_of)
|
||||
from ...core.models import Contraction, Move, Resolution, StrictModel, UploadStart
|
||||
from ...payments import release_files
|
||||
from ...printjobs import queue as queue_print_files, requeue as requeue_print_files
|
||||
@@ -89,7 +90,7 @@ class MachineChoice(StrictModel):
|
||||
@router.post('/api/operator/orders/{uid}/machine')
|
||||
def choose_machine(uid: UUID, body: MachineChoice, request: Request, user=Depends(can('print'))):
|
||||
"""Exceptional manual choice before printing; the operator's pull is final."""
|
||||
if request.state.operator['role'] == 'operador':
|
||||
if operator_only(request.state.operator, 'print'):
|
||||
raise HTTPException(403, 'A máquina do pedido é a de quem puxa para Imprimindo.')
|
||||
with db.connect() as c:
|
||||
current = c.execute('SELECT * FROM dtf_local.orders WHERE id=%s FOR UPDATE', (uid,)).fetchone()
|
||||
@@ -379,10 +380,10 @@ def queue_place(uid: UUID, body: QueuePlace, request: Request, user=Depends(oper
|
||||
if not row:
|
||||
raise HTTPException(404, 'Order not found')
|
||||
proof.require_unlocked(c, row)
|
||||
if not may_reorder(request.state.operator['role'], row['state']):
|
||||
if not may_reorder(roles_of(request.state.operator), row['state']):
|
||||
raise HTTPException(403, 'Seu perfil não muda a ordem dos pedidos desta etapa.')
|
||||
mine = request.state.operator['machine']
|
||||
if (request.state.operator['role'] == 'operador' and row['state'] != 'tra'
|
||||
if (reorder_machine_bound(request.state.operator, row['state']) and row['state'] != 'tra'
|
||||
and (not mine or str(row['machine_id'] or '') != mine['id'])):
|
||||
raise HTTPException(403, 'Este pedido é de outra máquina: só quem está nela move o card.')
|
||||
keys = {}
|
||||
@@ -406,7 +407,7 @@ def queue_place(uid: UUID, body: QueuePlace, request: Request, user=Depends(oper
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/move')
|
||||
def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
if request.state.operator['role'] not in MOVERS:
|
||||
if not set(roles_of(request.state.operator)) & set(MOVERS):
|
||||
raise HTTPException(403, 'Seu perfil não permite esta ação.')
|
||||
with db.connect() as c:
|
||||
row = c.execute('SELECT * FROM dtf_local.orders WHERE id=%s FOR UPDATE', (uid,)).fetchone()
|
||||
@@ -422,7 +423,7 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
back = BACK.get(row['state']) == body.state
|
||||
if body.state not in TRANSITIONS[row['state']] and not back:
|
||||
raise HTTPException(409, f"Não dá para ir de {STATES[row['state']]} para {STATES[body.state]}.")
|
||||
if not may_move(request.state.operator['role'], row['state'], body.state, back):
|
||||
if not may_move(roles_of(request.state.operator), row['state'], body.state, back):
|
||||
raise HTTPException(403, 'Só o Revisor manda o pedido para Finalizado.' if body.state == 'fin' and not back
|
||||
else f"Seu perfil não move pedidos de {STATES[row['state']]} para {STATES[body.state]}.")
|
||||
if body.state == 'cor' and not body.reason.strip():
|
||||
@@ -434,7 +435,9 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
account = request.state.operator
|
||||
session_machine = account['machine']
|
||||
pulling = row['state'] == 'tra' and body.state == 'imp'
|
||||
if account['role'] == 'operador':
|
||||
# The operator's machine rules, when only the Operador profile allows the move.
|
||||
bound = machine_bound(account, row['state'], body.state, back)
|
||||
if bound:
|
||||
if not session_machine:
|
||||
raise HTTPException(409, 'Escolha a máquina em que você está.')
|
||||
if not pulling and str(row['machine_id'] or '') != session_machine['id']:
|
||||
@@ -443,7 +446,7 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
chosen = body.machine_id or (UUID(session_machine['id']) if session_machine else row['machine_id'])
|
||||
if not chosen:
|
||||
raise HTTPException(409, 'Escolha a máquina que está puxando este card.')
|
||||
if account['role'] == 'operador' and str(chosen) != session_machine['id']:
|
||||
if bound and str(chosen) != session_machine['id']:
|
||||
raise HTTPException(409, f"Você está na {session_machine['name']}: o que você puxa vai para ela.")
|
||||
target = c.execute('SELECT name,products,active FROM dtf_local.machines WHERE id=%s', (chosen,)).fetchone()
|
||||
if not target or not target['active']:
|
||||
|
||||
Reference in New Issue
Block a user