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

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:
Cauê Faleiros
2026-11-26 10:57:20 -03:00
parent a88e7a3288
commit 4c6e2aac4a
16 changed files with 234 additions and 62 deletions

View File

@@ -54,10 +54,21 @@ const mayReorder=state=>!!ME?.reorder?.includes(state);
// others show, without drag or buttons.
const myMachine=()=>ME?.machine||null;
const isMine=order=>!!myMachine()&&order.machine?.id===myMachine().id;
const mayAct=order=>ME?.role!=='operador'||order.state==='tra'||isMine(order);
// Every profile of the user, the main one first (Marcus, 2026-11-26): what
// they may do is the sum of them.
const myRoles=()=>ME?.roles?.length?ME.roles:ME?[ME.role]:[];
const hasRole=r=>myRoles().includes(r);
const rolesLabel=roles=>roles.map(r=>ROLE_NAMES[r]||r).join(' / ');
// The moves only the Operador profile allows this user: they keep to the
// session's machine. An operator who is also Revisor releases any sheet.
const machineBound=(a,b)=>(ME?.machine_moves||[]).some(([c,d])=>c===a&&d===b);
// Printing comes to this user only through Operador: no choosing the machine by hand.
const printOnlyAsOperator=()=>hasRole('operador')&&!myRoles().some(r=>['superadmin','admin','gestao'].includes(r));
const mayAct=order=>!hasRole('operador')||order.state==='tra'||isMine(order)||
(ME?.moves||[]).some(([a,b])=>a===order.state&&!machineBound(a,b));
// Which tabs each capability opens.
// Vendedor and Financeiro consult Cotações and Números without acting there.
const consults=()=>['vendedor','financeiro'].includes(ME?.role);
const consults=()=>myRoles().some(r=>['vendedor','financeiro'].includes(r));
const TAB_NEEDS={quotes:o=>may('manage')||consults(),payments:()=>may('payments'),
stats:()=>may('manage')||consults(),site:()=>may('manage'),
integrations:()=>may('manage')||may('print')||may('label'),users:()=>may('users'),montar:()=>may('assemble')};
@@ -887,7 +898,7 @@ function showTab(name){
}
function render(){
$('who').textContent=ME?(ME.name||ME.email):'';
$('who-role').textContent=ME?(ROLE_NAMES[ME.role]||ME.role)+', '+ME.email:'';
$('who-role').textContent=ME?rolesLabel(myRoles())+', '+ME.email:'';
$('who-initials').textContent=ME?initialsOf(ME.name||ME.email):'';
$('initials').textContent=ME?initialsOf(ME.name||ME.email):'·';
$('badge-quotes').textContent=board.pending_total?String(board.pending_total):'';