clavarium 0.2.254-beta.1 → 0.2.255-beta.1
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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +162 -5
- package/server/conversations.mjs +5 -0
- package/server/grants.mjs +7 -4
- package/server/main.mjs +18 -4
- package/server/people.mjs +33 -6
- package/server/resources.mjs +4 -0
- package/server/secrets.mjs +5 -1
- package/server/settingswords.mjs +2 -0
- package/web/app.js +103 -0
- package/web/index.html +4 -0
- package/web/style.css +14 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.255-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.255-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -255,7 +255,11 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
255
255
|
if (query.get('r') === WORK_TAB) {
|
|
256
256
|
const c = conversations.list().find((x) => x.name === query.get('c'));
|
|
257
257
|
if (!c || !(c.owner === m.email || m.rightsOn(m.key, c.name).includes('x'))) throw new Refusal(403, 'This conversation\'s files are not yours.');
|
|
258
|
-
} else
|
|
258
|
+
} else {
|
|
259
|
+
/* Its own folder, or one given to it or to one of its groups (#431): reading needs r, writing w. */
|
|
260
|
+
const has = m.folderRights(query.get('r') ?? '');
|
|
261
|
+
if (!has.includes(need === 'write' ? 'w' : 'r')) throw new Refusal(403, need === 'write' && has ? 'This folder is given to you to read only.' : 'This folder is not yours.');
|
|
262
|
+
}
|
|
259
263
|
if (!m.still()) throw new Refusal(403, 'This account may not use this page now.');
|
|
260
264
|
}
|
|
261
265
|
/* The conversation's own work folder, when the server keeps it. */
|
|
@@ -380,14 +384,16 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
380
384
|
the administrators' conversations' names. */
|
|
381
385
|
if (pathname === '/api/resources' && resources && request.member) {
|
|
382
386
|
const mine = new Set(request.member.grantsOf().map((g) => g.name));
|
|
383
|
-
|
|
387
|
+
const given = new Set(request.member.folders());
|
|
388
|
+
return send(200, resources.list().filter((r) => r.owner === request.member.email || (r.type === 'folder' && given.has(r.name))).map((r) => ({ ...r, mine: r.owner === request.member.email, access: request.member.folderRights(r.name).includes('w') ? 'write' : 'read', attachments: Object.fromEntries(Object.entries(r.attachments ?? {}).filter(([c]) => mine.has(c))) }))), true;
|
|
384
389
|
}
|
|
385
390
|
if (pathname === '/api/resources' && resources) return send(200, resources.list()), true;
|
|
386
391
|
if (pathname === '/api/shortcuts' && shortcuts) return send(200, shortcuts.list()), true;
|
|
387
392
|
/* A member's (#431 step 2): its own keys' names, and which of ITS conversations has each. */
|
|
388
393
|
if (pathname === '/api/secrets' && secrets && request.member) {
|
|
389
394
|
const mine = new Set(request.member.grantsOf().map((g) => g.name));
|
|
390
|
-
|
|
395
|
+
const given = new Set(request.member.keys());
|
|
396
|
+
return send(200, secrets.list().filter((x) => !x.hostOnly && (x.owner === request.member.email || given.has(x.name))).map((x) => ({ ...x, mine: x.owner === request.member.email, conversations: (x.conversations ?? []).filter((c) => mine.has(typeof c === 'string' ? c : c?.name)) }))), true;
|
|
391
397
|
}
|
|
392
398
|
if (pathname === '/api/secrets' && secrets) return send(200, secrets.list()), true;
|
|
393
399
|
/* The providers and models OpenCode knows (models.dev), for a conversation made with it (03-11). */
|
|
@@ -526,6 +532,22 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
526
532
|
if (pathname === '/api/wifi/scan' && wifi) return send(200, await wifi.scan()), true;
|
|
527
533
|
if (pathname === '/api/meshcentral' && meshcentral) return send(200, await meshcentral.status()), true;
|
|
528
534
|
/* Each account with its role and, for a member, the conversations it was given (#419). */
|
|
535
|
+
/* WHO HAS ACCESS TO ONE THING (#431): its owner, its group and level, the people given it besides -- the one
|
|
536
|
+
block every conversation's and folder's page shows (web/app.js, accessBlock). */
|
|
537
|
+
const whoHas = /^\/api\/(conversations|resources)\/([a-z][a-z0-9-]{0,31})\/access$/.exec(pathname) ?? /^\/api\/(secrets)\/([A-Z][A-Z0-9_]{0,39})\/access$/.exec(pathname);
|
|
538
|
+
if (whoHas && team?.grants) {
|
|
539
|
+
const isConv = whoHas[1] === 'conversations'; const isKey = whoHas[1] === 'secrets'; const name = whoHas[2];
|
|
540
|
+
const thing = isConv ? conversations.list().find((c) => c.name === name) : isKey ? secrets?.record?.(name) : resources?.get(name);
|
|
541
|
+
if (!thing) throw new Refusal(404, isConv ? 'No such conversation.' : isKey ? 'No such key.' : 'No such folder.');
|
|
542
|
+
const on = team.grants.on(`${isConv ? 'conversation' : isKey ? 'secret' : 'folder'}:${name}`);
|
|
543
|
+
const group = thing.accessGroup ?? null;
|
|
544
|
+
return send(200, {
|
|
545
|
+
owner: thing.owner ?? null, group, groupRights: group ? (on.find((g) => g.subject === `group:${group}`)?.rights ?? '') : '',
|
|
546
|
+
people: on.filter((g) => g.subject.startsWith('person:') && g.subject !== `person:${thing.owner}`).map((g) => ({ email: g.subject.slice('person:'.length), rights: g.rights })),
|
|
547
|
+
groups: team.people?.groups?.().map((g) => g.name) ?? [], accounts: team.list().map((o) => ({ email: o.email, role: team.people?.roleOf(o.email) ?? 'admin' })),
|
|
548
|
+
}), true;
|
|
549
|
+
}
|
|
550
|
+
if (pathname === '/api/groups' && team?.people) return send(200, { groups: team.people.groups().map((g) => ({ ...g, given: team.grants?.of(`group:${g.name}`, 'conversation').map((x) => ({ name: x.name, rights: x.rights })) ?? [] })) }), true;
|
|
529
551
|
if (pathname === '/api/operators') return send(200, team ? { operators: team.list().map((o) => ({ ...o, role: team.people?.roleOf(o.email) ?? 'admin', ...(team.people?.roleOf(o.email) === 'member' ? { given: team.grants?.of(`person:${o.email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) ?? [], quota: team.people?.quotaOf?.(o.email) ?? null } : {}) })), me: identity, defaultRole: team.people?.defaultRole?.() ?? 'admin' } : { local: true }), true;
|
|
530
552
|
if (pathname === '/api/binder/people' && binders) return send(200, { people: binders.people(identity), changes: `${BOOT}:${binders.changes()}` }), true;
|
|
531
553
|
if (pathname === '/api/certificate' && certificate) return send(200, await certificate.about({ fresh: query.get('fresh') === '1' })), true;
|
|
@@ -733,6 +755,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
733
755
|
if (unlisted && resources) {
|
|
734
756
|
const gone = resources.get(unlisted[1]);
|
|
735
757
|
await resources.remove(unlisted[1]); mailboxes?.forget(unlisted[1]); gitReview?.forget(unlisted[1]);
|
|
758
|
+
/* What people and groups were given of it goes with it (#431): a folder made again by that name is nobody's but its maker's. */
|
|
759
|
+
team?.grants?.forgetAsset(`folder:${unlisted[1]}`);
|
|
736
760
|
/* A device that had been given it loses it. */
|
|
737
761
|
if (gone) sharing?.devices.forgetAsset(resources.assetOf(gone));
|
|
738
762
|
return send(200, { ok: true }), true;
|
|
@@ -869,6 +893,135 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
869
893
|
team.people.changed?.();
|
|
870
894
|
return send(200, { given: team.grants.of(`person:${email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) }), true;
|
|
871
895
|
}
|
|
896
|
+
/* A FOLDER TAKEN BACK (audit 29-11): wherever a member had attached it to its own conversation, the attachment
|
|
897
|
+
follows what the member still has of it -- written down to read, or detached. Never left writing. */
|
|
898
|
+
const folderRightsOf = (email, folder) => {
|
|
899
|
+
if (resources?.get(folder)?.owner === email) return 'rw';
|
|
900
|
+
const subjects = [`person:${email}`, ...(team?.people?.groupsOf?.(email) ?? []).map((g) => `group:${g}`)];
|
|
901
|
+
return [...new Set(subjects.flatMap((s) => [...(team?.grants?.rightsOf(s, `folder:${folder}`) ?? '')]))].join('');
|
|
902
|
+
};
|
|
903
|
+
/* A KEY TAKEN BACK (#431): off every member's own conversation that may no longer use it. */
|
|
904
|
+
const reconcileKeys = async () => {
|
|
905
|
+
for (const k of secrets?.list?.() ?? []) {
|
|
906
|
+
if (k.hostOnly) continue;
|
|
907
|
+
for (const c of k.conversations ?? []) {
|
|
908
|
+
const cname = typeof c === 'string' ? c : c?.name;
|
|
909
|
+
const owner = conversations.list().find((x) => x.name === cname)?.owner;
|
|
910
|
+
if (!owner || team?.people?.roleOf?.(owner) !== 'member') continue;
|
|
911
|
+
const subjects = [`person:${owner}`, ...(team?.people?.groupsOf?.(owner) ?? []).map((g) => `group:${g}`)];
|
|
912
|
+
const may = secrets.ownerOf(k.name) === owner || subjects.some((s) => (team?.grants?.rightsOf(s, `secret:${k.name}`) ?? '').includes('x'));
|
|
913
|
+
if (!may) {
|
|
914
|
+
try {
|
|
915
|
+
secrets.attach(cname, k.name, false);
|
|
916
|
+
const c2 = conversations.list().find((x) => x.name === cname);
|
|
917
|
+
if (c2?.phase === 'ready' && !c2.asleep) await secrets.deliver(cname).catch(() => {});
|
|
918
|
+
void guide?.changed(cname).catch(() => {});
|
|
919
|
+
} catch { /* said by the next look */ }
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
const reconcileFolders = async (only) => {
|
|
925
|
+
await reconcileKeys();
|
|
926
|
+
for (const r of resources?.list?.() ?? []) {
|
|
927
|
+
if (only && r.name !== only) continue;
|
|
928
|
+
for (const [c, access] of Object.entries(r.attachments ?? {})) {
|
|
929
|
+
const owner = conversations.list().find((x) => x.name === c)?.owner;
|
|
930
|
+
if (!owner || team?.people?.roleOf?.(owner) !== 'member') continue;
|
|
931
|
+
const has = folderRightsOf(owner, r.name);
|
|
932
|
+
const want = has.includes('w') ? access : has.includes('r') ? 'read' : 'none';
|
|
933
|
+
if (want !== access) { try { await resources.attach(c, r.name, want); void guide?.changed(c).catch(() => {}); } catch { /* said by the next look */ } }
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
/* CHOWN AND CHMOD (#431): each conversation and each folder has an owner (a person; none: the administrators),
|
|
938
|
+
a group with a level, and gifts to a person besides. */
|
|
939
|
+
const chown = /^\/api\/(conversations|resources)\/([a-z][a-z0-9-]{0,31})\/(owner|group|person)$/.exec(pathname) ?? /^\/api\/(secrets)\/([A-Z][A-Z0-9_]{0,39})\/(owner|group|person)$/.exec(pathname);
|
|
940
|
+
if (chown && team?.people && team.grants) {
|
|
941
|
+
const [, kind, name, what] = chown;
|
|
942
|
+
const isConv = kind === 'conversations'; const isKey = kind === 'secrets';
|
|
943
|
+
const thing = isConv ? conversations.list().find((c) => c.name === name) : isKey ? secrets?.record?.(name) : resources?.get(name);
|
|
944
|
+
if (!thing) throw new Refusal(404, isConv ? 'No such conversation.' : isKey ? 'No such key.' : 'No such folder.');
|
|
945
|
+
if (!isConv && !isKey && thing.type !== 'folder') throw new Refusal(400, 'Only a folder has an owner and a group here.');
|
|
946
|
+
const asset = `${isConv ? 'conversation' : isKey ? 'secret' : 'folder'}:${name}`;
|
|
947
|
+
const rightsFrom = (b) => (isConv ? `${b.chat === 'write' ? 'rw' : b.chat === 'read' ? 'r' : ''}${b.terminal === true ? 'x' : ''}` : isKey ? (b.use === true ? 'x' : '') : (b.access === 'write' ? 'rw' : b.access === 'read' ? 'r' : ''));
|
|
948
|
+
if (what === 'owner') {
|
|
949
|
+
const owner = String(body.owner ?? '').trim().toLowerCase();
|
|
950
|
+
if (owner && !team.list().some((o) => o.email === owner)) throw new Refusal(404, 'No such account.');
|
|
951
|
+
if (isConv && owner && team.people.roleOf(owner) === 'member') {
|
|
952
|
+
/* Within the new owner's room (audit 29-11): its own conversations count there. */
|
|
953
|
+
const q = team.people.quotaOf(owner); const others = conversations.list().filter((c) => c.owner === owner && c.name !== name);
|
|
954
|
+
const used = { mb: others.reduce((n, c) => n + (c.memoryMb ?? 0), 0), diskGb: others.reduce((n, c) => n + (c.diskGb ?? 0), 0), cpus: others.reduce((n, c) => n + (c.cpus ?? 1), 0) };
|
|
955
|
+
for (const [k, what, field, def] of [['mb', 'memory', 'memoryMb', 0], ['diskGb', 'disk', 'diskGb', 0], ['cpus', 'cores', 'cpus', 1]]) {
|
|
956
|
+
if (k === 'mb' ? !(q.mb > 0) : false) throw new Refusal(409, `${owner} has no room for conversations of its own: give it some first (Settings > Accounts).`);
|
|
957
|
+
if (q[k] > 0 && used[k] + (thing[field] ?? def) > q[k]) throw new Refusal(409, `Not enough ${what} left in ${owner}'s room for this conversation.`);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
if (isConv) {
|
|
961
|
+
conversations.setOwner?.(name, owner || undefined);
|
|
962
|
+
/* The new owner has it whole; the one before keeps nothing of being its owner. */
|
|
963
|
+
if (thing.owner) team.grants.take(`person:${thing.owner}`, asset);
|
|
964
|
+
if (owner && team.people.roleOf(owner) === 'member') team.grants.give(`person:${owner}`, asset, 'rwx');
|
|
965
|
+
} else if (isKey) { secrets.setOwner(name, owner || undefined); await reconcileKeys(); } else { resources.setOwner?.(name, owner || undefined); await reconcileFolders(name); }
|
|
966
|
+
/* The one before: its open terminal ends now, not at the next minute's look (audit 29-11). */
|
|
967
|
+
team.people.changed?.();
|
|
968
|
+
events?.fromRequest?.(pathname, body, identity, { owner });
|
|
969
|
+
return send(200, { ok: true, owner: owner || null }), true;
|
|
970
|
+
}
|
|
971
|
+
if (what === 'group') {
|
|
972
|
+
const group = String(body.group ?? '');
|
|
973
|
+
/* Checked before anything changes (audit 29-11): a wrong name leaves it as it was. */
|
|
974
|
+
if (group && !team.people.groups().some((g) => g.name === group)) throw new Refusal(404, 'No such group.');
|
|
975
|
+
const before = thing.accessGroup;
|
|
976
|
+
if (before) team.grants.take(`group:${before}`, asset);
|
|
977
|
+
const rights = group ? rightsFrom(body) : '';
|
|
978
|
+
if (group && rights) team.grants.give(`group:${group}`, asset, rights);
|
|
979
|
+
if (isConv) conversations.setAccessGroup?.(name, group && rights ? group : undefined); else if (isKey) { secrets.setAccessGroup(name, group && rights ? group : undefined); await reconcileKeys(); } else { resources.setAccessGroup?.(name, group && rights ? group : undefined); await reconcileFolders(name); }
|
|
980
|
+
team.people.changed?.();
|
|
981
|
+
return send(200, { ok: true, group: group && rights ? group : null, rights }), true;
|
|
982
|
+
}
|
|
983
|
+
const email = String(body.email ?? '').trim().toLowerCase();
|
|
984
|
+
if (!team.list().some((o) => o.email === email)) throw new Refusal(404, 'No such account.');
|
|
985
|
+
if (team.people.roleOf(email) !== 'member') throw new Refusal(409, 'An administrator has everything already.');
|
|
986
|
+
const rights = rightsFrom(body);
|
|
987
|
+
if (rights) team.grants.give(`person:${email}`, asset, rights); else team.grants.take(`person:${email}`, asset);
|
|
988
|
+
if (!isConv) await reconcileFolders(name);
|
|
989
|
+
team.people.changed?.();
|
|
990
|
+
return send(200, { ok: true }), true;
|
|
991
|
+
}
|
|
992
|
+
/* GROUPS OF PEOPLE (#431 step 3): made, changed (their people), removed -- what was given to one goes with it;
|
|
993
|
+
given a conversation (its chat and/or terminal) or taken back, as a member is. */
|
|
994
|
+
if (pathname === '/api/groups' && team?.people) {
|
|
995
|
+
const gname = String(body.name ?? '');
|
|
996
|
+
const exists = team.people.groups().some((g) => g.name === gname);
|
|
997
|
+
/* A new group by a name in use: refused, never emptied (audit 29-11); a new one starts with no right left from before. */
|
|
998
|
+
if (body.create === true && exists) throw new Refusal(409, 'A group already has this name.');
|
|
999
|
+
const groups = team.people.setGroup(gname, body.people ?? []);
|
|
1000
|
+
if (!exists) team.grants?.forgetSubject(`group:${gname}`);
|
|
1001
|
+
await reconcileFolders();
|
|
1002
|
+
return send(200, { groups }), true;
|
|
1003
|
+
}
|
|
1004
|
+
const grouped = /^\/api\/groups\/([a-z][a-z0-9-]{0,31})\/(remove|give|take)$/.exec(pathname);
|
|
1005
|
+
if (grouped && team?.people && team.grants) {
|
|
1006
|
+
const g = grouped[1];
|
|
1007
|
+
if (!team.people.groups().some((x) => x.name === g)) throw new Refusal(404, 'No such group.');
|
|
1008
|
+
if (grouped[2] === 'remove') {
|
|
1009
|
+
const groups = team.people.removeGroup(g);
|
|
1010
|
+
team.grants.forgetSubject(`group:${g}`);
|
|
1011
|
+
/* Its name on things goes too: no phantom group shown (audit 29-11). */
|
|
1012
|
+
for (const c of conversations.list()) if (c.accessGroup === g) conversations.setAccessGroup?.(c.name, undefined);
|
|
1013
|
+
for (const r of resources?.list?.() ?? []) if (r.accessGroup === g) resources.setAccessGroup?.(r.name, undefined);
|
|
1014
|
+
for (const k of secrets?.list?.() ?? []) if (!k.hostOnly && secrets.record(k.name)?.accessGroup === g) secrets.setAccessGroup(k.name, undefined);
|
|
1015
|
+
await reconcileFolders();
|
|
1016
|
+
return send(200, { groups }), true;
|
|
1017
|
+
}
|
|
1018
|
+
const name = String(body.conversation ?? '');
|
|
1019
|
+
if (!conversations.list().some((c) => c.name === name)) throw new Refusal(404, 'No such conversation.');
|
|
1020
|
+
const rights = grouped[2] === 'take' ? '' : `${body.chat === 'write' ? 'rw' : body.chat === 'read' ? 'r' : ''}${body.terminal === true ? 'x' : ''}`;
|
|
1021
|
+
if (rights === '') team.grants.take(`group:${g}`, `conversation:${name}`); else team.grants.give(`group:${g}`, `conversation:${name}`, rights);
|
|
1022
|
+
team.people.changed?.();
|
|
1023
|
+
return send(200, { given: team.grants.of(`group:${g}`, 'conversation').map((x) => ({ name: x.name, rights: x.rights })) }), true;
|
|
1024
|
+
}
|
|
872
1025
|
/* The memory a member's own conversations may take together (29-11): 0, it makes none. */
|
|
873
1026
|
const quota = /^\/api\/operators\/([^/]{3,200})\/quota$/.exec(pathname);
|
|
874
1027
|
if (quota && team?.people) {
|
|
@@ -1037,7 +1190,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
1037
1190
|
if (handed && secrets) {
|
|
1038
1191
|
const conversation = decodeURIComponent(handed[1]);
|
|
1039
1192
|
/* A member: its own key to its own conversation (the table checked the conversation). */
|
|
1040
|
-
|
|
1193
|
+
/* Its own key, or one given to it or its group (#431); taking one off its own conversation is always allowed. */
|
|
1194
|
+
if (request.member && body.attached === true && !request.member.mayUseKey(String(body.secret ?? ''))) return send(403, { error: 'Only your keys, or those given to you, to your own conversations.' }), true;
|
|
1041
1195
|
await handSecret(conversation, String(body.secret ?? ''), body.attached === true);
|
|
1042
1196
|
return send(200, { ok: true, secrets: secrets.of(conversation) }), true;
|
|
1043
1197
|
}
|
|
@@ -1103,7 +1257,10 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
1103
1257
|
const conversation = decodeURIComponent(attach[1]);
|
|
1104
1258
|
/* A member (#431 step 2): its own folder to its own conversation (the table checked the conversation), read
|
|
1105
1259
|
or write, or taken back; never another's folder. */
|
|
1106
|
-
if (request.member
|
|
1260
|
+
if (request.member) {
|
|
1261
|
+
const has = request.member.folderRights(String(body.resource ?? '')); const want = String(body.access ?? '');
|
|
1262
|
+
if (!has || !['read', 'write', 'none', ''].includes(want) || (want === 'write' && !has.includes('w')) || body.shared === true) return send(403, { error: 'Only your folders, or those given to you (at most as given), to your own conversations.' }), true;
|
|
1263
|
+
}
|
|
1107
1264
|
await attachResource(conversation, String(body.resource ?? ''), String(body.access ?? ''), body.shared === true);
|
|
1108
1265
|
return send(200, { ok: true, resources: resources.of(conversation) }), true;
|
|
1109
1266
|
}
|
package/server/conversations.mjs
CHANGED
|
@@ -390,6 +390,11 @@ export class Conversations {
|
|
|
390
390
|
return conversation;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
+
/* CHOWN (#431): its owner -- a person, or none (the administrators'). Its group for access is kept beside it (the
|
|
394
|
+
rights themselves are in grants.mjs). */
|
|
395
|
+
setOwner(name, owner) { if (!this.#store.get(name)) throw new Refusal(404, 'No such conversation.'); this.#store.patch(name, { owner: owner || undefined }); }
|
|
396
|
+
setAccessGroup(name, group) { if (!this.#store.get(name)) throw new Refusal(404, 'No such conversation.'); this.#store.patch(name, { accessGroup: group || undefined }); }
|
|
397
|
+
|
|
393
398
|
/* `again`: a machine built anew for a conversation that had one. */
|
|
394
399
|
async #build(name, tool, memoryMb, again = false) {
|
|
395
400
|
if (this.#store.get(name)?.sharedMachine) return this.#buildShared(name, tool, memoryMb);
|
package/server/grants.mjs
CHANGED
|
@@ -67,7 +67,7 @@ import { Refusal } from './conversations.mjs';
|
|
|
67
67
|
export const RIGHTS = Object.freeze({ conversation: 'rwxm', folder: 'rw', mailbox: 'r', git: 'rw', secret: 'x', server: 'rw', room: 'rwm', box: 'rw' });
|
|
68
68
|
/* What each of the server's own assets takes: its state and its jobs are read, rooms are made. */
|
|
69
69
|
const SERVER_RIGHTS = Object.freeze({ 'server:status': 'r', 'server:jobs': 'r', 'server:rooms': 'w', 'server:diagnostics': 'r' });
|
|
70
|
-
const SUBJECT = /^(conversation:[a-z]([a-z0-9-]{0,30}[a-z0-9])?|(pairing|apikey):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|person:[a-z0-9._+-]{1,64}@([a-z0-9-]{1,63}\.)+[a-z]{2,24})$/;
|
|
70
|
+
const SUBJECT = /^(conversation:[a-z]([a-z0-9-]{0,30}[a-z0-9])?|group:[a-z][a-z0-9-]{0,31}|(pairing|apikey):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|person:[a-z0-9._+-]{1,64}@([a-z0-9-]{1,63}\.)+[a-z]{2,24})$/;
|
|
71
71
|
const ASSET = /^(conversation|folder|mailbox|git):[a-z]([a-z0-9-]{0,30}[a-z0-9])?$|^secret:[A-Z][A-Z0-9_]{0,39}$|^server:(status|jobs|rooms|diagnostics)$|^(room|box):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
72
72
|
|
|
73
73
|
export const typeOf = (asset) => String(asset).split(':')[0];
|
|
@@ -113,10 +113,13 @@ export class Grants {
|
|
|
113
113
|
const clean = readRights(asset, rights);
|
|
114
114
|
/* A secret is handed to a conversation, never to a device: a device
|
|
115
115
|
would be a way to read it. */
|
|
116
|
-
if (typeOf(asset) === 'secret' &&
|
|
116
|
+
if (typeOf(asset) === 'secret' && !/^(conversation|person|group):/.test(subject)) throw new Refusal(400, 'A secret is handed to a conversation (or given to a member or a group, to hand to their own), never shared with a device.');
|
|
117
117
|
/* A MEMBER (person:, people.mjs, #419) is given conversations only, in this version: its chat, its terminal. */
|
|
118
|
-
|
|
119
|
-
if (
|
|
118
|
+
/* A MEMBER (person:, #419) is given conversations, and folders (#431: to read or write their files). */
|
|
119
|
+
if (subject.startsWith('person:') && !['conversation', 'folder', 'secret'].includes(typeOf(asset))) throw new Refusal(400, 'A member is given conversations, folders and keys only.');
|
|
120
|
+
/* A GROUP of people (#431 step 3): given conversations, as a member is; each of its people has them. */
|
|
121
|
+
if (subject.startsWith('group:') && !['conversation', 'folder', 'secret'].includes(typeOf(asset))) throw new Refusal(400, 'A group is given conversations, folders and keys only.');
|
|
122
|
+
if (typeOf(asset) === 'conversation' && !subject.startsWith('pairing:') && !subject.startsWith('apikey:') && !subject.startsWith('person:') && !subject.startsWith('group:')) throw new Refusal(400, 'A conversation is shared with a device or an API key, not with another conversation.');
|
|
120
123
|
/* The state of the server is given to an API key only; an API key is given only that, and
|
|
121
124
|
conversations one by one -- their chat, to read or to write in, never their terminal. */
|
|
122
125
|
if (typeOf(asset) === 'server' && !subject.startsWith('apikey:')) throw new Refusal(400, 'The state of the server is given to an API key only.');
|
package/server/main.mjs
CHANGED
|
@@ -288,12 +288,13 @@ function serve(port, conversations, resources, { gate = () => 'local', memberGat
|
|
|
288
288
|
const person = personOf(member);
|
|
289
289
|
const owns = (name) => conversations.list().some((c) => c.name === name && c.owner === person.email);
|
|
290
290
|
const ownsAsset = (name) => resources?.get(name)?.owner === person.email;
|
|
291
|
+
const folderRights = (name) => (ownsAsset(name) ? 'rw' : person.folderRights(name));
|
|
291
292
|
const ownsKey = (name) => secrets?.ownerOf?.(name) === person.email;
|
|
292
293
|
const may = memberMay(request.method, pathname, (name) => person.rightsOn(person.key, name), owns, ownsAsset, ownsKey);
|
|
293
294
|
if (!may.ok) { response.writeHead(403, { ...HEADERS, 'x-clavarium-role': 'member', 'content-type': 'application/json; charset=utf-8' }).end(JSON.stringify({ error: may.why })); return; }
|
|
294
295
|
/* Every answer marked as a member's (audit 29-11): an administrators' page made stale by a change of role sees it. */
|
|
295
296
|
response.setHeader('x-clavarium-role', 'member');
|
|
296
|
-
request.member = { ...person, need: may.need, conversation: may.conversation, asset: may.asset, ownsAsset, ownsKey, still: () => memberGate(request.headers) === member && ((may.conversation === undefined && may.asset === undefined && may.key === undefined) || (may.need === 'key-owner' ? ownsKey(may.key) : false) || (may.need === 'owner' ? owns(may.conversation) : may.need === 'asset-owner' ? ownsAsset(may.asset) : person.rightsOn(person.key, may.conversation).includes(may.need))) };
|
|
297
|
+
request.member = { ...person, need: may.need, conversation: may.conversation, asset: may.asset, ownsAsset, ownsKey, folderRights, mayUseKey: (name) => ownsKey(name) || person.keyGiven(name), still: () => memberGate(request.headers) === member && ((may.conversation === undefined && may.asset === undefined && may.key === undefined) || (may.need === 'key-owner' ? ownsKey(may.key) : false) || (may.need === 'owner' ? owns(may.conversation) : may.need === 'asset-owner' ? ownsAsset(may.asset) : person.rightsOn(person.key, may.conversation).includes(may.need))) };
|
|
297
298
|
request.stillAllowed = request.member.still;
|
|
298
299
|
/* Its desk: under its own name, as an administrator's is under theirs. */
|
|
299
300
|
if (pathname === '/api/desktop' && desks) { await handleDesktop(request, response, desks, member, originOk, HEADERS); return; }
|
|
@@ -421,11 +422,24 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
421
422
|
const personOf = team ? (given) => {
|
|
422
423
|
const email = String(given).trim().toLowerCase();
|
|
423
424
|
const subject = `person:${email}`;
|
|
424
|
-
|
|
425
|
+
/* Its own grants and its groups' (#431 step 3): the union, right by right, read at each call. */
|
|
426
|
+
const subjects = () => [subject, ...(team.people?.groupsOf?.(email) ?? []).map((g) => `group:${g}`)];
|
|
427
|
+
const merged = () => {
|
|
428
|
+
const by = new Map();
|
|
429
|
+
for (const s of subjects()) for (const g of grants.of(s, 'conversation')) { const was = by.get(g.name); by.set(g.name, { ...g, rights: [...new Set([...(was?.rights ?? ''), ...g.rights])].join('') }); }
|
|
430
|
+
return [...by.values()];
|
|
431
|
+
};
|
|
432
|
+
const mine = () => merged().map((g) => g.name).filter((n) => all.list().some((c) => c.name === n));
|
|
425
433
|
return {
|
|
426
434
|
email, key: subject,
|
|
427
|
-
grantsOf: () =>
|
|
428
|
-
rightsOn: (_key, name) => grants.rightsOf(
|
|
435
|
+
grantsOf: () => merged(),
|
|
436
|
+
rightsOn: (_key, name) => [...new Set(subjects().flatMap((s) => [...grants.rightsOf(s, `conversation:${name}`)]))].join(''),
|
|
437
|
+
/* A folder's rights for it (#431): its own, given to it, or to one of its groups -- '', 'r' or 'rw'. */
|
|
438
|
+
folderRights: (name) => [...new Set(subjects().flatMap((s) => [...grants.rightsOf(s, `folder:${name}`)]))].join(''),
|
|
439
|
+
folders: () => [...new Set(subjects().flatMap((s) => grants.of(s, 'folder').map((g) => g.name)))],
|
|
440
|
+
/* Keys it may hand to its own conversations (#431): given to it or to one of its groups ('x'). */
|
|
441
|
+
keyGiven: (name) => subjects().some((s) => grants.rightsOf(s, `secret:${name}`).includes('x')),
|
|
442
|
+
keys: () => [...new Set(subjects().flatMap((s) => grants.of(s, 'secret').map((g) => g.name)))],
|
|
429
443
|
conversationOf: (wanted) => { const m = mine(); if (wanted === undefined || wanted === '') return m[0]; return m.includes(wanted) ? wanted : undefined; },
|
|
430
444
|
/* ITS OWN CONVERSATIONS (29-11): the memory an administrator lets them take together, and what they take. */
|
|
431
445
|
quota: () => team.people?.quotaOf?.(email) ?? { mb: 0, diskGb: 0, cpus: 0 },
|
package/server/people.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, mkdi
|
|
|
22
22
|
import { dirname } from 'node:path';
|
|
23
23
|
import { Refusal } from './conversations.mjs';
|
|
24
24
|
|
|
25
|
+
const GROUP = /^[a-z][a-z0-9-]{0,31}$/;
|
|
25
26
|
/* A member's room, as kept: { mb, diskGb, cpus }, whole numbers; none without memory. */
|
|
26
27
|
const cleanQuota = (v) => {
|
|
27
28
|
const n = (x) => (Number.isInteger(x) && x >= 0 ? x : 0);
|
|
@@ -54,7 +55,9 @@ export class People {
|
|
|
54
55
|
if (!data || !Array.isArray(data.admins) || !Array.isArray(data.members)) throw new Error('not a roles file');
|
|
55
56
|
const quotas = {};
|
|
56
57
|
for (const [k, v] of Object.entries(data.quotas && typeof data.quotas === 'object' ? data.quotas : {})) { const q = cleanQuota(v); if (q) quotas[low(k)] = q; }
|
|
57
|
-
|
|
58
|
+
const groups = {};
|
|
59
|
+
for (const [g, people] of Object.entries(data.groups && typeof data.groups === 'object' ? data.groups : {})) if (GROUP.test(g) && Array.isArray(people)) groups[g] = [...new Set(people.map(low))];
|
|
60
|
+
return { admins: [...new Set(data.admins.map(low))], members: [...new Set(data.members.map(low))], quotas, groups };
|
|
58
61
|
}
|
|
59
62
|
#load() {
|
|
60
63
|
if (!existsSync(this.#path) && !existsSync(`${this.#path}.bak`)) { this.#lists = null; return; }
|
|
@@ -66,9 +69,9 @@ export class People {
|
|
|
66
69
|
}
|
|
67
70
|
#save() {
|
|
68
71
|
const tmp = `${this.#path}.new`;
|
|
69
|
-
const { quotas, ...lists } = this.#lists;
|
|
70
|
-
/* No room given to anyone: the file as before it existed (going back reads it the same). */
|
|
71
|
-
writeFileSync(tmp, `${JSON.stringify(quotas && Object.keys(quotas).length ? {
|
|
72
|
+
const { quotas, groups, ...lists } = this.#lists;
|
|
73
|
+
/* No room given to anyone, no group: the file as before it existed (going back reads it the same). */
|
|
74
|
+
writeFileSync(tmp, `${JSON.stringify({ ...lists, ...(quotas && Object.keys(quotas).length ? { quotas } : {}), ...(groups && Object.keys(groups).length ? { groups } : {}) }, null, 1)}\n`, { mode: 0o600 });
|
|
72
75
|
if (existsSync(this.#path)) { try { this.#read(this.#path); copyFileSync(this.#path, `${this.#path}.bak`); } catch { /* the old one was bad: no copy of it */ } }
|
|
73
76
|
renameSync(tmp, this.#path);
|
|
74
77
|
this.#damaged = false;
|
|
@@ -94,7 +97,29 @@ export class People {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
/* The lists written out at the first member: every account there is now an administrator, as it was. */
|
|
97
|
-
#seed() { if (this.#lists === null) this.#lists = { admins: this.#all().map((a) => a.email), members: [], quotas: {} }; this.#lists.quotas ??= {}; }
|
|
100
|
+
#seed() { if (this.#lists === null) this.#lists = { admins: this.#all().map((a) => a.email), members: [], quotas: {}, groups: {} }; this.#lists.quotas ??= {}; this.#lists.groups ??= {}; }
|
|
101
|
+
/* GROUPS OF PEOPLE (#431 step 3): a name and its people; what is given to a group (grants.mjs, `group:<name>`) is
|
|
102
|
+
each of theirs. Kept with the roles. */
|
|
103
|
+
groups() { return Object.entries(this.#lists?.groups ?? {}).map(([name, people]) => ({ name, people: [...people] })).sort((a, b) => a.name.localeCompare(b.name)); }
|
|
104
|
+
groupsOf(email) { const e = low(email); return Object.entries(this.#lists?.groups ?? {}).filter(([, people]) => people.includes(e)).map(([name]) => name); }
|
|
105
|
+
setGroup(name, people) {
|
|
106
|
+
if (this.#damaged) throw new Refusal(409, 'The file of the roles cannot be read: repair it first.');
|
|
107
|
+
if (typeof name !== 'string' || !GROUP.test(name)) throw new Refusal(400, 'A group\'s name is 1 to 32 lower-case letters, digits or hyphens; it starts with a letter.');
|
|
108
|
+
if (!Array.isArray(people) || people.length > 200) throw new Refusal(400, 'A group\'s people are a list of accounts.');
|
|
109
|
+
const here = new Set(this.#all().map((a) => a.email));
|
|
110
|
+
const list = [...new Set(people.map(low))];
|
|
111
|
+
/* An empty name is no account either (test-c 29-11: `find` returned '' and let it through). */
|
|
112
|
+
const unknown = list.findIndex((e) => !e || !here.has(e));
|
|
113
|
+
if (unknown >= 0) throw new Refusal(404, `No such account: ${list[unknown] || '(empty)'}.`);
|
|
114
|
+
this.#seed(); this.#lists.groups[name] = list; this.#save(); this.changed();
|
|
115
|
+
return this.groups();
|
|
116
|
+
}
|
|
117
|
+
removeGroup(name) {
|
|
118
|
+
if (this.#damaged) throw new Refusal(409, 'The file of the roles cannot be read: repair it first.');
|
|
119
|
+
if (!this.#lists?.groups?.[name]) throw new Refusal(404, 'No such group.');
|
|
120
|
+
delete this.#lists.groups[name]; this.#save(); this.changed();
|
|
121
|
+
return this.groups();
|
|
122
|
+
}
|
|
98
123
|
/* A MEMBER'S OWN CONVERSATIONS (29-11): what all of them may take together -- memory (MB), disk (GB), cores --
|
|
99
124
|
set by an administrator. A memory of 0: it makes none; a disk or cores of 0: not counted. */
|
|
100
125
|
quotaOf(email) { const q = this.#lists?.quotas?.[low(email)]; return q ? { ...q } : { mb: 0, diskGb: 0, cpus: 0 }; }
|
|
@@ -134,7 +159,7 @@ export class People {
|
|
|
134
159
|
const e = low(email);
|
|
135
160
|
if (!ROLES.includes(role) || this.#damaged) return () => {};
|
|
136
161
|
if (this.#lists === null && role === 'admin') return () => {};
|
|
137
|
-
const before = this.#lists === null ? null : { admins: [...this.#lists.admins], members: [...this.#lists.members], quotas: { ...(this.#lists.quotas ?? {}) } };
|
|
162
|
+
const before = this.#lists === null ? null : { admins: [...this.#lists.admins], members: [...this.#lists.members], quotas: { ...(this.#lists.quotas ?? {}) }, groups: structuredClone(this.#lists.groups ?? {}) };
|
|
138
163
|
this.#seed(); this.#put(e, role); this.#save();
|
|
139
164
|
return () => {
|
|
140
165
|
if (before === null) { this.#lists = null; rmSync(this.#path, { force: true }); rmSync(`${this.#path}.bak`, { force: true }); return; }
|
|
@@ -148,6 +173,7 @@ export class People {
|
|
|
148
173
|
this.#lists.admins = this.#lists.admins.filter((x) => x !== e);
|
|
149
174
|
this.#lists.members = this.#lists.members.filter((x) => x !== e);
|
|
150
175
|
if (this.#lists.quotas) delete this.#lists.quotas[e];
|
|
176
|
+
for (const g of Object.values(this.#lists.groups ?? {})) { const i = g.indexOf(e); if (i >= 0) g.splice(i, 1); }
|
|
151
177
|
this.#save();
|
|
152
178
|
}
|
|
153
179
|
/* Accounts gone outside the page (the host program): their roles forgotten. Returns the addresses forgotten. */
|
|
@@ -159,6 +185,7 @@ export class People {
|
|
|
159
185
|
if (!gone.length) return [];
|
|
160
186
|
this.#lists.admins = this.#lists.admins.filter((e) => here.has(e)); this.#lists.members = this.#lists.members.filter((e) => here.has(e));
|
|
161
187
|
for (const e of gone) if (this.#lists.quotas) delete this.#lists.quotas[e];
|
|
188
|
+
for (const g of Object.values(this.#lists.groups ?? {})) for (const e of gone) { const i = g.indexOf(e); if (i >= 0) g.splice(i, 1); }
|
|
162
189
|
this.#save();
|
|
163
190
|
return gone;
|
|
164
191
|
}
|
package/server/resources.mjs
CHANGED
|
@@ -209,6 +209,10 @@ export class Resources {
|
|
|
209
209
|
return { ...resource, attachments: {}, ...(type === 'git' && this.#access ? { via: this.#access.describe(name, origin) } : {}), ...(firstSeen.length ? { firstSeen } : {}), ...(pinned === undefined ? {} : { pinned }) };
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/* CHOWN (#431): a folder's owner (a person; none: the administrators'), and its group for access. */
|
|
213
|
+
setOwner(name, owner) { const r = this.#store.get(name); if (!r) throw new Refusal(404, 'No such folder.'); const { owner: _o, ...rest } = r; this.#store.put(owner ? { ...rest, owner } : rest); }
|
|
214
|
+
setAccessGroup(name, group) { const r = this.#store.get(name); if (!r) throw new Refusal(404, 'No such folder.'); const { accessGroup: _g, ...rest } = r; this.#store.put(group ? { ...rest, accessGroup: group } : rest); }
|
|
215
|
+
|
|
212
216
|
/* The read-only view of a folder, made if it is not already there. */
|
|
213
217
|
async ensureView(name) {
|
|
214
218
|
const r = await this.#host(['view', 'make', name]);
|
package/server/secrets.mjs
CHANGED
|
@@ -100,7 +100,7 @@ export class Secrets {
|
|
|
100
100
|
#handed(conversation, name) { return this.#grants.can(conversationSubject(conversation), `secret:${name}`, 'x'); }
|
|
101
101
|
/* Ephemeral: gone at its moment (minutes). Otherwise: gone from its day on. */
|
|
102
102
|
#expired(s) { return s.expiresAt ? Date.parse(s.expiresAt) <= this.#now().getTime() : (Boolean(s.expires) && daysTo(s.expires, this.#now()) <= 0); }
|
|
103
|
-
#users(name) { return this.#grants.on(`secret:${name}`).map((g) => g.subject.slice('conversation:'.length)); }
|
|
103
|
+
#users(name) { return this.#grants.on(`secret:${name}`).filter((g) => g.subject.startsWith('conversation:')).map((g) => g.subject.slice('conversation:'.length)); }
|
|
104
104
|
/* What is delivered to this conversation: handed, and not expired. */
|
|
105
105
|
#given(conversation) { return this.#store.all().filter((s) => !s.hostOnly && this.#handed(conversation, s.name) && !this.#expired(s)); }
|
|
106
106
|
|
|
@@ -115,6 +115,10 @@ export class Secrets {
|
|
|
115
115
|
}
|
|
116
116
|
/* Past its expiry day: kept, not used (nor by dictation, voice.mjs). */
|
|
117
117
|
ownerOf(name) { return this.#store.get(name)?.owner; }
|
|
118
|
+
/* CHOWN (#431): a key's owner (a person; none: the administrators'), and its group for use. Never a host-only one. */
|
|
119
|
+
setOwner(name, owner) { const k = this.#store.get(name); if (!k || k.hostOnly) throw new Refusal(404, 'No such key.'); const { owner: _o, ...rest } = k; this.#store.put(owner ? { ...rest, owner } : rest); }
|
|
120
|
+
setAccessGroup(name, group) { const k = this.#store.get(name); if (!k || k.hostOnly) throw new Refusal(404, 'No such key.'); const { accessGroup: _g, ...rest } = k; this.#store.put(group ? { ...rest, accessGroup: group } : rest); }
|
|
121
|
+
record(name) { const k = this.#store.get(name); return k && !k.hostOnly ? { name: k.name, owner: k.owner, accessGroup: k.accessGroup } : undefined; }
|
|
118
122
|
isExpired(name) { const s = this.#store.get(name); return Boolean(s) && this.#expired(s); }
|
|
119
123
|
/* Handed to it, expired or not (its Assets show both). */
|
|
120
124
|
of(conversation) { return this.#store.all().filter((s) => this.#handed(conversation, s.name)).map((s) => s.name); }
|
package/server/settingswords.mjs
CHANGED
|
@@ -60,6 +60,8 @@ export const SETTINGS_WORDS_FR = {
|
|
|
60
60
|
'set-share-memory': 'Mémoire par machine', 'set-share-disk': 'Disque par machine', 'set-share-others': 'Autres',
|
|
61
61
|
'set-share-rest': 'Système et autres', 'set-share-else': 'Tout le reste', 'set-share-free': 'Libre', 'set-share-used': 'Utilisé', 'set-share-of': 'sur {total}',
|
|
62
62
|
'set-room': 'Ses propres conversations', 'set-room-mem': 'Mémoire', 'set-room-disk': 'Disque', 'set-room-cpus': 'Cœurs', 'set-room-off': 'Non',
|
|
63
|
+
'set-groups': 'Groupes', 'set-groups-hint': 'Donné au groupe : à chacune de ses personnes.', 'set-group-add': '+ Ajouter…', 'set-group-remove': 'Supprimer', 'set-group-remove-sure': 'Oui, le supprimer', 'set-group-new-name': 'Nouveau groupe : son nom', 'set-group-make': 'Créer',
|
|
64
|
+
'set-who': 'Qui y a accès', 'set-who-none': 'Rien', 'set-who-read': 'Lire', 'set-who-write': 'Écrire', 'set-who-admins': 'Les administrateurs', 'set-who-owner': 'Propriétaire', 'set-who-nogroup': 'Aucun groupe', 'set-who-group': 'Groupe', 'set-who-add': '+ Donner à une personne…', 'set-who-besides': 'En plus', 'set-who-all': 'tout', 'set-who-use': 'Utiliser',
|
|
63
65
|
'set-binders-max': 'Les agents en font {n} au plus', 'set-admin-1': '1 administrateur', 'set-admins': '{n} administrateurs', 'set-member-1': '1 membre', 'set-members': '{n} membres', 'set-member-gone': 'Plus rien n\'est partagé avec vous.', 'set-give-read': 'Lecture seule', 'set-give-chat': 'Chat', 'set-give-both': 'Chat + terminal', 'set-give-terminal': 'Terminal', 'set-give-none': 'Retirer l\'accès', 'set-given-none': 'Rien de partagé pour l\'instant.', 'set-given-ai': 'Chat et terminal : tout ce que son IA atteint.', 'set-give-add': 'Partager une conversation…', 'set-role-admin': 'Administrateur', 'set-role-member': 'Membre', 'set-add-account': 'Ajouter un compte', 'set-ch-s-operators-about': 'Qui se connecte, et ce qu\'il voit.',
|
|
64
66
|
'set-backup-now': 'Exporter · importer', 'set-git-key': '1 clé git', 'set-git-keys': '{n} clés git', 'set-restart': 'redémarrer',
|
|
65
67
|
'set-logs-now': 'Clavarium, machines, système',
|
package/web/app.js
CHANGED
|
@@ -2713,6 +2713,8 @@
|
|
|
2713
2713
|
lives there only (given, its right set, taken back: « None »). Its sign-in mailbox (not an asset) stays below. */
|
|
2714
2714
|
const n = givenCount(here);
|
|
2715
2715
|
$('access-assets').textContent = uiSaid(n === 1 ? 'set-acc-assets-1' : 'set-acc-assets-n', n === 1 ? '1 asset · see' : '{n} assets · see', { n });
|
|
2716
|
+
/* Who has access among people (#431): the one block, for this conversation. */
|
|
2717
|
+
{ const holder = $('access-who-conv'); if (holder && (holder.dataset.name !== current || !holder.firstChild)) { holder.replaceChildren(accessBlock('conversations', current)); holder.dataset.name = current; } }
|
|
2716
2718
|
paintConvStates(here);
|
|
2717
2719
|
/* Where the tool works, and the way to the other place. */
|
|
2718
2720
|
const kept = here?.work === 'kept';
|
|
@@ -6279,6 +6281,9 @@
|
|
|
6279
6281
|
const share = !t && !MEMBER_PAGE && ['folder', 'git', 'mailbox'].includes(chosen.kind) ? el('button', 'as-link', uiSaid('set-acc-share', 'Share with a device...')) : null;
|
|
6280
6282
|
if (share) { share.type = 'button'; share.addEventListener('click', () => { void openCompose([[chosen.key, 'r']]); }); }
|
|
6281
6283
|
parts.push(KIT.AccessList(model, { key: KIT.rightsKey(chosen), kind: chosen.kind, name: chosen.name, onChange: (row, level, stored) => setAccess(chosen, row, level, stored), actions: [share] }));
|
|
6284
|
+
/* Who has access among people (#431): the same block as on a conversation's page. */
|
|
6285
|
+
if (chosen.kind === 'folder') parts.push(accessBlock('resources', chosen.name));
|
|
6286
|
+
if (chosen.kind === 'secret') parts.push(accessBlock('secrets', chosen.name));
|
|
6282
6287
|
}
|
|
6283
6288
|
/* A CALENDAR'S AGENDA (16-11): its events, under who has it -- read through Tether as the owner's own read
|
|
6284
6289
|
(agenda.mjs), so the calendar need not stay open elsewhere. The owner's page only: a device reads no calendar. */
|
|
@@ -8459,6 +8464,104 @@
|
|
|
8459
8464
|
}
|
|
8460
8465
|
/* Its line in the chapter's head: counted once the rows are there (#419). */
|
|
8461
8466
|
void paintSettingsStates().catch(() => {});
|
|
8467
|
+
void paintGroups(got).catch(() => {});
|
|
8468
|
+
}
|
|
8469
|
+
/* WHO HAS ACCESS (#431): ONE component, the same on every conversation's and folder's page -- its owner (chown),
|
|
8470
|
+
its group and that group's level (chmod), people besides (as an ACL). `kind`: 'conversations' or 'resources'.
|
|
8471
|
+
The administrators' only (the server refuses it to anyone else). */
|
|
8472
|
+
function accessBlock(kind, name) {
|
|
8473
|
+
const box = el('div', 'access-who'); box.dataset.kind = kind; box.dataset.name = name;
|
|
8474
|
+
if (MEMBER_PAGE || DEVICE) return box;
|
|
8475
|
+
const isConv = kind === 'conversations'; const isKey = kind === 'secrets';
|
|
8476
|
+
const levels = isKey ? [['', uiSaid('set-who-none', 'Nothing')], ['x', uiSaid('set-who-use', 'Use')]] : isConv
|
|
8477
|
+
? [['', uiSaid('set-who-none', 'Nothing')], ['r', uiSaid('set-give-read', 'Read only')], ['rw', uiSaid('set-give-chat', 'Chat')], ['rwx', uiSaid('set-give-both', 'Chat + terminal')], ['x', uiSaid('set-give-terminal', 'Terminal')]]
|
|
8478
|
+
: [['', uiSaid('set-who-none', 'Nothing')], ['r', uiSaid('set-who-read', 'Read')], ['rw', uiSaid('set-who-write', 'Write')]];
|
|
8479
|
+
const bodyOf = (rights) => (isKey ? { use: rights.includes('x') } : isConv ? { chat: rights.includes('w') ? 'write' : rights.includes('r') ? 'read' : null, terminal: rights.includes('x') } : { access: rights.includes('w') ? 'write' : rights.includes('r') ? 'read' : null });
|
|
8480
|
+
const select = (pairs, value, aria) => { const sel = el('select'); sel.setAttribute('aria-label', aria); for (const [v, l] of pairs) { const o = el('option', '', l); o.value = v; sel.append(o); } sel.value = value; return sel; };
|
|
8481
|
+
const said = el('p', 'hint access-who-said');
|
|
8482
|
+
const fail = el('p', 'err'); fail.hidden = true;
|
|
8483
|
+
const act = async (what, body) => { fail.hidden = true; try { await post(`${API}/${kind}/${encodeURIComponent(name)}/${what}`, body); } catch (error) { fail.textContent = error.message; fail.hidden = false; } await paint(); };
|
|
8484
|
+
const paint = async () => {
|
|
8485
|
+
const got = await fetch(`${API}/${kind}/${encodeURIComponent(name)}/access`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
8486
|
+
if (!got) { box.hidden = true; return; }
|
|
8487
|
+
box.hidden = false; box.replaceChildren(el('b', '', uiSaid('set-who', 'Who has access')));
|
|
8488
|
+
const members = got.accounts.filter((a) => a.role === 'member').map((a) => a.email);
|
|
8489
|
+
const row = (label, ...controls) => { const r = el('div', 'access-who-row'); r.append(el('span', '', label), ...controls); return r; };
|
|
8490
|
+
/* Owner: a person, or the administrators. */
|
|
8491
|
+
const owner = select([['', uiSaid('set-who-admins', 'The administrators')], ...got.accounts.map((a) => [a.email, a.email])], got.owner ?? '', `Owner of ${name}`);
|
|
8492
|
+
owner.addEventListener('change', () => void act('owner', { owner: owner.value }));
|
|
8493
|
+
box.append(row(uiSaid('set-who-owner', 'Owner'), owner));
|
|
8494
|
+
/* Its group and that group's level. */
|
|
8495
|
+
const group = select([['', uiSaid('set-who-nogroup', 'No group')], ...got.groups.map((g) => [g, g])], got.group ?? '', `Group of ${name}`);
|
|
8496
|
+
const level = select(levels.filter(([v]) => v !== ''), got.groupRights || (isKey ? 'x' : isConv ? 'rw' : 'r'), `What its group may do in ${name}`);
|
|
8497
|
+
level.hidden = !got.group;
|
|
8498
|
+
group.addEventListener('change', () => void act('group', group.value ? { group: group.value, ...bodyOf(level.value) } : { group: '' }));
|
|
8499
|
+
level.addEventListener('change', () => void act('group', { group: group.value, ...bodyOf(level.value) }));
|
|
8500
|
+
box.append(row(uiSaid('set-who-group', 'Group'), group, level));
|
|
8501
|
+
/* People besides: each with its level (Nothing takes it back), one more from a list. */
|
|
8502
|
+
for (const p of got.people) {
|
|
8503
|
+
const lv = select(levels, p.rights, `What ${p.email} may do in ${name}`);
|
|
8504
|
+
lv.addEventListener('change', () => void act('person', { email: p.email, ...bodyOf(lv.value) }));
|
|
8505
|
+
box.append(row(p.email, lv));
|
|
8506
|
+
}
|
|
8507
|
+
const others = members.filter((e) => e !== got.owner && !got.people.some((p) => p.email === e));
|
|
8508
|
+
if (others.length) {
|
|
8509
|
+
const add = select([['', uiSaid('set-who-add', '+ Give to one person…')], ...others.map((e) => [e, e])], '', `Give ${name} to one person`);
|
|
8510
|
+
add.addEventListener('change', () => { if (add.value) void act('person', { email: add.value, ...bodyOf(isKey ? 'x' : isConv ? 'rw' : 'r') }); });
|
|
8511
|
+
box.append(row(uiSaid('set-who-besides', 'Besides'), add));
|
|
8512
|
+
}
|
|
8513
|
+
/* In plain words: who has what. */
|
|
8514
|
+
const parts = [`${got.owner ? got.owner.split('@')[0] : uiSaid('set-who-admins', 'The administrators')} (${uiSaid('set-who-all', 'all')})`];
|
|
8515
|
+
if (got.group) parts.push(`${got.group} (${levels.find(([v]) => v === got.groupRights)?.[1] ?? got.groupRights})`);
|
|
8516
|
+
for (const p of got.people) parts.push(`${p.email.split('@')[0]} (${levels.find(([v]) => v === p.rights)?.[1] ?? p.rights})`);
|
|
8517
|
+
said.textContent = parts.join(' · ');
|
|
8518
|
+
box.append(said, fail);
|
|
8519
|
+
};
|
|
8520
|
+
void paint();
|
|
8521
|
+
return box;
|
|
8522
|
+
}
|
|
8523
|
+
/* GROUPS OF PEOPLE (#431 step 3): each with its people (× to take one out, + to add), the conversations given
|
|
8524
|
+
to it (as to a member), and a new one by its name. */
|
|
8525
|
+
async function paintGroups(ops) {
|
|
8526
|
+
const box = $('groups-box'); if (!box) return;
|
|
8527
|
+
const got = await fetch(`${API}/groups`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
8528
|
+
box.hidden = !got; if (!got) return;
|
|
8529
|
+
box.replaceChildren();
|
|
8530
|
+
const fail = (error) => { $('operators-error').textContent = error.message; $('operators-error').hidden = false; };
|
|
8531
|
+
const head = el('div', 'groups-head'); head.append(el('b', '', uiSaid('set-groups', 'Groups')), el('small', 'hint', uiSaid('set-groups-hint', 'Given to a group: to each of its people.')));
|
|
8532
|
+
box.append(head);
|
|
8533
|
+
const accounts = (ops?.operators ?? []).map((o) => o.email);
|
|
8534
|
+
const label = (n) => conversations.find((c) => c.name === n)?.chatName || n;
|
|
8535
|
+
for (const g of got.groups) {
|
|
8536
|
+
const row = el('div', 'group-row'); row.dataset.group = g.name;
|
|
8537
|
+
const top = el('div', 'group-top'); top.append(el('b', '', g.name));
|
|
8538
|
+
const people = el('div', 'group-people');
|
|
8539
|
+
for (const p of g.people) {
|
|
8540
|
+
const chip = el('button', 'group-chip', `${p.split('@')[0]} ×`); chip.type = 'button'; chip.title = p; chip.setAttribute('aria-label', `Take ${p} out of ${g.name}`);
|
|
8541
|
+
chip.addEventListener('click', async () => { try { await post(`${API}/groups`, { name: g.name, people: g.people.filter((x) => x !== p) }); } catch (error) { fail(error); } await paintGroups(ops); });
|
|
8542
|
+
people.append(chip);
|
|
8543
|
+
}
|
|
8544
|
+
const others = accounts.filter((a) => !g.people.includes(a));
|
|
8545
|
+
if (others.length) {
|
|
8546
|
+
const add = el('select', 'group-add'); add.setAttribute('aria-label', `Add someone to ${g.name}`);
|
|
8547
|
+
const first = el('option', '', uiSaid('set-group-add', '+ Add…')); first.value = ''; add.append(first);
|
|
8548
|
+
for (const a of others) { const o = el('option', '', a); o.value = a; add.append(o); }
|
|
8549
|
+
add.addEventListener('change', async () => { if (!add.value) return; try { await post(`${API}/groups`, { name: g.name, people: [...g.people, add.value] }); } catch (error) { fail(error); } await paintGroups(ops); });
|
|
8550
|
+
people.append(add);
|
|
8551
|
+
}
|
|
8552
|
+
const gone = el('button', 'danger group-remove', uiSaid('set-group-remove', 'Remove')); gone.type = 'button';
|
|
8553
|
+
gone.addEventListener('click', () => { gone.textContent = uiSaid('set-group-remove-sure', 'Yes, remove it'); gone.onclick = async () => { try { await post(`${API}/groups/${g.name}/remove`, {}); } catch (error) { fail(error); } await paintGroups(ops); }; });
|
|
8554
|
+
top.append(gone);
|
|
8555
|
+
/* What it may use is set on each thing (its « Who has access » block, accessBlock), not here: one place (29-11). */
|
|
8556
|
+
row.append(top, people);
|
|
8557
|
+
box.append(row);
|
|
8558
|
+
}
|
|
8559
|
+
/* A new group: its name, then its people are added. */
|
|
8560
|
+
const form = el('form', 'group-new'); const input = el('input'); input.placeholder = uiSaid('set-group-new-name', 'New group: its name'); input.setAttribute('aria-label', input.placeholder); input.maxLength = 32;
|
|
8561
|
+
const go = el('button', '', uiSaid('set-group-make', 'Make')); go.type = 'submit';
|
|
8562
|
+
form.append(input, go);
|
|
8563
|
+
form.addEventListener('submit', async (event) => { event.preventDefault(); const name = input.value.trim().toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, ''); if (!name) return; try { await post(`${API}/groups`, { name, people: [], create: true }); } catch (error) { fail(error); } await paintGroups(ops); });
|
|
8564
|
+
box.append(form);
|
|
8462
8565
|
}
|
|
8463
8566
|
/* API KEYS (server/apikeys.mjs): what a program or an AI elsewhere may read with a key. Made with no
|
|
8464
8567
|
scope until one is ticked; its secret shown this once, then never; revoked at once, confirmed in place.
|
package/web/index.html
CHANGED
|
@@ -279,6 +279,8 @@
|
|
|
279
279
|
<div class="chapter-body">
|
|
280
280
|
<!-- ITS ASSETS (07-11, assets step 4): one line; what it was given lives in its Assets tab (Give…, its rights). -->
|
|
281
281
|
<div class="row access-assets"><button type="button" id="access-assets" class="as-link"></button></div>
|
|
282
|
+
<!-- WHO HAS ACCESS among people (#431): owner, group and level, people besides (app.js, accessBlock). -->
|
|
283
|
+
<div id="access-who-conv"></div>
|
|
282
284
|
<!-- ITS SIGN-IN COMPANION (15-11, #362): the conversation that signs its tool in, if not the general one. -->
|
|
283
285
|
<div class="set-row" id="companion-here-row"><div class="set-what"><label for="companion-here">Sign-in companion</label><small id="companion-here-hint">Signs its tool in with its browser</small><small data-said="set-companion-yours">Your choice, your responsibility</small></div><div class="set-control"><select id="companion-here"></select></div></div>
|
|
284
286
|
<div id="signin-setup" hidden>
|
|
@@ -1170,6 +1172,8 @@
|
|
|
1170
1172
|
<summary><span class="chapter-title" data-said="set-ch-s-operators">Accounts</span><span class="chapter-about" data-said="set-ch-s-operators-about">Who signs in, and what they see.</span></summary>
|
|
1171
1173
|
<div class="chapter-body">
|
|
1172
1174
|
<div id="operators-rows"></div>
|
|
1175
|
+
<!-- GROUPS OF PEOPLE (#431 step 3): what is given to a group is each of its people's. -->
|
|
1176
|
+
<div id="groups-box" class="groups-box" hidden></div>
|
|
1173
1177
|
<form id="operators-new" class="set-row" autocomplete="off"><div class="set-what"><label for="operators-email" data-said="set-add-account">Add an account</label><small>Email address</small><small class="tip" hidden>Locked 15 min after 5 failures. The last administrator is never locked or removed.</small></div><div class="set-control"><input id="operators-email" type="email" placeholder="someone@example.com" spellcheck="false" autocapitalize="off" required><select id="operators-role" aria-label="Role of the new account"><option value="member" data-said="set-role-member">Member</option><option value="admin" data-said="set-role-admin">Administrator</option></select><button type="submit">Add</button></div></form>
|
|
1174
1178
|
<div id="operators-password" class="as-form" hidden><p><b id="operators-password-for"></b>: its password, shown <b>this once</b>. Give it to them yourself.</p><div class="row"><input id="operators-password-value" readonly spellcheck="false"><button type="button" id="operators-password-copy">Copy</button><button type="button" id="operators-password-done">Done</button></div></div>
|
|
1175
1179
|
<p class="error" id="operators-error" role="alert" hidden></p>
|
package/web/style.css
CHANGED
|
@@ -3481,3 +3481,17 @@ html[data-role="member"]:not([data-mine]) #folders { display: none !important; }
|
|
|
3481
3481
|
html[data-role="member"] #panel details.chapter:not(#chapter-general):not(#chapter-machine):not(#chapter-health) { display: none !important; }
|
|
3482
3482
|
html[data-role="member"] #assets-view { display: none !important; }
|
|
3483
3483
|
html[data-role="member"] #assets .as-group-add, html[data-role="member"] #assets-detail .kit-groupchip { display: none !important; }
|
|
3484
|
+
/* GROUPS OF PEOPLE (#431 step 3). */
|
|
3485
|
+
.groups-box{display:grid;gap:10px;margin-top:14px;padding-top:12px;border-top:1px solid var(--line)}
|
|
3486
|
+
.groups-head{display:grid;gap:2px}
|
|
3487
|
+
.group-row{display:grid;gap:6px;padding:10px 12px;border:1px solid var(--line);border-radius:10px;min-width:0}
|
|
3488
|
+
.group-top{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.group-top .group-remove{margin-left:auto}
|
|
3489
|
+
.group-people{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
3490
|
+
.group-chip{font-size:.85em;padding:2px 10px;border-radius:99px;border:1px solid var(--line);background:transparent;color:var(--ink)}
|
|
3491
|
+
.group-new{display:flex;gap:6px;flex-wrap:wrap}.group-new input{flex:1 1 12em;min-width:0}
|
|
3492
|
+
/* The accounts on a phone: the address on its own line, its buttons under it (29-11, seen with groups). */
|
|
3493
|
+
@media (max-width: 520px) { #operators-rows .list-item.folder { grid-template-columns: 1fr; } #operators-rows .list-item > .set-what { min-width: 0; overflow-wrap: anywhere; } #operators-rows .list-item > .set-control { flex-wrap: wrap; justify-content: flex-start; } }
|
|
3494
|
+
/* WHO HAS ACCESS (#431): one block, on every conversation and folder. */
|
|
3495
|
+
.access-who{display:grid;gap:6px;margin-top:10px;padding:10px 12px;border:1px solid var(--line);border-radius:10px;min-width:0}
|
|
3496
|
+
.access-who-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-width:0}.access-who-row>span{flex:1 1 8em;min-width:0;overflow-wrap:anywhere}
|
|
3497
|
+
.access-who-row select{min-width:7em;max-width:100%}
|