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

@@ -86,7 +86,7 @@ function machineCard(order){
const pulled=order.machine_pulled;
const detail=pulled?'Puxada por '+pulled.by+' em '+when(pulled.at):current?'Escolhida para este pedido':'Definida quando alguém puxar o card';
// The operator's orders go to the machine that pulls them (item 12).
if(!may('print')||ME?.role==='operador'||!board.machines?.length||waitingProof(order)||!['rec','tra','cor'].includes(order.state)){
if(!may('print')||printOnlyAsOperator()||!board.machines?.length||waitingProof(order)||!['rec','tra','cor'].includes(order.state)){
box.append(node('b',current?current.name:'Aguardando máquina'),node('span',detail));
return box;
}
@@ -193,7 +193,7 @@ function renderUsers(){
else machine.append(node('span','Sem máquina','muted'));
const open=node('td',undefined,'r');
if(editable){open.append(iconButton(IC.right,'Editar '+(u.name||u.email),()=>userForm(u),'btn sq ghost'));tr.classList.add('click');tr.onclick=()=>userForm(u);}
tr.append(who,node('td',ROLE_NAMES[u.role]+(u.active?'':', desativado')),machine,
tr.append(who,node('td',rolesLabel(u.roles||[u.role])+(u.active?'':', desativado')),machine,
node('td',u.last_login_at?ago(u.last_login_at):'nunca entrou','muted'),open);
return tr;
}));
@@ -202,7 +202,7 @@ function renderUsers(){
const editable=u.role!=='superadmin'||ME.role==='superadmin';
const row=node('button',undefined,'mli');row.type='button';row.disabled=!editable;if(editable)row.onclick=()=>userForm(u);
const words=node('span',undefined,'grow'),sub=node('span',undefined,'sub mcell');
sub.append(ROLE_NAMES[u.role]+(u.active?'':', desativado'));
sub.append(rolesLabel(u.roles||[u.role])+(u.active?'':', desativado'));
if(u.machines.length){sub.append(node('i',undefined,'mdot'),u.machines.map(machineName).join(', '));}
words.append(node('b',u.name||u.email),sub);
row.append(avatar(u),words,svgIcon(IC.right,'i m'));return row;}));
@@ -258,6 +258,10 @@ function userForm(u){
const role=choice(roles.map(r=>({value:r,label:ROLE_NAMES[r],hint:ROLE_HINTS[r]})),u?.role||'operador',
{label:'Perfil',disabled:u?.role==='superadmin'||u?.email===ME.email});
const roleField=node('div',undefined,'fld');roleField.append(node('span','Perfil'),role,role.hint);
// More than one profile (Marcus, 2026-11-26): the person may do what any of them may.
const others=pills(roles.filter(r=>r!=='superadmin').map(r=>[r,ROLE_NAMES[r]]),(u?.roles||[]).filter(r=>r!==u?.role));
if(u?.role==='superadmin'||u?.email===ME.email)others.querySelectorAll('button').forEach(b=>b.disabled=true);
const othersField=group('Outros perfis',others,node('small','Some as permissões de mais perfis, por exemplo Operador e Revisor.'));
const pass=node('input');pass.type='password';pass.minLength=8;pass.maxLength=128;pass.autocomplete='new-password';
pass.required=!editing;pass.placeholder=editing?'Deixe em branco para manter a atual':'8 caracteres ou mais';
const active=node('input');active.checked=u?u.active:true;active.disabled=u?.email===ME.email;
@@ -284,10 +288,11 @@ function userForm(u){
}
const m=formDialog(editing?u.name||u.email:'Novo usuário',{width:560,left,lead:editing?avatar(u,'bigava'):null,
text:editing?PRESENCE[presence(u)].split(':')[0]+', último acesso '+(u.last_login_at?when(u.last_login_at):'nunca'):'A pessoa entra com o e-mail e esta senha, e troca a senha em Minha conta.',
fields:[row,roleField,field(editing?'Nova senha':'Senha inicial',pass),field('Vendedor no Tiny',seller,sellerNote),checkbox('Ativo: pode entrar no sistema',active)],
fields:[row,roleField,othersField,field(editing?'Nova senha':'Senha inicial',pass),field('Vendedor no Tiny',seller,sellerNote),checkbox('Ativo: pode entrar no sistema',active)],
label:editing?'Salvar':'Criar usuário',onsave:async()=>{
const picked=seller.value?{id:Number(seller.value),name:seller.selectedOptions[0].textContent.replace(/ \(não está mais no Tiny\)$/,'')}:null;
const body={name:name.value,email:email.value,role:role.value()==='superadmin'?'admin':role.value(),active:active.checked,password:pass.value||null,tiny_seller:picked};
const main=role.value()==='superadmin'?'admin':role.value();
const body={name:name.value,email:email.value,role:main,roles:others.values().filter(r=>r!==main),active:active.checked,password:pass.value||null,tiny_seller:picked};
// An e-mail already in use is said in the form, not an error (Sentry DTF-WEB-1D).
await api(editing?'/users/'+u.id:'/users',body,{expected:[409]});
say(editing?'Usuário salvo.':'Usuário criado. Passe o e-mail e a senha inicial para a pessoa.');await loadUsers();
@@ -355,7 +360,7 @@ async function openMachineSheet(machineId, tab='situacao'){
catch(e){say(e.message,true);return;}
const machine=data.machine;
const machineState=(board.machines||[]).find(row=>row.id===machine.id)||null;
const launch=may('print')&&(ME?.role!=='operador'||myMachine()?.id===machine.id);
const launch=may('print')&&(!printOnlyAsOperator()||myMachine()?.id===machine.id);
const manage=may('manage');
let sheetModal=null;
let activeTab=tab;
@@ -594,7 +599,7 @@ function machineAlertDialog(order,machineId,alert){
return new Promise(resolve=>{
let decided=false;
const machine=(board.machines||[]).find(row=>row.id===machineId);
const allowed=ME?.role!=='operador'||myMachine()?.id===machineId;
const allowed=!printOnlyAsOperator()||myMachine()?.id===machineId;
const made=node('button','Marcar como feito','btn pri');made.type='button';
const later=node('button','Adiar uma vez','btn');later.type='button';
const back=node('button','Voltar','btn ghost right');back.type='button';
@@ -660,7 +665,7 @@ function choosePullMachine(order){
// always go to the machine of their session (DTF-WEB-4).
async function pullTo(order, machineId){
let target;
if(ME?.role==='operador'){
if(machineBound('tra','imp')){
const mine=myMachine();
if(!mine){askMachine(true);return;}
// Guidance, not an error: the pull goes to the session's machine (Sentry DTF-WEB-1A).
@@ -718,13 +723,13 @@ function accountForm(){
const next=node('input');next.type='password';next.required=true;next.minLength=8;next.autocomplete='new-password';
const again=node('input');again.type='password';again.required=true;again.minLength=8;again.autocomplete='new-password';
const dl=node('dl',undefined,'dl');
for(const [k,v] of [['E-mail',ME.email],['Perfil',ROLE_NAMES[ME.role]||ME.role],...(ME.machine_question?[['Máquina agora',myMachine()?.name||'Nenhuma']]:[])]){
for(const [k,v] of [['E-mail',ME.email],['Perfil',rolesLabel(myRoles())],...(ME.machine_question?[['Máquina agora',myMachine()?.name||'Nenhuma']]:[])]){
const d=node('div');d.append(node('dt',k),node('dd',v));dl.append(d);}
const sect=node('div',undefined,'sect');
const row=node('div',undefined,'frow');row.append(field('Nova senha',next,'8 caracteres ou mais'),field('Repita a nova senha',again));
sect.append(node('b','Trocar a senha'),field('Senha atual',current),row);
formDialog(ME.name||ME.email,{width:560,lead:avatar({name:ME.name,email:ME.email,active:true,seen_at:new Date().toISOString()},'bigava'),
text:ROLE_NAMES[ME.role]+(myMachine()?', na '+myMachine().name:''),fields:[dl,sect],
text:rolesLabel(myRoles())+(myMachine()?', na '+myMachine().name:''),fields:[dl,sect],
note:'Nome, e-mail e perfil quem muda é o administrador.',label:'Salvar senha',onsave:async()=>{
if(next.value!==again.value)throw new Error('A nova senha e a repetição não conferem.');
await api('/me/password',{current:current.value,new:next.value});say('Senha trocada.');