build-container / build (push) Successful in 2m20s
- Accounts: the setup code (or an existing single-user install, migrated automatically) creates the admin; the admin adds people in Settings -> People and gives each a one-time invite code to enrol their own passkey - Each person's tasks, NE Hub events and subscribe link, settings, calendar links, iCloud connection and Plex sign-in are private, stored in their own folder (/data/users/<id>/); Plex sign-in moved from browser cookies into that folder (encrypted), so it also follows them across devices - Tab access is enforced by the server (403) and reflected in the app (nav, Home, Settings, search, /api/config hides addresses of tabs a person cannot use); browser storage is namespaced per person - Admin tools: change tabs, invite a device, sign out everywhere (session epoch), turn off, make/remove admin, delete a person and their data; the last admin cannot be removed - Sessions carry the person (uid.epoch.expiry.signature); old single-user cookies still work as the admin - tools/users-test.js (83 checks: isolation, access limits, invites, sign-out/disable/delete, Plex and iCloud per person, migration) now runs in the Gitea workflow before the image is built Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
38 lines
2.4 KiB
JavaScript
38 lines
2.4 KiB
JavaScript
// The admin's tools for managing people: add someone, choose their tabs, give them a one-time invite code,
|
|
// sign them out everywhere, turn them off, or delete them and their data. Admin only (enforced by the caller).
|
|
const users = require('./users');
|
|
const auth = require('./auth');
|
|
|
|
const readBody = req => new Promise((ok, no) => { const c = []; req.on('data', d => c.push(d)); req.on('end', () => ok(Buffer.concat(c).toString())); req.on('error', no); });
|
|
const json = (res, code, obj) => { res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(obj)); };
|
|
const row = u => ({ ...users.publicView(u), tabsChosen: u.tabs || [], passkeys: auth.passkeyCount(u.id) });
|
|
|
|
async function handle(req, res, me) {
|
|
try {
|
|
const p = new URL(req.url, 'http://x').pathname.replace(/\/$/, ''), parts = p.split('/'); // ['', 'api', 'users', id?, action?]
|
|
const id = parts[3], action = parts[4];
|
|
if (!id && req.method === 'GET') return json(res, 200, { users: users.all().map(row), tabs: users.TABS.map(t => ({ id: t, label: users.TAB_LABELS[t] })), invite: { minutes: auth.INVITE_MINUTES } });
|
|
if (!id && req.method === 'POST') {
|
|
const b = JSON.parse(await readBody(req) || '{}');
|
|
const u = users.create({ name: b.name, role: 'user', tabs: b.tabs });
|
|
return json(res, 200, { user: row(u), code: auth.newInvite(u.id), minutes: auth.INVITE_MINUTES });
|
|
}
|
|
const u = users.get(id); if (!u) return json(res, 404, { error: 'Person not found' });
|
|
if (action === 'invite' && req.method === 'POST') return json(res, 200, { code: auth.newInvite(u.id), minutes: auth.INVITE_MINUTES }); // for a new device or to recover access
|
|
if (!action && req.method === 'PUT') {
|
|
const b = JSON.parse(await readBody(req) || '{}');
|
|
if (u.id === me.id && b.disabled) return json(res, 400, { error: 'You cannot turn off your own account' });
|
|
users.update(id, { name: b.name, tabs: b.tabs, role: b.role, disabled: b.disabled, signOutEverywhere: b.signOutEverywhere });
|
|
return json(res, 200, { user: row(users.get(id)) });
|
|
}
|
|
if (!action && req.method === 'DELETE') {
|
|
if (u.id === me.id) return json(res, 400, { error: 'You cannot delete your own account' });
|
|
users.remove(id); auth.removeCredsOf(id);
|
|
return json(res, 200, { ok: true });
|
|
}
|
|
json(res, 404, { error: 'Not found' });
|
|
} catch (e) { json(res, 400, { error: e.message }); }
|
|
}
|
|
|
|
module.exports = { handle };
|