@milesroxas/design-hub 0.6.1 → 0.7.0
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/README.md +17 -7
- package/core/review/model.ts +90 -10
- package/core/review/policy.test.ts +62 -0
- package/core/review/policy.ts +13 -9
- package/core/review/service.test.ts +464 -54
- package/core/review/service.ts +168 -36
- package/core/review/store.ts +31 -7
- package/dist/core/review/model.d.ts +39 -7
- package/dist/core/review/model.js +73 -7
- package/dist/core/review/policy.d.ts +4 -1
- package/dist/core/review/policy.js +4 -4
- package/dist/core/review/service.d.ts +24 -6
- package/dist/core/review/service.js +155 -36
- package/dist/core/review/store.d.ts +15 -5
- package/dist/core/review/store.js +27 -6
- package/dist/scripts/bootstrap.d.ts +16 -14
- package/dist/scripts/bootstrap.js +56 -39
- package/dist/scripts/lib/deploy.d.ts +12 -4
- package/dist/scripts/lib/deploy.js +47 -13
- package/dist/scripts/lib/review.js +3 -3
- package/dist/scripts/lib/vercel.d.ts +8 -2
- package/dist/scripts/lib/vercel.js +23 -9
- package/dist/scripts/people.d.ts +16 -29
- package/dist/scripts/people.js +72 -39
- package/dist/scripts/preflight.js +2 -2
- package/dist/scripts/share.d.ts +2 -3
- package/dist/scripts/share.js +18 -10
- package/dist/server/api.d.ts +6 -2
- package/dist/server/api.js +53 -22
- package/dist/server/dev.js +3 -3
- package/dist/server/fake-upstash.js +3 -2
- package/dist/server/local.d.ts +2 -2
- package/dist/server/local.js +6 -4
- package/dist/server/session.d.ts +25 -10
- package/dist/server/session.js +69 -52
- package/dist/server/upstash.js +4 -3
- package/dist/vercel/proxy.d.ts +5 -3
- package/dist/vercel/proxy.js +183 -157
- package/dist/vite/plugin.js +5 -5
- package/kit/ui/Menu.tsx +14 -4
- package/kit/ui/ui.css +16 -3
- package/package.json +2 -2
- package/shell/review/Bar.tsx +5 -4
- package/shell/review/People.tsx +194 -55
- package/shell/review/Review.tsx +9 -8
- package/shell/review/ThreadCard.tsx +24 -21
- package/shell/review/client.ts +37 -18
- package/shell/review/review.css +9 -1
- package/skills/miles-deploy/SKILL.md +44 -16
- package/skills/miles-design-hub/SKILL.md +5 -5
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-review/SKILL.md +7 -5
- package/skills/miles-worktrees/SKILL.md +1 -1
- package/templates/conductor/settings.toml +1 -1
- package/templates/guide.md +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# design-hub
|
|
2
2
|
|
|
3
|
-
The Design Hub product as an npm package: the hub that lists and serves a project's prototypes, the review panel and its API, the
|
|
3
|
+
The Design Hub product as an npm package: the hub that lists and serves a project's prototypes, the review panel and its API, the sign-in gate, the kit, the `design-hub` command and the `miles-*` skills. A project installs it and keeps only its prototypes, kit materials and docs; `npm create @milesroxas/design-hub` makes one.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
design-hub dev # the hub on http://localhost:<PORT>
|
|
@@ -64,18 +64,28 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
|
|
|
64
64
|
|
|
65
65
|
## The walkthrough
|
|
66
66
|
|
|
67
|
-
`/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have
|
|
67
|
+
`/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have a sign-in link but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. Above it, on every prototype, **All prototypes** goes back to `/` in the same tab. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
|
|
68
68
|
|
|
69
|
-
## Deploying, and
|
|
69
|
+
## Deploying, and signing in
|
|
70
70
|
|
|
71
|
-
`miles-deploy` owns the steps; this is what they rest on. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing. `design-hub bootstrap --vercel <project>` links the project, connects it to the `origin` repo when Vercel can reach it, turns Vercel Authentication off and sets the env. `design-hub share` runs the pre-flight, then deploys: a push of a clean production branch when the project is connected to the repo (following the build for that commit), else `vercel deploy --prod`; then it requests the production URL signed
|
|
71
|
+
`miles-deploy` owns the steps; this is what they rest on. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing. `design-hub bootstrap --vercel <project>` links the project, connects it to the `origin` repo when Vercel can reach it, turns Vercel Authentication off and sets the env. `design-hub share` runs the pre-flight, then deploys: a push of a clean production branch when the project is connected to the repo (following the build for that commit), else `vercel deploy --prod`; then it requests the production URL as a signed-out browser and fails unless the sign-in page answers with `noindex` and a link no store holds answers 404, which proves the review store is wired (503 means there is none, so nobody could sign in). Every path on the deployed site sits behind the gate, enforced on the server by Vercel Routing Middleware (`vercel/proxy.ts`, exported as `createProxy` and default-exported by the project's one-line `proxy.ts`, which `vercel.json` names as `proxy.entrypoint`). A client-side gate was rejected because the bundle and the state behind it would still download.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
Every person is named, and signs in with a one-time link that Studio makes in the review panel's People tab or with `design-hub people add`.
|
|
74
|
+
|
|
75
|
+
- **A link works once.** `GET /invite/<token>` shows who it is for and a Continue button, and uses nothing up, since mail and chat previews open links too. Continue is a same-origin `POST` that uses the link up, sets the session cookie and goes to `/`. The use is atomic: the store's delete is the claim, so of two requests with one link only the one whose delete removed it signs in. A used, expired or unknown link answers 404, as does a link for someone revoked or past their access end. An unused link lasts 14 days. The store keeps only a hash of each token (32 random bytes), so a read of the store signs nobody in.
|
|
76
|
+
- **A second device gets a second link** (`design-hub people link <id>`), and the first stays signed in. **Sign out everywhere** (`people sign-out <id>`) bumps the person's epoch, drops their unused links and returns one new link. **Revoke** ends their access everywhere.
|
|
77
|
+
- **What a stale write cannot undo.** A person is a profile (name, team, kind, access end), written read-modify-write, plus two records only revoke and sign out everywhere touch: the revocation, written once and never cleared, and the epoch, raised only by `HINCRBY`. So a profile change that started before a revoke or a sign out everywhere and lands after it never clears the revocation or lowers the epoch, and two sign outs everywhere at once raise it twice.
|
|
78
|
+
- **Access lasts the engagement.** Each person has an access end: 3 months, 6 months, or open-ended. The project default (`people access --access <length>`, or `bootstrap --review --access`) applies to a new Client and is 3 months when unset; a new Studio person is open-ended, and Studio can set one person's length from the People tab or `people access <id>`.
|
|
79
|
+
- **The session** is one cookie, `__Host-hub_person`: `HttpOnly`, `Secure`, `SameSite=Lax`, signed with HMAC-SHA256 over the person, their epoch, an expiry, `checkedAt` (when the store last said yes) and the review store's URL, which is signed but never written into the token, so two projects that share a `GATE_SECRET` never accept each other's cookies, and versioned (`p3`), so a cookie from an older release never verifies. It lasts to the access end, at most 400 days, the longest a browser keeps one. For `CHECK_SECONDS` (5 minutes) after `checkedAt` any request passes on the signature. After that the next request, of any kind, asks the store: a current person passes with a fresh cookie whose expiry follows their current access end; a revoked, signed-out-everywhere or ended person gets 401 and the cookie cleared. The request's own headers never decide whether the store is asked, since the client chooses them. A store that fails answers 503 with `Retry-After`, and leaves the cookie, so an outage signs nobody out; the review panel reads `Retry-After` as try again, and a 503 without it as a site with no store. The API function answers the same way in JSON. The sign-in POST also refuses a store failure with 503, and a link is checked before it is used up, so a failure never burns one.
|
|
80
|
+
- **The link page** sends `Referrer-Policy: same-origin`, so Continue's POST carries a real `Origin` (with `no-referrer` a browser sends `Origin: null`, trusted only beside `Sec-Fetch-Site`, which older Safari does not send). Every other gate response sends `no-referrer`.
|
|
81
|
+
- **Signed out**, a page gets the sign-in page (401). It has no form: it says to open the link the studio sent, that each link signs in one device and then stops working, and to ask the studio for a new one for another device. Anything else gets a plain-text 401, an anonymous `POST` included.
|
|
82
|
+
|
|
83
|
+
The middleware reads one environment variable, set in the Vercel project for Production and Preview and never committed (`.env.example` names it): `GATE_SECRET`, at least 32 random characters that sign the session cookie. With it missing the gate answers 503 on every path, so a misconfigured deploy never serves the prototypes open. People and links live in the review store, so a site without it has a gate nobody can pass. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted by `vite/plugin.ts` at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The pages' title is the `siteName` the project's `proxy.ts` passes to `createProxy`. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page and `?page=used` a used one.
|
|
74
84
|
|
|
75
85
|
## Comments and people
|
|
76
86
|
|
|
77
|
-
|
|
87
|
+
Every signed-in person can comment as themselves. The People tab lists each person with their team, kind and when their access ends, and says how links behave where Studio shares them.
|
|
78
88
|
|
|
79
|
-
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `/api/review` (`server/api.ts`, reached on Vercel through the project's one-line `api/review.ts`, which also bundles the project's `checks.json` so triage runs on its thresholds): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may
|
|
89
|
+
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `/api/review` (`server/api.ts`, reached on Vercel through the project's one-line `api/review.ts`, which also bundles the project's `checks.json` so triage runs on its thresholds): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is) live once, in `core/review/`, behind a small storage port: Upstash Redis over REST when deployed, a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person.
|
|
80
90
|
|
|
81
91
|
`design-hub dev` serves the prototypes open, with the review panel on the local store. The gate is covered by `pnpm test` (`vercel/proxy.test.ts`, against an in-memory Upstash); `vercel dev` in a project runs it for real.
|
package/core/review/model.ts
CHANGED
|
@@ -6,15 +6,40 @@
|
|
|
6
6
|
|
|
7
7
|
import { SLUG } from '../feature.ts';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
export
|
|
9
|
+
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
10
|
+
export const PERSON_KINDS = ['studio', 'client'] as const;
|
|
11
|
+
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
11
12
|
|
|
12
13
|
/** How a comment is triaged: something broken, a design opinion, or the words. */
|
|
13
14
|
export const KINDS = ['bug', 'taste', 'copy'] as const;
|
|
14
15
|
export type Kind = (typeof KINDS)[number];
|
|
15
16
|
|
|
16
|
-
/** How long an
|
|
17
|
-
export const
|
|
17
|
+
/** How long an unused sign-in link lasts. A link signs in one device, then stops working. */
|
|
18
|
+
export const LINK_DAYS = 14;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* How long a person keeps access: three months, six months, or open-ended.
|
|
22
|
+
* The project sets a default; Studio can set it for one person.
|
|
23
|
+
*/
|
|
24
|
+
export const ACCESS = ['3m', '6m', 'open'] as const;
|
|
25
|
+
export type Access = (typeof ACCESS)[number];
|
|
26
|
+
/** The project default when none is set. */
|
|
27
|
+
export const DEFAULT_ACCESS: Access = '3m';
|
|
28
|
+
|
|
29
|
+
const ACCESS_MONTHS: Record<Exclude<Access, 'open'>, number> = { '3m': 3, '6m': 6 };
|
|
30
|
+
|
|
31
|
+
/** When access given at `from` ends, as an ISO time, or null for open-ended. */
|
|
32
|
+
export function accessEnd(access: Access, from: Date): string | null {
|
|
33
|
+
if (access === 'open') return null;
|
|
34
|
+
// On the same day of the month, or the target month's last day when it is shorter (30 Nov + 3m is 28 Feb).
|
|
35
|
+
const end = new Date(from.getTime());
|
|
36
|
+
const day = end.getUTCDate();
|
|
37
|
+
end.setUTCDate(1);
|
|
38
|
+
end.setUTCMonth(end.getUTCMonth() + ACCESS_MONTHS[access]);
|
|
39
|
+
const last = new Date(Date.UTC(end.getUTCFullYear(), end.getUTCMonth() + 1, 0)).getUTCDate();
|
|
40
|
+
end.setUTCDate(Math.min(day, last));
|
|
41
|
+
return end.toISOString();
|
|
42
|
+
}
|
|
18
43
|
|
|
19
44
|
export const LIMITS = {
|
|
20
45
|
name: 80,
|
|
@@ -32,13 +57,20 @@ export type Person = {
|
|
|
32
57
|
name: string;
|
|
33
58
|
/** The group a person belongs to, shown beside their name: the studio, or the client's company. */
|
|
34
59
|
team: string;
|
|
35
|
-
|
|
60
|
+
kind: PersonKind;
|
|
61
|
+
/** Always null until email sign-in exists. */
|
|
62
|
+
email: string | null;
|
|
63
|
+
/** When their access ends (ISO time), or null for open-ended. Their sessions end with it. */
|
|
64
|
+
accessEndsAt: string | null;
|
|
36
65
|
createdAt: string;
|
|
37
66
|
revokedAt: string | null;
|
|
38
|
-
/** Bumped on revoke and on
|
|
67
|
+
/** Bumped on revoke and on sign out everywhere, which ends every session signed with the old one. */
|
|
39
68
|
epoch: number;
|
|
40
69
|
};
|
|
41
70
|
|
|
71
|
+
/** A one-time sign-in link, stored under the hash of its token and deleted when used. */
|
|
72
|
+
export type Link = { person: string; expiresAt: string };
|
|
73
|
+
|
|
42
74
|
/** A comment's author as it was when they wrote it, so a revoked person's comments still read. */
|
|
43
75
|
export type Author = Pick<Person, 'id' | 'name' | 'team'>;
|
|
44
76
|
|
|
@@ -79,6 +111,39 @@ export type Comment = {
|
|
|
79
111
|
triage: Triage | null;
|
|
80
112
|
};
|
|
81
113
|
|
|
114
|
+
const isText = (v: unknown) => typeof v === 'string';
|
|
115
|
+
const isTextOrNull = (v: unknown) => v === null || typeof v === 'string';
|
|
116
|
+
|
|
117
|
+
/** What a stored profile must hold to be a person; anything else is no person at all. */
|
|
118
|
+
const PROFILE_RULES: [string, (v: unknown) => boolean][] = [
|
|
119
|
+
['id', (v) => isText(v) && v !== ''],
|
|
120
|
+
['name', isText],
|
|
121
|
+
['team', isText],
|
|
122
|
+
['kind', (v) => PERSON_KINDS.includes(v as PersonKind)],
|
|
123
|
+
['email', isTextOrNull],
|
|
124
|
+
['accessEndsAt', isTextOrNull],
|
|
125
|
+
['createdAt', isText],
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
/** Whether a stored profile (a person without revocation and epoch) is well formed. */
|
|
129
|
+
export function isProfile(v: unknown): v is Omit<Person, 'revokedAt' | 'epoch'> {
|
|
130
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) return false;
|
|
131
|
+
const o = v as Record<string, unknown>;
|
|
132
|
+
return PROFILE_RULES.every(([key, ok]) => ok(o[key]));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Whether someone may sign in at `at`: not revoked, and an access end that is
|
|
137
|
+
* open (null) or a parseable time still ahead. An access end that does not
|
|
138
|
+
* parse is no access.
|
|
139
|
+
*/
|
|
140
|
+
export function hasAccess(p: Pick<Person, 'revokedAt' | 'accessEndsAt'>, at: Date): boolean {
|
|
141
|
+
if (p.revokedAt !== null) return false;
|
|
142
|
+
if (p.accessEndsAt === null) return true;
|
|
143
|
+
const end = Date.parse(p.accessEndsAt);
|
|
144
|
+
return Number.isFinite(end) && end > at.getTime();
|
|
145
|
+
}
|
|
146
|
+
|
|
82
147
|
export const authorOf = (p: Person): Author => ({ id: p.id, name: p.name, team: p.team });
|
|
83
148
|
export const isRoot = (c: Comment) => c.thread === c.id;
|
|
84
149
|
|
|
@@ -99,14 +164,29 @@ const text = (v: unknown, path: string, max: number, problems: string[]): string
|
|
|
99
164
|
const fraction = (v: unknown) => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 1;
|
|
100
165
|
const size = (v: unknown) => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v < 100_000;
|
|
101
166
|
|
|
102
|
-
|
|
167
|
+
const isAccess = (v: unknown): v is Access => ACCESS.includes(v as Access);
|
|
168
|
+
const ACCESS_PROBLEM = `access: one of ${ACCESS.join(', ')}`;
|
|
169
|
+
|
|
170
|
+
export function checkAccess(input: unknown): Checked<Access> {
|
|
171
|
+
return isAccess(input) ? { ok: true, value: input } : { ok: false, problems: [ACCESS_PROBLEM] };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type PersonInput = Pick<Person, 'name' | 'team' | 'kind'> & { access: Access | null };
|
|
175
|
+
|
|
176
|
+
export function checkPersonInput(input: unknown): Checked<PersonInput> {
|
|
103
177
|
const i = (input ?? {}) as Record<string, unknown>;
|
|
104
178
|
const problems: string[] = [];
|
|
105
179
|
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
106
180
|
const team = text(i.team, 'team', LIMITS.team, problems);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
181
|
+
// Most people added are on the client's side; Studio is the deliberate choice.
|
|
182
|
+
const kind = i.kind ?? 'client';
|
|
183
|
+
if (!PERSON_KINDS.includes(kind as PersonKind)) problems.push(`kind: one of ${PERSON_KINDS.join(', ')}`);
|
|
184
|
+
// Absent, the service picks: the project default for a Client, open-ended for Studio.
|
|
185
|
+
const access = i.access ?? null;
|
|
186
|
+
if (access !== null && !isAccess(access)) problems.push(ACCESS_PROBLEM);
|
|
187
|
+
return problems.length
|
|
188
|
+
? { ok: false, problems }
|
|
189
|
+
: { ok: true, value: { name, team, kind: kind as PersonKind, access: access as Access | null } };
|
|
110
190
|
}
|
|
111
191
|
|
|
112
192
|
export function checkBody(body: unknown): Checked<string> {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import type { Comment, Person, PersonKind } from './model.ts';
|
|
4
|
+
import { type Action, can } from './policy.ts';
|
|
5
|
+
|
|
6
|
+
const person = (id: string, kind: PersonKind, revokedAt: string | null = null): Person => ({
|
|
7
|
+
id,
|
|
8
|
+
name: id,
|
|
9
|
+
team: kind === 'studio' ? 'Studio' : 'Acme',
|
|
10
|
+
kind,
|
|
11
|
+
email: null,
|
|
12
|
+
accessEndsAt: null,
|
|
13
|
+
createdAt: '',
|
|
14
|
+
revokedAt,
|
|
15
|
+
epoch: 0,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const thread = (author: string): Comment => ({
|
|
19
|
+
id: 'c',
|
|
20
|
+
thread: 'c',
|
|
21
|
+
author: { id: author, name: author, team: 'Acme' },
|
|
22
|
+
body: 'x',
|
|
23
|
+
createdAt: '',
|
|
24
|
+
editedAt: null,
|
|
25
|
+
anchor: null,
|
|
26
|
+
status: 'open',
|
|
27
|
+
resolvedBy: null,
|
|
28
|
+
triage: null,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// The rule table, one row per action: [Studio own, Studio other's, Client own, Client other's].
|
|
32
|
+
const TABLE: [Action, boolean, boolean, boolean, boolean][] = [
|
|
33
|
+
['read', true, true, true, true],
|
|
34
|
+
['comment', true, true, true, true],
|
|
35
|
+
['edit', true, false, true, false],
|
|
36
|
+
['resolve', true, true, true, true],
|
|
37
|
+
['delete', true, true, true, false],
|
|
38
|
+
['triage', true, true, false, false],
|
|
39
|
+
['people', true, true, false, false],
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const studio = person('s', 'studio');
|
|
43
|
+
const client = person('c', 'client');
|
|
44
|
+
|
|
45
|
+
for (const [action, studioOwn, studioOther, clientOwn, clientOther] of TABLE) {
|
|
46
|
+
test(`${action}: Studio and Client, own and another's`, () => {
|
|
47
|
+
assert.equal(can(studio, action, thread(studio.id)), studioOwn, 'Studio, own');
|
|
48
|
+
assert.equal(can(studio, action, thread('someone')), studioOther, "Studio, another's");
|
|
49
|
+
assert.equal(can(client, action, thread(client.id)), clientOwn, 'Client, own');
|
|
50
|
+
assert.equal(can(client, action, thread('someone')), clientOther, "Client, another's");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test(`${action}: nobody signed in and a revoked person may not`, () => {
|
|
54
|
+
for (const kind of ['studio', 'client'] as const) {
|
|
55
|
+
const gone = person('r', kind, '2030-01-01T00:00:00Z');
|
|
56
|
+
assert.equal(can(gone, action, thread(gone.id)), false, `revoked ${kind}, own`);
|
|
57
|
+
assert.equal(can(gone, action, thread('someone')), false, `revoked ${kind}, another's`);
|
|
58
|
+
}
|
|
59
|
+
assert.equal(can(null, action, thread('someone')), false, 'null');
|
|
60
|
+
assert.equal(can(null, action), false, 'null, no subject');
|
|
61
|
+
});
|
|
62
|
+
}
|
package/core/review/policy.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
// Who may do what.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Who may do what. Studio runs the review: it adds and revokes people,
|
|
2
|
+
// deletes any comment and corrects triage. A Client comments, replies, edits
|
|
3
|
+
// and deletes what they wrote, and resolves or reopens any thread, because
|
|
4
|
+
// clients work alongside others in their own organisation. A revoked person,
|
|
5
|
+
// or a visitor who is not signed in, may do nothing here.
|
|
5
6
|
import type { Comment, Person } from './model.ts';
|
|
6
7
|
|
|
7
8
|
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
11
|
+
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
12
|
+
|
|
13
|
+
export function can(actor: Actor | null, action: Action, subject?: Comment): boolean {
|
|
10
14
|
if (!actor || actor.revokedAt) return false;
|
|
11
|
-
const
|
|
15
|
+
const studio = actor.kind === 'studio';
|
|
12
16
|
const own = subject?.author.id === actor.id;
|
|
13
17
|
switch (action) {
|
|
14
18
|
case 'read':
|
|
15
19
|
case 'comment':
|
|
20
|
+
case 'resolve':
|
|
16
21
|
return true;
|
|
17
22
|
case 'edit':
|
|
18
23
|
return own;
|
|
19
24
|
case 'delete':
|
|
20
|
-
|
|
21
|
-
return own || editor;
|
|
25
|
+
return own || studio;
|
|
22
26
|
case 'triage':
|
|
23
27
|
case 'people':
|
|
24
|
-
return
|
|
28
|
+
return studio;
|
|
25
29
|
}
|
|
26
30
|
}
|