Modal scroll fix; per-account editor/viewer roles

- Fix account settings modal overflow: add max-height to .modal, make
  .modal-body flex/scrollable, widen #acct-settings-modal to 620px
- Add role column to user_accounts (editor|viewer) with migration;
  existing assignments promoted to editor
- New isEditorForAccount() in auth middleware for per-account write checks
- Replace global requireEditor with per-account checks in checks.js,
  deposits.js, pdf.js, deposit-pdf.js, qbo-import.js
- GET /api/accounts now returns user_role per account
- users.js returns {account_id, role} per assignment; POST/PUT accept
  accounts as [{id, role}]
- Frontend: state.accountRole tracks effective role for active account;
  applyRoleUI and renderRow use it; user management shows role dropdown
  per account assignment
This commit is contained in:
2026-03-18 23:31:23 -06:00
parent 764def4f7d
commit af88549ad8
12 changed files with 137 additions and 41 deletions
+17
View File
@@ -99,6 +99,23 @@ if (!acctInfo.some(c => c.name === 'second_signature')) {
db.exec('ALTER TABLE account ADD COLUMN second_signature INTEGER NOT NULL DEFAULT 0');
}
// Migration: add role column to user_accounts
const uaInfo = db.prepare('PRAGMA table_info(user_accounts)').all();
if (!uaInfo.some(c => c.name === 'role')) {
db.exec(`
ALTER TABLE user_accounts RENAME TO user_accounts_old;
CREATE TABLE user_accounts (
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
account_id INTEGER NOT NULL REFERENCES account(id) ON DELETE CASCADE,
role TEXT NOT NULL DEFAULT 'viewer' CHECK(role IN ('editor','viewer')),
PRIMARY KEY (user_id, account_id)
);
INSERT INTO user_accounts (user_id, account_id, role)
SELECT user_id, account_id, 'editor' FROM user_accounts_old;
DROP TABLE user_accounts_old;
`);
}
// Create account_id indexes unconditionally (safe after migrations have run)
db.exec(`
CREATE INDEX IF NOT EXISTS idx_checks_account ON checks(account_id);