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:
@@ -233,3 +233,26 @@ CREATE TABLE IF NOT EXISTS dtf_local.cnpj_names (
|
||||
cnpj text PRIMARY KEY, legal_name text, trade_name text,
|
||||
fetched_at timestamptz, failed_at timestamptz
|
||||
);
|
||||
|
||||
-- Who may do what on the Kanban. superadmin is the system's own account (set
|
||||
-- from the console); administrators manage users and machines; gestão runs
|
||||
-- the business; operadores produce; vendedores only read.
|
||||
ALTER TABLE dtf_local.operators ADD COLUMN IF NOT EXISTS role text NOT NULL DEFAULT 'admin';
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE dtf_local.operators ADD CONSTRAINT operators_role
|
||||
CHECK (role IN ('superadmin','admin','gestao','operador','vendedor'));
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
-- The print machines, and which products each prints. An order goes to the
|
||||
-- first active machine that prints its product unless someone chooses one.
|
||||
CREATE TABLE IF NOT EXISTS dtf_local.machines (
|
||||
id uuid PRIMARY KEY, name text UNIQUE NOT NULL, products text[] NOT NULL DEFAULT '{}',
|
||||
active boolean NOT NULL DEFAULT true, created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS machine_id uuid REFERENCES dtf_local.machines(id) ON DELETE SET NULL;
|
||||
-- The machines an operator works on; none means every machine.
|
||||
CREATE TABLE IF NOT EXISTS dtf_local.operator_machines (
|
||||
operator_id uuid NOT NULL REFERENCES dtf_local.operators(id) ON DELETE CASCADE,
|
||||
machine_id uuid NOT NULL REFERENCES dtf_local.machines(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (operator_id, machine_id)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user