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:
@@ -207,9 +207,19 @@ MACHINE_QUESTION = {'operador': 'required', 'gestao': 'optional', 'admin': 'opti
|
||||
MOVERS = MANAGERS + tuple(MOVES)
|
||||
|
||||
|
||||
def _profiles(role):
|
||||
"""One profile or several: a user with more than one profile may do what
|
||||
any of them may (Marcus, 2026-11-26: operador/revisor, gestor/operador)."""
|
||||
return (role,) if isinstance(role, str) else tuple(role)
|
||||
|
||||
|
||||
def may_move(role, from_state, to_state, back=False):
|
||||
"""Whether this profile may move a card; `back` is the step back that
|
||||
undoes the move to_state -> from_state."""
|
||||
"""Whether this profile (or any of these) may move a card; `back` is the
|
||||
step back that undoes the move to_state -> from_state."""
|
||||
return any(_may_move(r, from_state, to_state, back) for r in _profiles(role))
|
||||
|
||||
|
||||
def _may_move(role, from_state, to_state, back):
|
||||
if back:
|
||||
return role in MANAGERS or (to_state, from_state) in MOVES.get(role, ())
|
||||
if to_state == 'fin':
|
||||
@@ -222,7 +232,44 @@ def may_move(role, from_state, to_state, back=False):
|
||||
def may_reorder(role, state):
|
||||
"""Changing a card's place in its column, the order it is worked in: for
|
||||
whoever takes cards forward out of it."""
|
||||
return role in MANAGERS or any(a == state and b != 'cor' for a, b in MOVES.get(role, ()))
|
||||
return any(r in MANAGERS or any(a == state and b != 'cor' for a, b in MOVES.get(r, ()))
|
||||
for r in _profiles(role))
|
||||
|
||||
|
||||
def roles_of(account):
|
||||
"""Every profile of a signed-in user, the main one first. Rows written
|
||||
before profiles became a list have only `role`."""
|
||||
return tuple(account.get('roles') or ()) or (account['role'],)
|
||||
|
||||
|
||||
def has(account, capability):
|
||||
return any(r in CAPABILITIES[capability] for r in roles_of(account))
|
||||
|
||||
|
||||
def machine_bound(account, from_state, to_state, back=False):
|
||||
"""Whether only the Operador profile allows this move, so the operator's
|
||||
machine rules apply to it: an operator who is also Revisor releases any
|
||||
machine's sheet, as a Revisor does."""
|
||||
roles = roles_of(account)
|
||||
return 'operador' in roles and not may_move([r for r in roles if r != 'operador'], from_state, to_state, back)
|
||||
|
||||
|
||||
def reorder_machine_bound(account, state):
|
||||
roles = roles_of(account)
|
||||
return 'operador' in roles and not may_reorder([r for r in roles if r != 'operador'], state)
|
||||
|
||||
|
||||
def operator_only(account, capability):
|
||||
"""Whether this capability comes to the user only through Operador."""
|
||||
roles = roles_of(account)
|
||||
return 'operador' in roles and not any(r in CAPABILITIES[capability] for r in roles if r != 'operador')
|
||||
|
||||
|
||||
def machine_question(account):
|
||||
""""Em qual máquina você está?": optional for management, required for an
|
||||
operator who is nothing more, never for the others."""
|
||||
answers = {MACHINE_QUESTION.get(r) for r in roles_of(account)}
|
||||
return 'optional' if 'optional' in answers else 'required' if 'required' in answers else None
|
||||
|
||||
|
||||
def signed_in(request: Request):
|
||||
@@ -233,7 +280,7 @@ def signed_in(request: Request):
|
||||
raise HTTPException(401, 'Entre no Kanban.')
|
||||
digest = hashlib.sha256(token.encode()).hexdigest()
|
||||
with connect() as c:
|
||||
row = c.execute('''SELECT o.id,o.email,o.name,o.role,s.machine_answered,m.id AS machine_id,m.name AS machine_name
|
||||
row = c.execute('''SELECT o.id,o.email,o.name,o.role,o.roles,s.machine_answered,m.id AS machine_id,m.name AS machine_name
|
||||
FROM dtf_local.operator_sessions s
|
||||
JOIN dtf_local.operators o ON o.email=s.username AND o.active
|
||||
LEFT JOIN dtf_local.machines m ON m.id=s.machine_id
|
||||
@@ -258,7 +305,7 @@ def can(capability):
|
||||
returns the operator's e-mail, as the routes record it."""
|
||||
def check(request: Request):
|
||||
account = signed_in(request)
|
||||
if account['role'] not in CAPABILITIES[capability]:
|
||||
if not has(account, capability):
|
||||
raise HTTPException(403, 'Seu perfil não permite esta ação.')
|
||||
return account['email']
|
||||
return check
|
||||
@@ -269,7 +316,7 @@ def can_any(*capabilities):
|
||||
and returns the operator's e-mail, as the routes record it."""
|
||||
def check(request: Request):
|
||||
account = signed_in(request)
|
||||
if not any(account['role'] in CAPABILITIES[capability] for capability in capabilities):
|
||||
if not any(has(account, capability) for capability in capabilities):
|
||||
raise HTTPException(403, 'Seu perfil não permite esta ação.')
|
||||
return account['email']
|
||||
return check
|
||||
|
||||
Reference in New Issue
Block a user