feat: Kanban profiles, a Usuários page, and machines that route orders
Every operator could do everything, and accounts were made from the console. Each account now has a profile, checked by the server on every action: Administrador (everything, plus users and machines), Gestão (everything but users), Operador (moves cards and handles artwork) and Vendedor (reads orders, quotes and Números, changes nothing). The superadmin is the system's own account, set from the console and kept by the account OPERATOR_EMAIL seeds; administrators cannot change it, and nobody can delete, disable or demote themselves. The Usuários tab creates, edits, disables and deletes users with a first password (there is no e-mail yet), and registers machines with the products each prints. An order goes to the first active machine that prints its product, or to the one chosen in its panel; an operator tied to machines sees and downloads only their orders. Everyone changes their own password in the account menu, which now holds the name and Sair too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,11 +7,15 @@ existing deployment keeps working unchanged.
|
||||
|
||||
Administered from the API container, the same way the schema is:
|
||||
|
||||
python -m local.operators list
|
||||
python -m local.operators add maria@example.com --name "Maria"
|
||||
python -m local.operators password maria@example.com
|
||||
python -m local.operators disable maria@example.com
|
||||
python -m local.operators enable maria@example.com
|
||||
python -m app.operators list
|
||||
python -m app.operators add maria@example.com --name "Maria" [--role admin]
|
||||
python -m app.operators role maria@example.com superadmin
|
||||
python -m app.operators password maria@example.com
|
||||
python -m app.operators disable maria@example.com
|
||||
python -m app.operators enable maria@example.com
|
||||
|
||||
The superadmin is the system's own account and is only set here; the
|
||||
administrators manage everyone else on the Kanban's Usuários page.
|
||||
|
||||
Passwords are read from the terminal, never from an argument, so they do not
|
||||
reach shell history or the process list.
|
||||
@@ -21,7 +25,7 @@ import os
|
||||
import sys
|
||||
from uuid import uuid4
|
||||
|
||||
from .core.auth import password_hash
|
||||
from .core.auth import ROLES, password_hash
|
||||
from .core.db import connect
|
||||
|
||||
MIN_PASSWORD = 12
|
||||
@@ -40,9 +44,11 @@ def seed_from_environment(cursor):
|
||||
existing = cursor.execute(
|
||||
'SELECT id FROM dtf_local.operators WHERE email=%s', (email,)).fetchone()
|
||||
if existing:
|
||||
# The configured account is the system's own: it stays superadmin.
|
||||
cursor.execute("UPDATE dtf_local.operators SET role='superadmin' WHERE email=%s", (email,))
|
||||
return None
|
||||
cursor.execute(
|
||||
'INSERT INTO dtf_local.operators(id,email,name,password_hash) VALUES(%s,%s,%s,%s)',
|
||||
"INSERT INTO dtf_local.operators(id,email,name,password_hash,role) VALUES(%s,%s,%s,%s,'superadmin')",
|
||||
(uuid4(), email, 'Operador', password_hash(password)))
|
||||
return email
|
||||
|
||||
@@ -56,14 +62,26 @@ def _ask_password(email):
|
||||
return first
|
||||
|
||||
|
||||
def add(email, name=''):
|
||||
def add(email, name='', role='admin'):
|
||||
email = email.strip().lower()
|
||||
if role not in ROLES:
|
||||
raise SystemExit('Role must be one of: ' + ', '.join(ROLES))
|
||||
with connect() as c:
|
||||
if c.execute('SELECT id FROM dtf_local.operators WHERE email=%s', (email,)).fetchone():
|
||||
raise SystemExit(f'{email} already exists. Use "password" or "enable".')
|
||||
c.execute('INSERT INTO dtf_local.operators(id,email,name,password_hash) VALUES(%s,%s,%s,%s)',
|
||||
(uuid4(), email, name, password_hash(_ask_password(email))))
|
||||
print(f'Added {email}.')
|
||||
c.execute('INSERT INTO dtf_local.operators(id,email,name,password_hash,role) VALUES(%s,%s,%s,%s,%s)',
|
||||
(uuid4(), email, name, password_hash(_ask_password(email)), role))
|
||||
print(f'Added {email} as {role}.')
|
||||
|
||||
|
||||
def set_role(email, role):
|
||||
email = email.strip().lower()
|
||||
if role not in ROLES:
|
||||
raise SystemExit('Role must be one of: ' + ', '.join(ROLES))
|
||||
with connect() as c:
|
||||
if not c.execute('UPDATE dtf_local.operators SET role=%s WHERE email=%s RETURNING id', (role, email)).fetchone():
|
||||
raise SystemExit(f'{email} does not exist.')
|
||||
print(f'{email} is now {role}.')
|
||||
|
||||
|
||||
def password(email):
|
||||
@@ -93,7 +111,7 @@ def set_active(email, active):
|
||||
|
||||
def listing():
|
||||
with connect() as c:
|
||||
rows = c.execute('''SELECT email,name,active,last_login_at FROM dtf_local.operators
|
||||
rows = c.execute('''SELECT email,name,role,active,last_login_at FROM dtf_local.operators
|
||||
ORDER BY email''').fetchall()
|
||||
if not rows:
|
||||
print('No operator accounts. Set OPERATOR_EMAIL and OPERATOR_PASSWORD and run'
|
||||
@@ -102,7 +120,7 @@ def listing():
|
||||
for row in rows:
|
||||
seen = row['last_login_at'].strftime('%Y-%m-%d %H:%M') if row['last_login_at'] else 'never'
|
||||
state = 'active ' if row['active'] else 'DISABLED'
|
||||
print(f"{state} {row['email']:<34} {row['name'][:20]:<20} last login {seen}")
|
||||
print(f"{state} {row['email']:<34} {row['name'][:20]:<20} {row['role']:<10} last login {seen}")
|
||||
|
||||
|
||||
def main(argv):
|
||||
@@ -116,7 +134,12 @@ def main(argv):
|
||||
email = rest[0]
|
||||
if command == 'add':
|
||||
name = rest[rest.index('--name') + 1] if '--name' in rest else ''
|
||||
return add(email, name)
|
||||
role = rest[rest.index('--role') + 1] if '--role' in rest else 'admin'
|
||||
return add(email, name, role)
|
||||
if command == 'role':
|
||||
if len(rest) < 2:
|
||||
raise SystemExit('usage: python -m app.operators role <email> <role>')
|
||||
return set_role(email, rest[1])
|
||||
if command == 'password':
|
||||
return password(email)
|
||||
if command == 'disable':
|
||||
|
||||
Reference in New Issue
Block a user