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

@@ -372,6 +372,14 @@ try{
await waitFor(()=>kanban.eval(`document.querySelector('#users-list').children.length>0
&& document.querySelector('#roles-matrix').children.length>0
&& document.querySelector('#machines-list').children.length>0`),'Usuários tab, people, roles and machines');
// More than one profile (Marcus, 2026-11-26): the form offers the others as chips.
await kanban.eval('userForm()');
await waitFor(()=>kanban.eval(`[...document.querySelectorAll('.fld > span')].some(s=>s.textContent==='Outros perfis')
&& document.querySelectorAll('.fopts .fopt').length>=8`),'user form with other profiles');
await kanban.eval(`document.querySelector('.fopts .fopt').click()`);
assert.equal(await kanban.eval(`document.querySelector('.fopts .fopt').getAttribute('aria-pressed')`),'true');
await kanban.eval(`[...document.querySelectorAll('.modal .dfoot button')].find(b=>b.textContent==='Cancelar').click()`);
await waitFor(()=>kanban.eval(`!document.querySelector('.modal')`),'user form closed');
// Pagamentos and Integrações live in their own file now: both lists still render.
await kanban.click('[data-tab="payments"]');
await waitFor(()=>kanban.eval(`document.querySelector('#payments').children.length>0`),'Pagamentos tab');

53
tests/test_profiles.py Normal file
View File

@@ -0,0 +1,53 @@
"""Users with more than one profile (Marcus, 2026-11-26): what they may do is
the sum of their profiles, and an operator's machine rules apply only to the
moves that come from Operador.
Run from the repository root: python3 -m unittest tests.test_profiles -v.
"""
import unittest
from app.core.auth import has, machine_bound, machine_question, may_move, operator_only, roles_of
from tests.test_moves import moves
def user(*roles):
return {'role': roles[0], 'roles': list(roles)}
class ProfilesTest(unittest.TestCase):
def test_moves_are_the_sum_of_the_profiles(self):
self.assertEqual(moves(['operador', 'revisor']), moves('operador') | moves('revisor'))
# Gestão and Operador: the coordination's pulls back, and the operator's moves forward.
self.assertEqual(moves(['gestao', 'operador']), moves('gestao') | moves('operador'))
self.assertTrue(may_move(['gestao', 'operador'], 'tra', 'imp'))
self.assertFalse(may_move('gestao', 'tra', 'imp'))
def test_operador_and_revisor_release_what_they_printed(self):
# D-29 does not block a user with both profiles (Marcus, 2026-11-26).
self.assertTrue(may_move(['operador', 'revisor'], 'rev', 'fin'))
def test_the_machine_rules_follow_the_profile_that_allows_the_move(self):
both = user('operador', 'revisor')
self.assertTrue(machine_bound(both, 'tra', 'imp'))
self.assertTrue(machine_bound(both, 'imp', 'rev'))
self.assertFalse(machine_bound(both, 'rev', 'fin')) # as a Revisor, any machine
self.assertFalse(machine_bound(user('gestao', 'operador'), 'imp', 'cor'))
self.assertTrue(machine_bound(user('operador'), 'imp', 'rev'))
self.assertFalse(machine_bound(user('admin'), 'tra', 'imp'))
def test_capabilities_and_the_machine_question(self):
both = user('operador', 'revisor')
self.assertTrue(has(both, 'inspect') and has(both, 'print'))
self.assertTrue(operator_only(both, 'print'))
self.assertFalse(operator_only(user('gestao', 'operador'), 'print'))
self.assertEqual(machine_question(user('operador')), 'required')
self.assertEqual(machine_question(both), 'required')
self.assertEqual(machine_question(user('gestao', 'operador', 'revisor')), 'optional')
self.assertIsNone(machine_question(user('revisor')))
def test_a_row_from_before_the_list_has_its_one_profile(self):
self.assertEqual(roles_of({'role': 'designer', 'roles': []}), ('designer',))
if __name__ == '__main__':
unittest.main()

View File

@@ -231,6 +231,19 @@ def run():
reviewer.call(f'/operator/orders/{uv_o}/picked-up', {}, expected=409)
shown = next(o for o in su.call('/operator/board', operator=True)['orders'] if o['id'] == str(uv_o))
assert (shown['picked_up_by'], shown['picked_up_photo']) == (emails['revisor'], photo) and shown['picked_up_at'], shown
# More than one profile (Marcus, 2026-11-26): Revisor and Operador sum
# their moves; the operator's machine rules keep only to Operador's.
row = next(u for u in admin.call('/operator/users')['users'] if u['email'] == emails['revisor'])
admin.call(f"/operator/users/{row['id']}", {'name': 'Confere', 'email': emails['revisor'], 'role': 'revisor',
'roles': ['operador', 'revisor']})
assert next(u for u in admin.call('/operator/users')['users']
if u['email'] == emails['revisor'])['roles'] == ['revisor', 'operador']
both = reviewer.call('/operator/me')
assert both['roles'] == ['revisor', 'operador'] and both['machine_question'] == 'required', both
assert ['tra', 'imp'] in both['moves'] and ['rev', 'fin'] in both['moves'] and 'print' in both['can'], both
assert ['tra', 'imp'] in both['machine_moves'] and ['rev', 'fin'] not in both['machine_moves'], both
admin.call(f"/operator/users/{row['id']}", {'name': 'Confere', 'email': emails['revisor'], 'role': 'revisor'})
assert reviewer.call('/operator/me')['roles'] == ['revisor']
# The designer: every order, whatever its machine; the artwork stages only.
admin.call('/operator/users', {'name': 'Arte', 'email': emails['designer'], 'role': 'designer',