clavarium 0.2.528-next.1 → 0.2.529-next.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.528-next.1",
3
+ "version": "0.2.529-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.528-next.1",
9
+ "version": "0.2.529-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.528-next.1",
3
+ "version": "0.2.529-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/api.mjs CHANGED
@@ -801,8 +801,9 @@ export async function handleApi(request, response, conversations, headers, resou
801
801
  if (team.list().some((o) => o.email === adding)) throw new Refusal(409, 'This account exists already.');
802
802
  /* Nothing of a past account of that address comes back with the new one. */
803
803
  team.grants?.forgetSubject(`person:${adding}`);
804
- team.people?.adding(adding, role);
805
- const made = await team.add(body.email);
804
+ const undo = team.people?.adding(adding, role);
805
+ let made;
806
+ try { made = await team.add(body.email); } catch (error) { undo?.(); throw error; }
806
807
  return send(201, { ...made, role: team.people?.roleOf(made.email) ?? 'admin' }), true;
807
808
  }
808
809
  /* An account made an administrator or a member (#419): never oneself, never the last administrator. */
@@ -810,7 +811,10 @@ export async function handleApi(request, response, conversations, headers, resou
810
811
  if (roleOf && team?.people) {
811
812
  const email = decodeURIComponent(roleOf[1]).trim().toLowerCase();
812
813
  if (email === identity) throw new Refusal(409, 'You cannot change your own role: ask another administrator.');
813
- return send(200, { operators: team.people.setRole(email, String(body.role ?? '')) }), true;
814
+ const changed = team.people.setRole(email, String(body.role ?? ''));
815
+ /* Made an administrator: what it was given as a member is forgotten, not given back if it is a member again (audit 13). */
816
+ if (team.people.roleOf(email) === 'admin') team.grants?.forgetSubject(`person:${email}`);
817
+ return send(200, { operators: changed }), true;
814
818
  }
815
819
  /* A conversation given to a member, or taken back: its chat (read or write) and/or its terminal (#419). */
816
820
  const giving = /^\/api\/operators\/([^/]{3,200})\/(give|take)$/.exec(pathname);
package/server/people.mjs CHANGED
@@ -18,7 +18,7 @@
18
18
  * server was installed with (`install`, its --operators) are the administrators and every other one a member --
19
19
  * never everybody locked out, never a member made an administrator. It is said, loudly.
20
20
  */
21
- import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, mkdirSync } from 'node:fs';
21
+ import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, mkdirSync, rmSync } from 'node:fs';
22
22
  import { dirname } from 'node:path';
23
23
  import { Refusal } from './conversations.mjs';
24
24
 
@@ -103,11 +103,18 @@ export class People {
103
103
  }
104
104
  /* An account ABOUT TO BE added, its role said first: never an administrator for a moment by mistake, and an
105
105
  account removed then added again does not come back as it was. */
106
+ /* Returns what puts it back as it was, when the account could not be added after all (audit 13): no file left
107
+ where there was none -- an owner without members keeps everything as before. */
106
108
  adding(email, role) {
107
109
  const e = low(email);
108
- if (!ROLES.includes(role) || this.#damaged) return;
109
- if (this.#lists === null && role === 'admin') return;
110
+ if (!ROLES.includes(role) || this.#damaged) return () => {};
111
+ if (this.#lists === null && role === 'admin') return () => {};
112
+ const before = this.#lists === null ? null : { admins: [...this.#lists.admins], members: [...this.#lists.members] };
110
113
  this.#seed(); this.#put(e, role); this.#save();
114
+ return () => {
115
+ if (before === null) { this.#lists = null; rmSync(this.#path, { force: true }); rmSync(`${this.#path}.bak`, { force: true }); return; }
116
+ this.#lists = before; this.#save();
117
+ };
111
118
  }
112
119
  /* An account removed: its role forgotten with it. */
113
120
  removed(email) {