@agenticmail/enterprise 0.5.296 → 0.5.298
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-A5LURBEY.js +1519 -0
- package/dist/chunk-DZU6DQ3I.js +1519 -0
- package/dist/chunk-PNOFGWIB.js +4014 -0
- package/dist/chunk-WQRGOMQJ.js +4008 -0
- package/dist/chunk-Y3WLLVOK.js +48 -0
- package/dist/cli-agent-WSCDFYMU.js +1778 -0
- package/dist/cli-recover-NXARYVSH.js +487 -0
- package/dist/cli-serve-GTTDOLB7.js +143 -0
- package/dist/cli-serve-RRKVF3QM.js +143 -0
- package/dist/cli-verify-RKB6KQN4.js +149 -0
- package/dist/cli.js +5 -5
- package/dist/dashboard/app.js +3 -1
- package/dist/dashboard/pages/agent-detail/index.js +20 -0
- package/dist/dashboard/pages/agents.js +12 -2
- package/dist/dashboard/pages/users.js +248 -24
- package/dist/factory-M6E7YAKW.js +9 -0
- package/dist/index.js +3 -3
- package/dist/page-registry-NV4AIPCF.js +178 -0
- package/dist/postgres-LJSV5YUF.js +771 -0
- package/dist/server-CCQIW6GR.js +15 -0
- package/dist/server-VTMQY7VU.js +15 -0
- package/dist/setup-HK4WDXUL.js +20 -0
- package/dist/setup-OL4GJ53G.js +20 -0
- package/dist/sqlite-E5KKAJ24.js +503 -0
- package/package.json +1 -1
- package/src/admin/page-registry.ts +11 -5
- package/src/admin/routes.ts +66 -3
- package/src/auth/routes.ts +5 -0
- package/src/dashboard/app.js +3 -1
- package/src/dashboard/pages/agent-detail/index.js +20 -0
- package/src/dashboard/pages/agents.js +12 -2
- package/src/dashboard/pages/users.js +248 -24
- package/src/db/adapter.ts +1 -0
- package/src/db/postgres.ts +2 -0
- package/src/db/sqlite.ts +1 -0
package/src/admin/routes.ts
CHANGED
|
@@ -564,17 +564,73 @@ export function createAdminRoutes(db: DatabaseAdapter) {
|
|
|
564
564
|
return c.json({ ok: true, message: 'Password reset successfully' });
|
|
565
565
|
});
|
|
566
566
|
|
|
567
|
+
// ─── Deactivate / Reactivate User ──────────────────
|
|
568
|
+
|
|
569
|
+
api.post('/users/:id/deactivate', requireRole('admin'), async (c) => {
|
|
570
|
+
const existing = await db.getUser(c.req.param('id'));
|
|
571
|
+
if (!existing) return c.json({ error: 'User not found' }, 404);
|
|
572
|
+
const requesterId = c.get('userId');
|
|
573
|
+
if (requesterId === c.req.param('id')) return c.json({ error: 'Cannot deactivate your own account' }, 400);
|
|
574
|
+
|
|
575
|
+
try {
|
|
576
|
+
await (db as any).pool.query('UPDATE users SET is_active = FALSE, updated_at = NOW() WHERE id = $1', [c.req.param('id')]);
|
|
577
|
+
} catch {
|
|
578
|
+
const edb = (db as any).db;
|
|
579
|
+
if (edb?.prepare) edb.prepare('UPDATE users SET is_active = 0, updated_at = CURRENT_TIMESTAMP WHERE id = ?').run(c.req.param('id'));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
await db.logEvent({
|
|
583
|
+
actor: c.get('userId') || 'system', actorType: 'user', action: 'user.deactivated',
|
|
584
|
+
resource: `user:${c.req.param('id')}`, details: { targetEmail: existing.email },
|
|
585
|
+
ip: c.req.header('x-forwarded-for')?.split(',')[0]?.trim(),
|
|
586
|
+
}).catch(() => {});
|
|
587
|
+
|
|
588
|
+
return c.json({ ok: true, message: 'User deactivated' });
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
api.post('/users/:id/reactivate', requireRole('admin'), async (c) => {
|
|
592
|
+
const existing = await db.getUser(c.req.param('id'));
|
|
593
|
+
if (!existing) return c.json({ error: 'User not found' }, 404);
|
|
594
|
+
|
|
595
|
+
try {
|
|
596
|
+
await (db as any).pool.query('UPDATE users SET is_active = TRUE, updated_at = NOW() WHERE id = $1', [c.req.param('id')]);
|
|
597
|
+
} catch {
|
|
598
|
+
const edb = (db as any).db;
|
|
599
|
+
if (edb?.prepare) edb.prepare('UPDATE users SET is_active = 1, updated_at = CURRENT_TIMESTAMP WHERE id = ?').run(c.req.param('id'));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
await db.logEvent({
|
|
603
|
+
actor: c.get('userId') || 'system', actorType: 'user', action: 'user.reactivated',
|
|
604
|
+
resource: `user:${c.req.param('id')}`, details: { targetEmail: existing.email },
|
|
605
|
+
ip: c.req.header('x-forwarded-for')?.split(',')[0]?.trim(),
|
|
606
|
+
}).catch(() => {});
|
|
607
|
+
|
|
608
|
+
return c.json({ ok: true, message: 'User reactivated' });
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
// ─── Delete User (owner only, requires confirmation token) ──
|
|
612
|
+
|
|
567
613
|
api.delete('/users/:id', requireRole('owner'), async (c) => {
|
|
568
614
|
const existing = await db.getUser(c.req.param('id'));
|
|
569
615
|
if (!existing) return c.json({ error: 'User not found' }, 404);
|
|
570
616
|
|
|
571
|
-
// Cannot delete yourself
|
|
572
617
|
const requesterId = c.get('userId');
|
|
573
|
-
if (requesterId === c.req.param('id')) {
|
|
574
|
-
|
|
618
|
+
if (requesterId === c.req.param('id')) return c.json({ error: 'Cannot delete your own account' }, 400);
|
|
619
|
+
|
|
620
|
+
// Require confirmation token from frontend (5-step modal flow)
|
|
621
|
+
const body = await c.req.json().catch(() => ({}));
|
|
622
|
+
if (body.confirmationToken !== 'DELETE_USER_' + existing.email) {
|
|
623
|
+
return c.json({ error: 'Invalid confirmation. Delete requires 5-step confirmation from the dashboard.' }, 400);
|
|
575
624
|
}
|
|
576
625
|
|
|
577
626
|
await db.deleteUser(c.req.param('id'));
|
|
627
|
+
|
|
628
|
+
await db.logEvent({
|
|
629
|
+
actor: c.get('userId') || 'system', actorType: 'user', action: 'user.deleted',
|
|
630
|
+
resource: `user:${c.req.param('id')}`, details: { targetEmail: existing.email },
|
|
631
|
+
ip: c.req.header('x-forwarded-for')?.split(',')[0]?.trim(),
|
|
632
|
+
}).catch(() => {});
|
|
633
|
+
|
|
578
634
|
return c.json({ ok: true });
|
|
579
635
|
});
|
|
580
636
|
|
|
@@ -607,6 +663,13 @@ export function createAdminRoutes(db: DatabaseAdapter) {
|
|
|
607
663
|
}
|
|
608
664
|
const { PAGE_REGISTRY } = await import('./page-registry.js');
|
|
609
665
|
for (const [pageId, grant] of Object.entries(permissions)) {
|
|
666
|
+
if (pageId === '_allowedAgents') {
|
|
667
|
+
// Validate: must be '*' or string[]
|
|
668
|
+
if (grant !== '*' && !Array.isArray(grant)) {
|
|
669
|
+
return c.json({ error: '_allowedAgents must be "*" or string[]' }, 400);
|
|
670
|
+
}
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
610
673
|
if (!(pageId in PAGE_REGISTRY)) {
|
|
611
674
|
return c.json({ error: `Unknown page: ${pageId}` }, 400);
|
|
612
675
|
}
|
package/src/auth/routes.ts
CHANGED
|
@@ -275,6 +275,11 @@ export function createAuthRoutes(
|
|
|
275
275
|
return c.json({ error: 'Invalid credentials' }, 401);
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
// Check if account is deactivated
|
|
279
|
+
if (user.isActive === false) {
|
|
280
|
+
return c.json({ error: 'Your account has been deactivated by your organization. Please contact your organization administrator to restore access.' }, 403);
|
|
281
|
+
}
|
|
282
|
+
|
|
278
283
|
const { default: bcrypt } = await import('bcryptjs');
|
|
279
284
|
const valid = await bcrypt.compare(password, user.passwordHash);
|
|
280
285
|
if (!valid) {
|
package/src/dashboard/app.js
CHANGED
|
@@ -143,7 +143,9 @@ function App() {
|
|
|
143
143
|
if (!authed) return;
|
|
144
144
|
engineCall('/approvals/pending').then(d => setPendingCount((d.requests || []).length)).catch(() => {});
|
|
145
145
|
apiCall('/settings').then(d => { const s = d.settings || d || {}; if (s.primaryColor) applyBrandColor(s.primaryColor); if (s.orgId) setOrgId(s.orgId); }).catch(() => {});
|
|
146
|
-
apiCall('/me/permissions').then(d => {
|
|
146
|
+
apiCall('/me/permissions').then(d => {
|
|
147
|
+
if (d && d.permissions) setPermissions(d.permissions);
|
|
148
|
+
}).catch(() => {});
|
|
147
149
|
}, [authed]);
|
|
148
150
|
|
|
149
151
|
const logout = useCallback(() => { authCall('/logout', { method: 'POST' }).catch(() => {}).finally(() => { setAuthed(false); setUser(null); }); }, []);
|
|
@@ -57,6 +57,26 @@ export function AgentDetailPage(props) {
|
|
|
57
57
|
return false;
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
// Check agent-level access
|
|
61
|
+
var allowedAgents = perms === '*' ? '*' : (perms._allowedAgents || '*');
|
|
62
|
+
var hasAgentAccess = allowedAgents === '*' || (Array.isArray(allowedAgents) && allowedAgents.indexOf(agentId) >= 0);
|
|
63
|
+
|
|
64
|
+
if (!hasAgentAccess) {
|
|
65
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', minHeight: '60vh', textAlign: 'center', padding: 40 } },
|
|
66
|
+
h('div', { style: { width: 64, height: 64, borderRadius: '50%', background: 'var(--danger-soft, rgba(220,38,38,0.1))', display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 20 } },
|
|
67
|
+
h('svg', { width: 32, height: 32, viewBox: '0 0 24 24', fill: 'none', stroke: 'var(--danger, #dc2626)', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round' },
|
|
68
|
+
h('rect', { x: 3, y: 11, width: 18, height: 11, rx: 2, ry: 2 }),
|
|
69
|
+
h('path', { d: 'M7 11V7a5 5 0 0 1 10 0v4' })
|
|
70
|
+
)
|
|
71
|
+
),
|
|
72
|
+
h('h2', { style: { fontSize: 20, fontWeight: 700, marginBottom: 8 } }, 'Agent Access Restricted'),
|
|
73
|
+
h('p', { style: { fontSize: 14, color: 'var(--text-muted)', maxWidth: 400, lineHeight: 1.6 } },
|
|
74
|
+
'You don\'t have permission to access this agent. Contact your organization administrator to request access.'
|
|
75
|
+
),
|
|
76
|
+
h('button', { className: 'btn btn-primary', style: { marginTop: 16 }, onClick: onBack }, 'Back to Agents')
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
60
80
|
var load = function() {
|
|
61
81
|
setLoading(true);
|
|
62
82
|
Promise.all([
|
|
@@ -1125,11 +1125,21 @@ export function CreateAgentWizard({ onClose, onCreated, toast }) {
|
|
|
1125
1125
|
// ════════════════════════════════════════════════════════════
|
|
1126
1126
|
|
|
1127
1127
|
export function AgentsPage({ onSelectAgent }) {
|
|
1128
|
-
const
|
|
1128
|
+
const app = useApp();
|
|
1129
|
+
const toast = app.toast;
|
|
1129
1130
|
const [agents, setAgents] = useState([]);
|
|
1130
1131
|
const [creating, setCreating] = useState(false);
|
|
1131
1132
|
|
|
1132
|
-
const
|
|
1133
|
+
const perms = app.permissions || '*';
|
|
1134
|
+
const allowedAgents = perms === '*' ? '*' : (perms._allowedAgents || '*');
|
|
1135
|
+
|
|
1136
|
+
const load = () => apiCall('/agents').then(d => {
|
|
1137
|
+
var all = d.agents || d || [];
|
|
1138
|
+
if (allowedAgents !== '*' && Array.isArray(allowedAgents)) {
|
|
1139
|
+
all = all.filter(a => allowedAgents.indexOf(a.id) >= 0);
|
|
1140
|
+
}
|
|
1141
|
+
setAgents(all);
|
|
1142
|
+
}).catch(() => {});
|
|
1133
1143
|
useEffect(() => { load(); }, []);
|
|
1134
1144
|
|
|
1135
1145
|
// Delete moved to agent detail overview tab with triple confirmation
|
|
@@ -6,23 +6,37 @@ import { HelpButton } from '../components/help-button.js';
|
|
|
6
6
|
// ─── Permission Editor Component ───────────────────
|
|
7
7
|
|
|
8
8
|
function PermissionEditor({ userId, userName, currentPerms, pageRegistry, onSave, onClose }) {
|
|
9
|
-
// Deep clone perms
|
|
9
|
+
// Deep clone perms (skip _allowedAgents from page grants)
|
|
10
10
|
var [grants, setGrants] = useState(function() {
|
|
11
11
|
if (currentPerms === '*') {
|
|
12
|
-
// Start with all pages selected (all tabs)
|
|
13
12
|
var all = {};
|
|
14
13
|
Object.keys(pageRegistry).forEach(function(pid) { all[pid] = true; });
|
|
15
14
|
return all;
|
|
16
15
|
}
|
|
17
|
-
// Clone existing
|
|
18
16
|
var c = {};
|
|
19
17
|
Object.keys(currentPerms || {}).forEach(function(pid) {
|
|
18
|
+
if (pid === '_allowedAgents') return; // skip agent field
|
|
20
19
|
var g = currentPerms[pid];
|
|
21
20
|
c[pid] = g === true ? true : (Array.isArray(g) ? g.slice() : true);
|
|
22
21
|
});
|
|
23
22
|
return c;
|
|
24
23
|
});
|
|
25
24
|
var [fullAccess, setFullAccess] = useState(currentPerms === '*');
|
|
25
|
+
|
|
26
|
+
// Agent access control
|
|
27
|
+
var [agents, setAgents] = useState([]);
|
|
28
|
+
var [allowedAgents, setAllowedAgents] = useState(function() {
|
|
29
|
+
if (currentPerms === '*') return '*';
|
|
30
|
+
return (currentPerms || {})._allowedAgents || '*';
|
|
31
|
+
});
|
|
32
|
+
var [allAgentsAccess, setAllAgentsAccess] = useState(function() {
|
|
33
|
+
if (currentPerms === '*') return true;
|
|
34
|
+
return (currentPerms || {})._allowedAgents === '*' || !(currentPerms || {})._allowedAgents;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
useEffect(function() {
|
|
38
|
+
apiCall('/agents').then(function(d) { setAgents(d.agents || d || []); }).catch(function() {});
|
|
39
|
+
}, []);
|
|
26
40
|
var [saving, setSaving] = useState(false);
|
|
27
41
|
var [expandedPage, setExpandedPage] = useState(null);
|
|
28
42
|
|
|
@@ -86,8 +100,11 @@ function PermissionEditor({ userId, userName, currentPerms, pageRegistry, onSave
|
|
|
86
100
|
var all = {};
|
|
87
101
|
Object.keys(pageRegistry).forEach(function(pid) { all[pid] = true; });
|
|
88
102
|
setGrants(all);
|
|
103
|
+
setAllAgentsAccess(true);
|
|
104
|
+
setAllowedAgents('*');
|
|
89
105
|
} else {
|
|
90
106
|
setGrants({});
|
|
107
|
+
setAllAgentsAccess(true);
|
|
91
108
|
}
|
|
92
109
|
};
|
|
93
110
|
|
|
@@ -101,7 +118,17 @@ function PermissionEditor({ userId, userName, currentPerms, pageRegistry, onSave
|
|
|
101
118
|
var doSave = async function() {
|
|
102
119
|
setSaving(true);
|
|
103
120
|
try {
|
|
104
|
-
var permsToSave
|
|
121
|
+
var permsToSave;
|
|
122
|
+
if (fullAccess) {
|
|
123
|
+
permsToSave = '*';
|
|
124
|
+
} else {
|
|
125
|
+
permsToSave = Object.assign({}, grants);
|
|
126
|
+
if (!allAgentsAccess && Array.isArray(allowedAgents)) {
|
|
127
|
+
permsToSave._allowedAgents = allowedAgents;
|
|
128
|
+
} else {
|
|
129
|
+
permsToSave._allowedAgents = '*';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
105
132
|
await onSave(permsToSave);
|
|
106
133
|
} catch(e) { /* handled by parent */ }
|
|
107
134
|
setSaving(false);
|
|
@@ -201,11 +228,61 @@ function PermissionEditor({ userId, userName, currentPerms, pageRegistry, onSave
|
|
|
201
228
|
})
|
|
202
229
|
),
|
|
203
230
|
|
|
231
|
+
// ─── Agent Access ──────────────────────────
|
|
232
|
+
!fullAccess && h('div', { style: { marginTop: 16 } },
|
|
233
|
+
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 } },
|
|
234
|
+
h('div', null,
|
|
235
|
+
h('strong', { style: { fontSize: 13 } }, 'Agent Access'),
|
|
236
|
+
h('div', { style: { fontSize: 11, color: 'var(--text-muted)', marginTop: 1 } }, 'Which agents this user can see and manage')
|
|
237
|
+
),
|
|
238
|
+
h('label', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, cursor: 'pointer' } },
|
|
239
|
+
h('input', { type: 'checkbox', checked: allAgentsAccess, onChange: function() {
|
|
240
|
+
var newVal = !allAgentsAccess;
|
|
241
|
+
setAllAgentsAccess(newVal);
|
|
242
|
+
if (newVal) setAllowedAgents('*');
|
|
243
|
+
else setAllowedAgents([]);
|
|
244
|
+
}, style: _checkbox }),
|
|
245
|
+
'All Agents'
|
|
246
|
+
)
|
|
247
|
+
),
|
|
248
|
+
!allAgentsAccess && h('div', { style: { maxHeight: 180, overflowY: 'auto', border: '1px solid var(--border)', borderRadius: 8 } },
|
|
249
|
+
agents.length === 0
|
|
250
|
+
? h('div', { style: { padding: 16, textAlign: 'center', color: 'var(--text-muted)', fontSize: 12 } }, 'No agents found')
|
|
251
|
+
: agents.map(function(a) {
|
|
252
|
+
var checked = Array.isArray(allowedAgents) && allowedAgents.indexOf(a.id) >= 0;
|
|
253
|
+
return h('div', {
|
|
254
|
+
key: a.id,
|
|
255
|
+
style: Object.assign({}, _cs, checked ? { background: 'var(--bg-tertiary)' } : {}),
|
|
256
|
+
onClick: function() {
|
|
257
|
+
setAllowedAgents(function(prev) {
|
|
258
|
+
var arr = Array.isArray(prev) ? prev.slice() : [];
|
|
259
|
+
var idx = arr.indexOf(a.id);
|
|
260
|
+
if (idx >= 0) arr.splice(idx, 1);
|
|
261
|
+
else arr.push(a.id);
|
|
262
|
+
return arr;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
h('input', { type: 'checkbox', checked: checked, readOnly: true, style: _checkbox }),
|
|
267
|
+
h('div', { style: { flex: 1 } },
|
|
268
|
+
h('div', { style: { fontWeight: 500, fontSize: 13 } }, a.displayName || a.name || a.id),
|
|
269
|
+
a.role && h('div', { style: { fontSize: 11, color: 'var(--text-muted)' } }, a.role)
|
|
270
|
+
),
|
|
271
|
+
a.status && h('span', { className: 'badge badge-' + (a.status === 'active' || a.status === 'running' ? 'success' : 'neutral'), style: { fontSize: 9 } }, a.status)
|
|
272
|
+
);
|
|
273
|
+
})
|
|
274
|
+
),
|
|
275
|
+
!allAgentsAccess && Array.isArray(allowedAgents) && h('div', { style: { marginTop: 4, fontSize: 11, color: 'var(--text-muted)' } },
|
|
276
|
+
allowedAgents.length === 0 ? 'No agents selected — user will see no agents' : allowedAgents.length + ' agent' + (allowedAgents.length !== 1 ? 's' : '') + ' selected'
|
|
277
|
+
)
|
|
278
|
+
),
|
|
279
|
+
|
|
204
280
|
// Summary
|
|
205
281
|
h('div', { style: { marginTop: 12, padding: 8, background: 'var(--bg-tertiary)', borderRadius: 6, fontSize: 11, color: 'var(--text-muted)' } },
|
|
206
282
|
fullAccess
|
|
207
|
-
? 'This user has full access to all pages and
|
|
208
|
-
: 'Access to ' + Object.keys(grants).length + ' of ' + Object.keys(pageRegistry).length + ' pages
|
|
283
|
+
? 'This user has full access to all pages, tabs, and agents.'
|
|
284
|
+
: 'Access to ' + Object.keys(grants).length + ' of ' + Object.keys(pageRegistry).length + ' pages' +
|
|
285
|
+
(allAgentsAccess ? ', all agents.' : ', ' + (Array.isArray(allowedAgents) ? allowedAgents.length : 0) + ' agents.')
|
|
209
286
|
)
|
|
210
287
|
);
|
|
211
288
|
}
|
|
@@ -214,15 +291,31 @@ function PermissionEditor({ userId, userName, currentPerms, pageRegistry, onSave
|
|
|
214
291
|
|
|
215
292
|
function InlinePermissionPicker({ permissions, pageRegistry, onChange }) {
|
|
216
293
|
var [expandedPage, setExpandedPage] = useState(null);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
294
|
+
var [agents, setAgents] = useState([]);
|
|
295
|
+
useEffect(function() { apiCall('/agents').then(function(d) { setAgents(d.agents || d || []); }).catch(function() {}); }, []);
|
|
296
|
+
|
|
297
|
+
// Resolve grants from permissions (skip _allowedAgents)
|
|
298
|
+
var rawGrants = permissions === '*' ? (function() { var a = {}; Object.keys(pageRegistry).forEach(function(p) { a[p] = true; }); return a; })() : (permissions || {});
|
|
299
|
+
var grants = {};
|
|
300
|
+
Object.keys(rawGrants).forEach(function(k) { if (k !== '_allowedAgents') grants[k] = rawGrants[k]; });
|
|
301
|
+
var currentAllowed = permissions === '*' ? '*' : (rawGrants._allowedAgents || '*');
|
|
302
|
+
var allAgentsMode = currentAllowed === '*';
|
|
303
|
+
|
|
304
|
+
var emitChange = function(nextGrants, nextAllowed) {
|
|
305
|
+
var result = Object.assign({}, nextGrants);
|
|
306
|
+
if (nextAllowed !== undefined) result._allowedAgents = nextAllowed;
|
|
307
|
+
else if (currentAllowed !== '*') result._allowedAgents = currentAllowed;
|
|
308
|
+
var allPages = Object.keys(nextGrants).length === Object.keys(pageRegistry).length && Object.values(nextGrants).every(function(v) { return v === true; });
|
|
309
|
+
var allAg = (result._allowedAgents || '*') === '*';
|
|
310
|
+
if (allPages && allAg) return onChange('*');
|
|
311
|
+
onChange(result);
|
|
312
|
+
};
|
|
220
313
|
|
|
221
314
|
var togglePage = function(pid) {
|
|
222
315
|
var next = Object.assign({}, grants);
|
|
223
316
|
if (next[pid]) { delete next[pid]; if (expandedPage === pid) setExpandedPage(null); }
|
|
224
317
|
else { next[pid] = true; }
|
|
225
|
-
|
|
318
|
+
emitChange(next);
|
|
226
319
|
};
|
|
227
320
|
|
|
228
321
|
var toggleTab = function(pid, tabId) {
|
|
@@ -243,7 +336,7 @@ function InlinePermissionPicker({ permissions, pageRegistry, onChange }) {
|
|
|
243
336
|
next[pid] = newArr.length === allTabs.length ? true : newArr;
|
|
244
337
|
}
|
|
245
338
|
}
|
|
246
|
-
|
|
339
|
+
emitChange(next);
|
|
247
340
|
};
|
|
248
341
|
|
|
249
342
|
var isTabChecked = function(pid, tabId) {
|
|
@@ -288,14 +381,38 @@ function InlinePermissionPicker({ permissions, pageRegistry, onChange }) {
|
|
|
288
381
|
);
|
|
289
382
|
})
|
|
290
383
|
);
|
|
291
|
-
})
|
|
384
|
+
}),
|
|
385
|
+
// Agent access section
|
|
386
|
+
agents.length > 0 && h('div', { style: { marginTop: 8 } },
|
|
387
|
+
h('div', { style: { fontSize: 10, fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.05em', color: 'var(--text-muted)', padding: '4px 10px 2px' } }, 'Agent Access'),
|
|
388
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, padding: '4px 10px', fontSize: 12, cursor: 'pointer' }, onClick: function() {
|
|
389
|
+
emitChange(grants, allAgentsMode ? [] : '*');
|
|
390
|
+
} },
|
|
391
|
+
h('input', { type: 'checkbox', checked: allAgentsMode, readOnly: true, style: { width: 14, height: 14, accentColor: 'var(--primary)', cursor: 'pointer' } }),
|
|
392
|
+
h('span', { style: { fontWeight: 500 } }, 'All Agents')
|
|
393
|
+
),
|
|
394
|
+
!allAgentsMode && agents.map(function(a) {
|
|
395
|
+
var checked = Array.isArray(currentAllowed) && currentAllowed.indexOf(a.id) >= 0;
|
|
396
|
+
return h('div', { key: a.id, style: { display: 'flex', alignItems: 'center', gap: 8, padding: '3px 10px 3px 28px', fontSize: 11, cursor: 'pointer' }, onClick: function() {
|
|
397
|
+
var arr = Array.isArray(currentAllowed) ? currentAllowed.slice() : [];
|
|
398
|
+
var idx = arr.indexOf(a.id);
|
|
399
|
+
if (idx >= 0) arr.splice(idx, 1); else arr.push(a.id);
|
|
400
|
+
emitChange(grants, arr);
|
|
401
|
+
} },
|
|
402
|
+
h('input', { type: 'checkbox', checked: checked, readOnly: true, style: { width: 13, height: 13, accentColor: 'var(--primary)', cursor: 'pointer' } }),
|
|
403
|
+
h('span', null, a.displayName || a.name || a.id),
|
|
404
|
+
a.role && h('span', { style: { color: 'var(--text-muted)', marginLeft: 4 } }, '(' + a.role + ')')
|
|
405
|
+
);
|
|
406
|
+
})
|
|
407
|
+
)
|
|
292
408
|
);
|
|
293
409
|
}
|
|
294
410
|
|
|
295
411
|
// ─── Users Page ────────────────────────────────────
|
|
296
412
|
|
|
297
413
|
export function UsersPage() {
|
|
298
|
-
var
|
|
414
|
+
var app = useApp();
|
|
415
|
+
var toast = app.toast;
|
|
299
416
|
var [users, setUsers] = useState([]);
|
|
300
417
|
var [creating, setCreating] = useState(false);
|
|
301
418
|
var [form, setForm] = useState({ email: '', password: '', name: '', role: 'viewer', permissions: '*' });
|
|
@@ -343,22 +460,39 @@ export function UsersPage() {
|
|
|
343
460
|
setResetting(false);
|
|
344
461
|
};
|
|
345
462
|
|
|
346
|
-
var
|
|
463
|
+
var toggleActive = async function(user) {
|
|
464
|
+
var action = user.isActive === false ? 'reactivate' : 'deactivate';
|
|
347
465
|
var ok = await showConfirm({
|
|
348
|
-
title: '
|
|
349
|
-
message:
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
466
|
+
title: action === 'deactivate' ? 'Deactivate User' : 'Reactivate User',
|
|
467
|
+
message: action === 'deactivate'
|
|
468
|
+
? 'Deactivate "' + (user.name || user.email) + '"? They will be unable to log in and will see a message to contact their organization.'
|
|
469
|
+
: 'Reactivate "' + (user.name || user.email) + '"? They will be able to log in again.',
|
|
470
|
+
danger: action === 'deactivate',
|
|
471
|
+
confirmText: action === 'deactivate' ? 'Deactivate' : 'Reactivate'
|
|
353
472
|
});
|
|
354
473
|
if (!ok) return;
|
|
355
474
|
try {
|
|
356
|
-
await apiCall('/users/' + user.id, { method: '
|
|
357
|
-
toast('User
|
|
475
|
+
await apiCall('/users/' + user.id + '/' + action, { method: 'POST' });
|
|
476
|
+
toast('User ' + action + 'd', 'success');
|
|
358
477
|
load();
|
|
359
478
|
} catch (e) { toast(e.message, 'error'); }
|
|
360
479
|
};
|
|
361
480
|
|
|
481
|
+
var [deleteStep, setDeleteStep] = useState(0);
|
|
482
|
+
var [deleteTarget, setDeleteTarget] = useState(null);
|
|
483
|
+
var [deleteTyped, setDeleteTyped] = useState('');
|
|
484
|
+
|
|
485
|
+
var startDelete = function(user) { setDeleteTarget(user); setDeleteStep(1); setDeleteTyped(''); };
|
|
486
|
+
var cancelDelete = function() { setDeleteTarget(null); setDeleteStep(0); setDeleteTyped(''); };
|
|
487
|
+
|
|
488
|
+
var confirmDelete = async function() {
|
|
489
|
+
try {
|
|
490
|
+
await apiCall('/users/' + deleteTarget.id, { method: 'DELETE', body: JSON.stringify({ confirmationToken: 'DELETE_USER_' + deleteTarget.email }) });
|
|
491
|
+
toast('User permanently deleted', 'success');
|
|
492
|
+
cancelDelete(); load();
|
|
493
|
+
} catch (e) { toast(e.message, 'error'); }
|
|
494
|
+
};
|
|
495
|
+
|
|
362
496
|
var openPermissions = async function(user) {
|
|
363
497
|
try {
|
|
364
498
|
var d = await apiCall('/users/' + user.id + '/permissions');
|
|
@@ -485,18 +619,100 @@ export function UsersPage() {
|
|
|
485
619
|
onClose: function() { setPermTarget(null); }
|
|
486
620
|
}),
|
|
487
621
|
|
|
622
|
+
// 5-step delete confirmation modal
|
|
623
|
+
deleteTarget && h(Modal, {
|
|
624
|
+
title: 'Delete User — Step ' + deleteStep + ' of 5',
|
|
625
|
+
onClose: cancelDelete,
|
|
626
|
+
width: 480,
|
|
627
|
+
footer: h(Fragment, null,
|
|
628
|
+
h('button', { className: 'btn btn-secondary', onClick: deleteStep === 1 ? cancelDelete : function() { setDeleteStep(deleteStep - 1); } }, deleteStep === 1 ? 'Cancel' : 'Back'),
|
|
629
|
+
deleteStep < 5
|
|
630
|
+
? h('button', { className: 'btn btn-' + (deleteStep >= 3 ? 'danger' : 'primary'), onClick: function() { setDeleteStep(deleteStep + 1); } }, 'Continue')
|
|
631
|
+
: h('button', { className: 'btn btn-danger', onClick: confirmDelete, disabled: deleteTyped !== deleteTarget.email }, 'Permanently Delete')
|
|
632
|
+
)
|
|
633
|
+
},
|
|
634
|
+
// Step 1: Warning
|
|
635
|
+
deleteStep === 1 && h('div', null,
|
|
636
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 12, padding: 16, background: 'var(--danger-soft, rgba(220,38,38,0.08))', borderRadius: 8, marginBottom: 16 } },
|
|
637
|
+
h('svg', { width: 24, height: 24, viewBox: '0 0 24 24', fill: 'none', stroke: 'var(--danger)', strokeWidth: 2 }, h('path', { d: 'M12 9v4m0 4h.01M10.29 3.86l-8.6 14.86A2 2 0 0 0 3.4 21h17.2a2 2 0 0 0 1.71-2.98L13.71 3.86a2 2 0 0 0-3.42 0z' })),
|
|
638
|
+
h('div', null,
|
|
639
|
+
h('strong', null, 'Permanent Deletion'),
|
|
640
|
+
h('div', { style: { fontSize: 12, color: 'var(--text-muted)', marginTop: 2 } }, 'This action cannot be undone.')
|
|
641
|
+
)
|
|
642
|
+
),
|
|
643
|
+
h('p', { style: { fontSize: 13 } }, 'You are about to permanently delete the user account for:'),
|
|
644
|
+
h('div', { style: { padding: 12, background: 'var(--bg-tertiary)', borderRadius: 8, marginTop: 8 } },
|
|
645
|
+
h('strong', null, deleteTarget.name || 'Unnamed'), h('br'),
|
|
646
|
+
h('span', { style: { fontSize: 12, color: 'var(--text-muted)', fontFamily: 'var(--font-mono)' } }, deleteTarget.email)
|
|
647
|
+
),
|
|
648
|
+
h('p', { style: { fontSize: 12, color: 'var(--text-muted)', marginTop: 12 } }, 'Consider deactivating instead — deactivated users can be reactivated later.')
|
|
649
|
+
),
|
|
650
|
+
// Step 2: Data loss
|
|
651
|
+
deleteStep === 2 && h('div', null,
|
|
652
|
+
h('h4', { style: { marginBottom: 12 } }, 'Data That Will Be Lost'),
|
|
653
|
+
h('ul', { style: { paddingLeft: 20, fontSize: 13, lineHeight: 1.8 } },
|
|
654
|
+
h('li', null, 'All login sessions will be terminated immediately'),
|
|
655
|
+
h('li', null, 'Audit log entries will be orphaned (no user reference)'),
|
|
656
|
+
h('li', null, 'Any API keys created by this user will be revoked'),
|
|
657
|
+
h('li', null, 'Permission grants and role assignments will be removed'),
|
|
658
|
+
h('li', null, '2FA configuration and backup codes will be destroyed')
|
|
659
|
+
)
|
|
660
|
+
),
|
|
661
|
+
// Step 3: Impact
|
|
662
|
+
deleteStep === 3 && h('div', null,
|
|
663
|
+
h('h4', { style: { marginBottom: 12 } }, 'Impact Assessment'),
|
|
664
|
+
h('div', { style: { padding: 12, background: 'var(--warning-soft, rgba(245,158,11,0.08))', borderRadius: 8, fontSize: 13, lineHeight: 1.6 } },
|
|
665
|
+
h('p', null, 'If this user manages or supervises any agents, those agents will lose their manager assignment.'),
|
|
666
|
+
h('p', { style: { marginTop: 8 } }, 'If this user created approval workflows, pending approvals may become orphaned.'),
|
|
667
|
+
h('p', { style: { marginTop: 8 } }, 'Any scheduled tasks or cron jobs created by this user will continue to run but cannot be modified.')
|
|
668
|
+
)
|
|
669
|
+
),
|
|
670
|
+
// Step 4: Alternative
|
|
671
|
+
deleteStep === 4 && h('div', null,
|
|
672
|
+
h('h4', { style: { marginBottom: 12 } }, 'Are You Sure?'),
|
|
673
|
+
h('div', { style: { padding: 16, background: 'var(--success-soft, rgba(21,128,61,0.08))', borderRadius: 8, marginBottom: 16 } },
|
|
674
|
+
h('strong', null, 'Recommended alternative: Deactivate'),
|
|
675
|
+
h('p', { style: { fontSize: 12, color: 'var(--text-secondary)', marginTop: 4 } }, 'Deactivating blocks login while preserving all data. The user can be reactivated at any time. This is the safe option.')
|
|
676
|
+
),
|
|
677
|
+
h('div', { style: { padding: 16, background: 'var(--danger-soft, rgba(220,38,38,0.08))', borderRadius: 8 } },
|
|
678
|
+
h('strong', null, 'Permanent deletion'),
|
|
679
|
+
h('p', { style: { fontSize: 12, color: 'var(--text-secondary)', marginTop: 4 } }, 'Removes the user and all associated data forever. There is no recovery.')
|
|
680
|
+
)
|
|
681
|
+
),
|
|
682
|
+
// Step 5: Type email to confirm
|
|
683
|
+
deleteStep === 5 && h('div', null,
|
|
684
|
+
h('h4', { style: { marginBottom: 12, color: 'var(--danger)' } }, 'Final Confirmation'),
|
|
685
|
+
h('p', { style: { fontSize: 13, marginBottom: 12 } }, 'Type the user\'s email address to confirm permanent deletion:'),
|
|
686
|
+
h('div', { style: { padding: 8, background: 'var(--bg-tertiary)', borderRadius: 6, fontFamily: 'var(--font-mono)', fontSize: 13, textAlign: 'center', marginBottom: 12 } }, deleteTarget.email),
|
|
687
|
+
h('input', {
|
|
688
|
+
className: 'input', type: 'text', value: deleteTyped,
|
|
689
|
+
onChange: function(e) { setDeleteTyped(e.target.value); },
|
|
690
|
+
placeholder: 'Type email to confirm',
|
|
691
|
+
autoFocus: true,
|
|
692
|
+
style: { fontFamily: 'var(--font-mono)', fontSize: 13, borderColor: deleteTyped === deleteTarget.email ? 'var(--danger)' : 'var(--border)' }
|
|
693
|
+
}),
|
|
694
|
+
deleteTyped && deleteTyped !== deleteTarget.email && h('div', { style: { fontSize: 11, color: 'var(--danger)', marginTop: 4 } }, 'Email does not match')
|
|
695
|
+
)
|
|
696
|
+
),
|
|
697
|
+
|
|
488
698
|
// Users table
|
|
489
699
|
h('div', { className: 'card' },
|
|
490
700
|
h('div', { className: 'card-body-flush' },
|
|
491
701
|
users.length === 0 ? h('div', { style: { padding: 24, textAlign: 'center', color: 'var(--text-muted)' } }, 'No users')
|
|
492
702
|
: h('table', null,
|
|
493
|
-
h('thead', null, h('tr', null, h('th', null, 'Name'), h('th', null, 'Email'), h('th', null, 'Role'), h('th', null, 'Access'), h('th', null, '2FA'), h('th', null, 'Created'), h('th', { style: { width:
|
|
703
|
+
h('thead', null, h('tr', null, h('th', null, 'Name'), h('th', null, 'Email'), h('th', null, 'Role'), h('th', null, 'Status'), h('th', null, 'Access'), h('th', null, '2FA'), h('th', null, 'Created'), h('th', { style: { width: 200 } }, 'Actions'))),
|
|
494
704
|
h('tbody', null, users.map(function(u) {
|
|
495
705
|
var isRestricted = u.role === 'member' || u.role === 'viewer';
|
|
496
|
-
|
|
706
|
+
var isDeactivated = u.isActive === false;
|
|
707
|
+
var isSelf = u.id === ((app || {}).user || {}).id;
|
|
708
|
+
return h('tr', { key: u.id, style: isDeactivated ? { opacity: 0.6 } : {} },
|
|
497
709
|
h('td', null, h('strong', null, u.name || '-')),
|
|
498
710
|
h('td', null, h('span', { style: { fontFamily: 'var(--font-mono)', fontSize: 12 } }, u.email)),
|
|
499
711
|
h('td', null, h('span', { className: 'badge badge-' + (u.role === 'owner' ? 'warning' : u.role === 'admin' ? 'primary' : 'neutral') }, u.role)),
|
|
712
|
+
h('td', null, isDeactivated
|
|
713
|
+
? h('span', { className: 'badge badge-danger', style: { fontSize: 10 } }, 'Deactivated')
|
|
714
|
+
: h('span', { className: 'badge badge-success', style: { fontSize: 10 } }, 'Active')
|
|
715
|
+
),
|
|
500
716
|
h('td', null, permBadge(u)),
|
|
501
717
|
h('td', null, u.totpEnabled ? h('span', { className: 'badge badge-success' }, 'On') : h('span', { className: 'badge badge-neutral' }, 'Off')),
|
|
502
718
|
h('td', { style: { fontSize: 12, color: 'var(--text-muted)' } }, u.createdAt ? new Date(u.createdAt).toLocaleDateString() : '-'),
|
|
@@ -509,7 +725,15 @@ export function UsersPage() {
|
|
|
509
725
|
style: !isRestricted ? { opacity: 0.4 } : {}
|
|
510
726
|
}, I.shield()),
|
|
511
727
|
h('button', { className: 'btn btn-ghost btn-sm', title: 'Reset Password', onClick: function() { setResetTarget(u); setNewPassword(''); } }, I.lock()),
|
|
512
|
-
|
|
728
|
+
// Deactivate / Reactivate
|
|
729
|
+
!isSelf && h('button', {
|
|
730
|
+
className: 'btn btn-ghost btn-sm',
|
|
731
|
+
title: isDeactivated ? 'Reactivate User' : 'Deactivate User',
|
|
732
|
+
onClick: function() { toggleActive(u); },
|
|
733
|
+
style: { color: isDeactivated ? 'var(--success, #15803d)' : 'var(--warning, #f59e0b)' }
|
|
734
|
+
}, isDeactivated ? I.check() : I.pause()),
|
|
735
|
+
// Delete (owner only)
|
|
736
|
+
!isSelf && h('button', { className: 'btn btn-ghost btn-sm', title: 'Delete User Permanently', onClick: function() { startDelete(u); }, style: { color: 'var(--danger)' } }, I.trash())
|
|
513
737
|
)
|
|
514
738
|
)
|
|
515
739
|
);
|
package/src/db/adapter.ts
CHANGED
|
@@ -67,6 +67,7 @@ export interface User {
|
|
|
67
67
|
totpBackupCodes?: string; // JSON array of hashed backup codes
|
|
68
68
|
permissions?: any; // '*' or { pageId: true | string[] }
|
|
69
69
|
mustResetPassword?: boolean;
|
|
70
|
+
isActive?: boolean;
|
|
70
71
|
createdAt: Date;
|
|
71
72
|
updatedAt: Date;
|
|
72
73
|
lastLoginAt?: Date;
|
package/src/db/postgres.ts
CHANGED
|
@@ -191,6 +191,7 @@ export class PostgresAdapter extends DatabaseAdapter {
|
|
|
191
191
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS totp_backup_codes TEXT;
|
|
192
192
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS permissions JSONB DEFAULT '"*"';
|
|
193
193
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS must_reset_password BOOLEAN DEFAULT FALSE;
|
|
194
|
+
ALTER TABLE users ADD COLUMN IF NOT EXISTS is_active BOOLEAN DEFAULT TRUE;
|
|
194
195
|
`).catch(() => {});
|
|
195
196
|
await client.query('COMMIT');
|
|
196
197
|
} catch (err) {
|
|
@@ -709,6 +710,7 @@ export class PostgresAdapter extends DatabaseAdapter {
|
|
|
709
710
|
totpSecret: r.totp_secret, totpEnabled: !!r.totp_enabled, totpBackupCodes: r.totp_backup_codes,
|
|
710
711
|
permissions: r.permissions != null ? (typeof r.permissions === 'string' ? (() => { try { return JSON.parse(r.permissions); } catch { return '*'; } })() : r.permissions) : '*',
|
|
711
712
|
mustResetPassword: !!r.must_reset_password,
|
|
713
|
+
isActive: r.is_active !== false && r.is_active !== 0, // default true
|
|
712
714
|
createdAt: new Date(r.created_at), updatedAt: new Date(r.updated_at),
|
|
713
715
|
lastLoginAt: r.last_login_at ? new Date(r.last_login_at) : undefined,
|
|
714
716
|
};
|
package/src/db/sqlite.ts
CHANGED
|
@@ -62,6 +62,7 @@ export class SqliteAdapter extends DatabaseAdapter {
|
|
|
62
62
|
// Add permissions column if missing
|
|
63
63
|
try { this.db.exec(`ALTER TABLE users ADD COLUMN permissions TEXT DEFAULT '"*"'`); } catch { /* exists */ }
|
|
64
64
|
try { this.db.exec(`ALTER TABLE users ADD COLUMN must_reset_password INTEGER DEFAULT 0`); } catch { /* exists */ }
|
|
65
|
+
try { this.db.exec(`ALTER TABLE users ADD COLUMN is_active INTEGER DEFAULT 1`); } catch { /* exists */ }
|
|
65
66
|
});
|
|
66
67
|
tx();
|
|
67
68
|
}
|