@bevel-software/platform-core-frontend 0.20.0 → 0.22.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.
Files changed (64) hide show
  1. package/package.json +2 -2
  2. package/src/core/registry.ts +57 -0
  3. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  4. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  5. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  6. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  7. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  8. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  9. package/src/modules/access/requests.api.ts +121 -0
  10. package/src/modules/auth/components/LoginScreen.tsx +6 -0
  11. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  12. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  13. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  14. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  15. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  16. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  17. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  18. package/src/modules/git/services/error-messages.ts +2 -2
  19. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  20. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  21. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  22. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  23. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  24. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  26. package/src/modules/library/__tests__/ToolPage.test.tsx +34 -0
  27. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  28. package/src/modules/library/__tests__/title-row-actions.ts +95 -0
  29. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  30. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  31. package/src/modules/library/components/PluginPage.tsx +115 -3
  32. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  33. package/src/modules/library/components/tool-page/ToolPage.tsx +36 -18
  34. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  35. package/src/modules/library/routes/library-paths.ts +9 -2
  36. package/src/modules/library/services/plugins.api.ts +45 -0
  37. package/src/modules/library/utils/plugin-summary.ts +7 -2
  38. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  39. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  40. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  41. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  42. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  43. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  44. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  45. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  46. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  47. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  48. package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
  49. package/src/modules/setup/__tests__/setup.test.tsx +8 -14
  50. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  51. package/src/modules/setup/components/SetupGate.tsx +1 -0
  52. package/src/modules/setup/components/SetupScreen.tsx +464 -38
  53. package/src/modules/setup/services/setup.api.ts +93 -0
  54. package/src/modules/setup/utils/kept-draft.ts +86 -0
  55. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  56. package/src/modules/workspace/components/FileViewer.tsx +8 -3
  57. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  58. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +49 -0
  59. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  60. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  61. package/src/modules/workspace/utils/fileTree.ts +2 -1
  62. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  63. package/src/shared/components/SlotBoundary.tsx +51 -0
  64. package/src/shared/theme/measure.ts +23 -2
@@ -1,11 +1,12 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import { Banner, Button } from '../../../shared/components';
3
3
  import { cn } from '../../../lib/utils';
4
- import type { JoinProposal, JoinRequest } from '../services/plugins.api';
4
+ import type { AccessProposal, AccessRequestRow } from '../requests.api';
5
5
 
6
6
  /**
7
- * Somebody asked for access to this plugin — the manager-side face of a join change
8
- * request.
7
+ * Somebody asked for access to this item — the editor-side face of an access
8
+ * request, wherever the item lives: a plugin's page, a skill's page, or the
9
+ * Manage access dialog of any file or folder.
9
10
  *
10
11
  * It shows what the request PROPOSES, one row per grant, because that is what
11
12
  * accepting acts on: each Accept writes exactly that one grant onto the
@@ -14,42 +15,57 @@ import type { JoinProposal, JoinRequest } from '../services/plugins.api';
14
15
  * yeses and three ignores, and nothing the branch happens to carry besides
15
16
  * the grants can ride in on a click.
16
17
  *
17
- * Naming the verb is not pedantry: a request may propose `write` or `owner`
18
+ * Naming the level is not pedantry: a request may propose `write` or `owner`
18
19
  * rather than `read`, and "asked for access to" would hide that. Whatever the
19
- * branch asks for is what the row says.
20
+ * branch asks for is what the row says — in the caller's vocabulary, since a
21
+ * dialog that calls it "Can edit" everywhere else must not suddenly say
22
+ * "write" here.
20
23
  *
21
- * Decline rejects the whole request. Manage access is the third path — a
22
- * manager who wants to do something other than what was proposed opens the
23
- * dialog, and the request settles itself if that covers it.
24
+ * Decline rejects the whole request. Manage access is the third path — an
25
+ * editor who wants to do something other than what was proposed opens the
26
+ * dialog, and the request settles itself if that covers it. Inside that
27
+ * dialog there is nothing to link to, so `folders` is empty there and the
28
+ * link does not render.
24
29
  */
25
30
 
26
31
  export interface AccessRequestsBannerProps {
27
- plugin: string;
28
- /** Repo-relative plugin folder for `Manage access` (single-element today). */
32
+ /** What the item is called on the line: a plugin, a skill, a file, a folder. */
33
+ itemName: string;
34
+ /** Repo-relative folders for `Manage access`. Empty ⇒ no link (the dialog). */
29
35
  folders: string[];
30
- requests: JoinRequest[];
36
+ requests: AccessRequestRow[];
31
37
  onManage(folder: string): void;
32
- onAccept(request: JoinRequest, proposal: JoinProposal): void;
33
- onDecline(request: JoinRequest): void;
38
+ onAccept(request: AccessRequestRow, proposal: AccessProposal): void;
39
+ onDecline(request: AccessRequestRow): void;
40
+ /** How to spell a verb. Defaults to the verb itself (the Library's wording). */
41
+ verbLabel?(verb: AccessProposal['verb']): string;
42
+ /** What went wrong answering this request, shown on its own line. */
43
+ errorFor?(request: AccessRequestRow): string | null | undefined;
44
+ /** Requests being answered right now — their buttons wait. */
45
+ busyFor?(request: AccessRequestRow): boolean;
34
46
  className?: string;
35
47
  }
36
48
 
37
49
  export function AccessRequestsBanner({
38
- plugin,
50
+ itemName,
39
51
  folders,
40
52
  requests,
41
53
  onManage,
42
54
  onAccept,
43
55
  onDecline,
56
+ verbLabel = (verb) => verb,
57
+ errorFor,
58
+ busyFor,
44
59
  className,
45
60
  }: AccessRequestsBannerProps) {
46
61
  if (requests.length === 0) return null;
47
62
 
48
- const accept = (request: JoinRequest, proposal: JoinProposal) => (
63
+ const accept = (request: AccessRequestRow, proposal: AccessProposal) => (
49
64
  <Button
50
65
  variant="outline"
51
66
  size="sm"
52
- aria-label={`Grant ${proposal.verb} to ${proposal.label}`}
67
+ disabled={busyFor?.(request) ?? false}
68
+ aria-label={`Grant ${verbLabel(proposal.verb)} to ${proposal.label}`}
53
69
  onClick={() => onAccept(request, proposal)}
54
70
  >
55
71
  Accept
@@ -64,16 +80,37 @@ export function AccessRequestsBanner({
64
80
  const lines: { key: string; text: ReactNode; actions: ReactNode; nested?: boolean }[] = [];
65
81
  for (const request of requests) {
66
82
  const single = request.proposals.length === 1 ? request.proposals[0] : null;
83
+ const note = request.note?.trim();
84
+ const failure = errorFor?.(request);
67
85
  lines.push({
68
86
  key: `request:${request.number}`,
69
- text: single ? (
87
+ text: (
70
88
  <>
71
- {`${request.requesterName} asked for access to ${plugin}: `}
72
- {single.label !== request.requesterName && `${single.label}, `}
73
- <span className="font-semibold">{single.verb}</span>
89
+ {single ? (
90
+ <>
91
+ {`${request.requesterName} asked for access to ${itemName}: `}
92
+ {single.label !== request.requesterName && `${single.label}, `}
93
+ <span className="font-semibold">{verbLabel(single.verb)}</span>
94
+ </>
95
+ ) : (
96
+ `${request.requesterName} asked for access to ${itemName}.`
97
+ )}
98
+ {/* The requester's own words, under the line they belong to and as
99
+ plain text — it is someone else's writing, not markup. */}
100
+ {note && (
101
+ <span className="mt-0.5 block whitespace-pre-line text-detail text-ink-muted">
102
+ {note}
103
+ </span>
104
+ )}
105
+ {/* A refusal belongs to the request it refused, never only to a
106
+ toast: this banner lives inside a dialog that has no toast host,
107
+ and an error shown there would simply vanish. */}
108
+ {failure && (
109
+ <span role="alert" className="mt-0.5 block text-detail text-danger">
110
+ {failure}
111
+ </span>
112
+ )}
74
113
  </>
75
- ) : (
76
- `${request.requesterName} asked for access to ${plugin}.`
77
114
  ),
78
115
  actions: (
79
116
  <>
@@ -81,6 +118,7 @@ export function AccessRequestsBanner({
81
118
  <Button
82
119
  variant="quiet"
83
120
  size="sm"
121
+ disabled={busyFor?.(request) ?? false}
84
122
  aria-label={`Decline the request from ${request.requesterName}`}
85
123
  onClick={() => onDecline(request)}
86
124
  >
@@ -96,7 +134,7 @@ export function AccessRequestsBanner({
96
134
  text: (
97
135
  <>
98
136
  {`${proposal.label}: `}
99
- <span className="font-semibold">{proposal.verb}</span>
137
+ <span className="font-semibold">{verbLabel(proposal.verb)}</span>
100
138
  </>
101
139
  ),
102
140
  actions: accept(request, proposal),
@@ -117,7 +155,7 @@ export function AccessRequestsBanner({
117
155
  <span className="flex shrink-0 items-center gap-1.5">
118
156
  {line.actions}
119
157
  {/* The third path, said as a link rather than a button of its
120
- own: the manager who wants something other than what was
158
+ own: the editor who wants something other than what was
121
159
  proposed. It closes the banner's last line. */}
122
160
  {i === lines.length - 1 &&
123
161
  folders.map((folder) => (
@@ -13,6 +13,7 @@ import { X, Lock, Loader2, ChevronDown, Check, Globe, CircleHelp } from 'lucide-
13
13
  import {
14
14
  canCarryFrontmatter,
15
15
  conferredByOthers,
16
+ DEFAULT_BRANCH,
16
17
  effectiveVerbs,
17
18
  folderGovernsAccessMessage,
18
19
  KNOWN_VERBS,
@@ -55,6 +56,10 @@ import {
55
56
  type SuggestResponse,
56
57
  } from '../api';
57
58
  import { EMAIL_RE, initials, labelInitials } from '../../../lib/email';
59
+ import { AccessRequestControl } from './AccessRequestControl';
60
+ import { AccessRequestsBanner } from './AccessRequestsBanner';
61
+ import { useAccessRequests } from '../hooks/useAccessRequests';
62
+ import { listAccessRequests, reconcileAccessRequest, LEVEL_WORDS } from '../requests.api';
58
63
 
59
64
  interface Props {
60
65
  entry: FileTreeEntry;
@@ -1182,6 +1187,49 @@ export function ManageAccessDialog({
1182
1187
  // Never on a folder-governed file: there is nothing here to write to.
1183
1188
  const canManage = !!data?.canWrite && !folderGoverns;
1184
1189
 
1190
+ /**
1191
+ * Is this sheet showing the LIVE workspace?
1192
+ *
1193
+ * Asking for access is offered there and nowhere else. A draft branch's
1194
+ * rules may differ from the ones the person is actually asking about, and a
1195
+ * file that exists only on a change request has no live rules at all — a
1196
+ * request from either would propose a grant into a branch nobody merges.
1197
+ * Both cases keep today's dialog, unchanged.
1198
+ */
1199
+ const liveWorkspace = !proposal && workspaceId === encodeURIComponent(DEFAULT_BRANCH);
1200
+
1201
+ /** What Accept grants on, and what the request routes are asked about. */
1202
+ const requestTarget = useMemo(
1203
+ () => ({ path: entry.relativePath, kind: targetKind }),
1204
+ [entry.relativePath, targetKind],
1205
+ );
1206
+
1207
+ // The item's open requests, for the people who can answer them. Asked for
1208
+ // unconditionally on the live workspace: the endpoint answers `[]` to
1209
+ // everyone who is not an editor, so "may I answer these" stays the server's
1210
+ // ruling rather than a guess made from `canManage`.
1211
+ const requestsSource = useMemo(
1212
+ () => ({
1213
+ list: () =>
1214
+ workspaceId && governed && liveWorkspace
1215
+ ? listAccessRequests(workspaceId, requestTarget)
1216
+ : Promise.resolve([]),
1217
+ reconcile: (number: number) =>
1218
+ workspaceId
1219
+ ? reconcileAccessRequest(workspaceId, number, requestTarget)
1220
+ : Promise.resolve(false),
1221
+ }),
1222
+ [workspaceId, governed, liveWorkspace, requestTarget],
1223
+ );
1224
+ const accessRequests = useAccessRequests({
1225
+ itemKey: liveWorkspace && governed ? `${workspaceId}:${entry.relativePath}` : null,
1226
+ source: requestsSource,
1227
+ grantOn: requestTarget,
1228
+ // The new row has to be on screen before the request's line goes, or an
1229
+ // Accept looks like it did nothing at all.
1230
+ onGranted: reload,
1231
+ });
1232
+
1185
1233
  // Resolve the CURRENT typed query into a principal to append as a chip: an
1186
1234
  // exact group/role match or a free-typed email. (Suggestion clicks append
1187
1235
  // directly.) Group first — bare grant tokens resolve group-first, so a name
@@ -1826,6 +1874,21 @@ export function ManageAccessDialog({
1826
1874
  </Banner>
1827
1875
  )}
1828
1876
 
1877
+ {/* Somebody is waiting on an answer, at the top of the sheet where the
1878
+ answer is given. No "Manage access" link: this IS that dialog. */}
1879
+ <AccessRequestsBanner
1880
+ itemName={entry.name}
1881
+ folders={[]}
1882
+ requests={accessRequests.requests}
1883
+ onManage={() => {}}
1884
+ onAccept={(r, pr) => void accessRequests.accept(r, pr)}
1885
+ onDecline={(r) => void accessRequests.decline(r)}
1886
+ verbLabel={(verb) => LEVEL_WORDS[verb as 'write' | 'owner'] ?? verb}
1887
+ errorFor={(r) => accessRequests.errors[r.number]}
1888
+ busyFor={(r) => !!accessRequests.busy[r.number]}
1889
+ className="mb-0 mt-3"
1890
+ />
1891
+
1829
1892
  {governed && canManage && (
1830
1893
  <div className="mt-3">
1831
1894
  {/* `items-start`, not `items-stretch`: the verb button is `rounded-full`,
@@ -2149,10 +2212,24 @@ export function ManageAccessDialog({
2149
2212
  ) : (
2150
2213
  <>
2151
2214
  {!canManage && (
2152
- <Banner tone="neutral" role="note" className="mt-3">
2153
- Only people with edit access can share this {targetKind}.
2154
- {ownerNames && <> Ask an owner: {ownerNames}.</>}
2155
- </Banner>
2215
+ <>
2216
+ <Banner tone="neutral" role="note" className="mt-3">
2217
+ Only people with edit access can share this {targetKind}.
2218
+ {ownerNames && <> Ask an owner: {ownerNames}.</>}
2219
+ </Banner>
2220
+ {/* The rest of that sentence. Only on the live workspace,
2221
+ and only where the item has rules of its own to ask
2222
+ about — a folder-governed file keeps its pointer at the
2223
+ folder, whose dialog carries the control. */}
2224
+ {liveWorkspace && workspaceId && (
2225
+ <AccessRequestControl
2226
+ workspaceId={workspaceId}
2227
+ target={requestTarget}
2228
+ targetKind={targetKind}
2229
+ ownerNames={ownerNames}
2230
+ />
2231
+ )}
2232
+ </>
2156
2233
  )}
2157
2234
 
2158
2235
  {/* Names WHICH RULE you are editing, and adapts to the target
@@ -0,0 +1,183 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
3
+ import { useLatestRef } from '../../../shared/components';
4
+ import { grantAccess } from '../api';
5
+ import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
6
+ import type { AccessProposal, AccessRequestRow } from '../requests.api';
7
+
8
+ /**
9
+ * The access requests one item's editors can answer, and the two ways to
10
+ * answer them.
11
+ *
12
+ * ACCEPTING IS A GRANT, NOT A MERGE. A proposal is "give this principal this
13
+ * verb on this item", so accepting it calls the ordinary access-grant API —
14
+ * the same endpoint the Manage access dialog's own rows use, with the same
15
+ * gate, lock and commit, and the same answer for a person the rules explicitly
16
+ * deny. The request's branch is never merged, so nothing else it carries can
17
+ * ride in on an approval, and a request naming five people can be answered
18
+ * with two yeses and three ignores.
19
+ *
20
+ * The request then retires ITSELF: it is open exactly while it proposes
21
+ * something the person does not already hold, so once the accepted grant lands
22
+ * the server closes it and deletes the branch. `reconcile` just asks for that
23
+ * check immediately instead of waiting for the next listing (which does it
24
+ * too).
25
+ *
26
+ * Fetching is unconditional and degrades to `[]` — the endpoints answer `[]`
27
+ * to non-editors rather than 403, so "am I an editor here" stays a question
28
+ * only the server answers.
29
+ */
30
+ export interface AccessRequestsState {
31
+ requests: AccessRequestRow[];
32
+ /** Grant one proposal, then settle the request if that was the last one. */
33
+ accept(request: AccessRequestRow, proposal: AccessProposal): Promise<void>;
34
+ /** Decline the whole request — reject the change request. */
35
+ decline(request: AccessRequestRow): Promise<void>;
36
+ /** Why answering a request failed, by request number. Cleared by a retry. */
37
+ errors: Readonly<Record<number, string>>;
38
+ /** Request numbers being answered right now. */
39
+ busy: Readonly<Record<number, boolean>>;
40
+ reload(): void;
41
+ }
42
+
43
+ /** Where the requests come from — one item's listing and its settle call. */
44
+ export interface AccessRequestsSource {
45
+ list(): Promise<AccessRequestRow[]>;
46
+ reconcile(number: number): Promise<boolean>;
47
+ }
48
+
49
+ export interface UseAccessRequestsOptions {
50
+ /**
51
+ * What identifies the item. Requests are shown only while the key they
52
+ * arrived for is still the one being asked about: a page that moves from
53
+ * skill A to skill B without unmounting must not show A's requests until
54
+ * B's arrive — a banner that lets an editor grant A's proposal against B's
55
+ * rules.
56
+ */
57
+ itemKey: string | null;
58
+ source: AccessRequestsSource;
59
+ /** What an Accept grants on. Null ⇒ Accept does nothing. */
60
+ grantOn: { path: string; kind: 'folder' | 'file' } | null;
61
+ /** Run after a grant lands — where the caller re-reads what it shows. */
62
+ onGranted?(): void | Promise<void>;
63
+ /** Told what went wrong, on top of the per-request `errors` map. */
64
+ onError?(message: string): void;
65
+ /** Told what landed, for surfaces that announce it. */
66
+ onAccepted?(message: string): void;
67
+ }
68
+
69
+ export function useAccessRequests(opts: UseAccessRequestsOptions): AccessRequestsState {
70
+ const { itemKey, source, grantOn, onGranted, onError, onAccepted } = opts;
71
+ // Keyed by the item they came from — see `itemKey`.
72
+ const [loaded, setLoaded] = useState<{ key: string; rows: AccessRequestRow[] } | null>(null);
73
+ const requests = loaded && itemKey !== null && loaded.key === itemKey ? loaded.rows : [];
74
+ const [revision, setRevision] = useState(0);
75
+ const [errors, setErrors] = useState<Record<number, string>>({});
76
+ const [busy, setBusy] = useState<Record<number, boolean>>({});
77
+
78
+ // Held in a ref rather than in the effect's deps: these are values the
79
+ // caller rebuilds on every render, and depending on them would refetch the
80
+ // listing on every render — including the re-render the listing's own answer
81
+ // causes. Read only from effects and event handlers, never during render.
82
+ const live = useLatestRef({ source, grantOn, onGranted, onError, onAccepted });
83
+
84
+ useEffect(() => {
85
+ if (itemKey === null) return;
86
+ let cancelled = false;
87
+ live.current.source
88
+ .list()
89
+ .then((rows) => {
90
+ if (!cancelled) setLoaded({ key: itemKey, rows });
91
+ })
92
+ .catch(() => {
93
+ // Silent: an editor surface that fails must not put an error banner in
94
+ // front of somebody who came to read the item.
95
+ });
96
+ return () => {
97
+ cancelled = true;
98
+ };
99
+ // `live` is a stable ref object; it is listed only to satisfy the rule.
100
+ }, [itemKey, revision, live]);
101
+
102
+ const reload = useCallback(() => setRevision((r) => r + 1), []);
103
+
104
+ const mark = (number: number, running: boolean) =>
105
+ setBusy((b) => ({ ...b, [number]: running }));
106
+
107
+ const accept = useCallback(async (request: AccessRequestRow, proposal: AccessProposal) => {
108
+ const { grantOn: target, onGranted: granted, onError: fail, onAccepted: ok } = live.current;
109
+ if (!target) return;
110
+ setErrors((e) => {
111
+ if (!(request.number in e)) return e;
112
+ const next = { ...e };
113
+ delete next[request.number];
114
+ return next;
115
+ });
116
+ mark(request.number, true);
117
+ try {
118
+ await grantAccess(encodeURIComponent(DEFAULT_BRANCH), {
119
+ path: target.path,
120
+ kind: target.kind,
121
+ verb: proposal.verb,
122
+ principal: proposal.principal,
123
+ });
124
+ } catch (err) {
125
+ // The request STAYS OPEN: nothing was granted, so there is nothing to
126
+ // settle, and hiding the line would lose the only place the refusal is
127
+ // visible.
128
+ const message = err instanceof Error ? err.message : "Couldn't grant that: try again.";
129
+ setErrors((e) => ({ ...e, [request.number]: message }));
130
+ fail?.(message);
131
+ mark(request.number, false);
132
+ setRevision((r) => r + 1);
133
+ return;
134
+ }
135
+ // Drop the accepted proposal locally so the row goes immediately; the
136
+ // refetch below is what makes it true.
137
+ setLoaded((cur) =>
138
+ cur && itemKey !== null && cur.key === itemKey
139
+ ? {
140
+ ...cur,
141
+ rows: cur.rows.map((r) =>
142
+ r.number === request.number
143
+ ? {
144
+ ...r,
145
+ proposals: r.proposals.filter(
146
+ (p) => !(p.id === proposal.id && p.verb === proposal.verb),
147
+ ),
148
+ }
149
+ : r,
150
+ ),
151
+ }
152
+ : cur,
153
+ );
154
+ ok?.(`${proposal.label} now has ${proposal.verb} access.`);
155
+ // The caller re-reads FIRST: the new row has to be on screen by the time
156
+ // the request's line goes, or accepting looks like it did nothing.
157
+ await Promise.resolve(granted?.()).catch(() => undefined);
158
+ await live.current.source.reconcile(request.number).catch(() => false);
159
+ mark(request.number, false);
160
+ setRevision((r) => r + 1);
161
+ }, [itemKey, live]);
162
+
163
+ const decline = useCallback(async (request: AccessRequestRow) => {
164
+ mark(request.number, true);
165
+ try {
166
+ await cancelPullRequest(request.number);
167
+ setErrors((e) => {
168
+ if (!(request.number in e)) return e;
169
+ const next = { ...e };
170
+ delete next[request.number];
171
+ return next;
172
+ });
173
+ } catch (err) {
174
+ const message = err instanceof Error ? err.message : "Couldn't dismiss that: try again.";
175
+ setErrors((e) => ({ ...e, [request.number]: message }));
176
+ live.current.onError?.(message);
177
+ }
178
+ mark(request.number, false);
179
+ setRevision((r) => r + 1);
180
+ }, [live]);
181
+
182
+ return { requests, accept, decline, errors, busy, reload };
183
+ }
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { isProtectedBranch } from '@bevel-software/platform-shared';
2
+ import { currentBranchModel, isProtectedBranch } from '@bevel-software/platform-shared';
3
3
  import { useWorkspace } from '../../workspace/state/workspace.context';
4
4
  import { fetchFileAccess, type AccessEligible } from '../api';
5
5
 
@@ -98,7 +98,7 @@ export function useFileAccess(
98
98
  setState({ canWrite: null, canDownload: null, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
99
99
  return;
100
100
  }
101
- if (!isProtectedBranch(branch)) {
101
+ if (!isProtectedBranch(currentBranchModel(), branch)) {
102
102
  // `canDownload: null` — NOT true. The write short-circuits are this
103
103
  // hook's own policy, and they match the backend's write gates; the raw
104
104
  // endpoint gates EVERY download regardless of branch or path, so
@@ -0,0 +1,121 @@
1
+ import { authFetch } from '../../lib/api';
2
+ import { handleApiResponse } from '../git/services/git.api';
3
+
4
+ /** The two levels the Manage access dialog can ask for. Owner covers Can edit. */
5
+ export type RequestLevel = 'write' | 'owner';
6
+
7
+ /** The dialog's own words for a level — the same ones its row menu uses. */
8
+ export const LEVEL_WORDS: Record<RequestLevel, string> = {
9
+ write: 'Can edit',
10
+ owner: 'Owner',
11
+ };
12
+
13
+ /** The longest note a request can carry, in characters. Mirrors the server's cap. */
14
+ export const REQUEST_NOTE_MAX = 500;
15
+
16
+ /**
17
+ * What the requester's own dialog shows in place of the control.
18
+ *
19
+ * `not-accepted` means their last request closed without the access landing —
20
+ * declined by an editor, or withdrawn by themselves. The two read the same on
21
+ * purpose: nothing records WHO closed a request, and inventing a difference
22
+ * would need a new column.
23
+ */
24
+ export interface AccessRequestStatus {
25
+ state: 'none' | 'pending' | 'not-accepted';
26
+ level?: RequestLevel;
27
+ number?: number;
28
+ }
29
+
30
+ /** One grant a request still proposes — the shape `grantAccess` takes. */
31
+ export interface AccessProposal {
32
+ verb: 'read' | 'write' | 'owner' | 'download';
33
+ /** Canonical identity (lowercased email / canonical role) — a stable key. */
34
+ id: string;
35
+ principal:
36
+ | { kind: 'user'; email: string; displayName: string }
37
+ | { kind: 'role'; role: string };
38
+ label: string;
39
+ }
40
+
41
+ /** One open request, as the editors' surfaces render it. */
42
+ export interface AccessRequestRow {
43
+ number: number;
44
+ branch: string;
45
+ requesterName: string;
46
+ createdAt: string;
47
+ /** Still-pending proposals; a request with none left is already closed. */
48
+ proposals: AccessProposal[];
49
+ /** The requester's note, as plain text, when they wrote one. */
50
+ note?: string;
51
+ }
52
+
53
+ /** Repo- or workspace-relative path plus what it is; both are sent verbatim. */
54
+ interface TargetQuery {
55
+ path: string;
56
+ kind: 'folder' | 'file';
57
+ }
58
+
59
+ const query = (t: TargetQuery) => `path=${encodeURIComponent(t.path)}&kind=${t.kind}`;
60
+
61
+ /** Where the caller's own request on this item stands. */
62
+ export async function fetchAccessRequestStatus(
63
+ workspaceId: string,
64
+ target: TargetQuery,
65
+ ): Promise<AccessRequestStatus> {
66
+ return handleApiResponse(
67
+ await authFetch(`/api/workspace/${workspaceId}/access/request?${query(target)}`),
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Ask for `level` on this item. Idempotent by (person, item): a second send
73
+ * while a request is open answers with that same request rather than opening
74
+ * a rival, so a double click leaves exactly one.
75
+ */
76
+ export async function sendAccessRequest(
77
+ workspaceId: string,
78
+ input: TargetQuery & { level: RequestLevel; note?: string },
79
+ ): Promise<{ number: number; level: RequestLevel }> {
80
+ return handleApiResponse(
81
+ await authFetch(`/api/workspace/${workspaceId}/access/request`, {
82
+ method: 'POST',
83
+ headers: { 'Content-Type': 'application/json' },
84
+ body: JSON.stringify(input),
85
+ }),
86
+ );
87
+ }
88
+
89
+ /**
90
+ * The open requests for an item the caller EDITS. Everyone else gets `[]`
91
+ * rather than a 403, so the dialog may ask unconditionally — "am I an editor
92
+ * here" stays a question only the server answers.
93
+ */
94
+ export async function listAccessRequests(
95
+ workspaceId: string,
96
+ target: TargetQuery,
97
+ ): Promise<AccessRequestRow[]> {
98
+ const data = await handleApiResponse<{ requests: AccessRequestRow[] }>(
99
+ await authFetch(`/api/workspace/${workspaceId}/access/requests?${query(target)}`),
100
+ );
101
+ return data.requests;
102
+ }
103
+
104
+ /**
105
+ * Ask the server to settle a request whose proposals have all landed. The
106
+ * listing does this lazily too, so a failure here only delays it.
107
+ */
108
+ export async function reconcileAccessRequest(
109
+ workspaceId: string,
110
+ number: number,
111
+ target: TargetQuery,
112
+ ): Promise<boolean> {
113
+ const data = await handleApiResponse<{ closed: boolean }>(
114
+ await authFetch(`/api/workspace/${workspaceId}/access/requests/${number}/reconcile`, {
115
+ method: 'POST',
116
+ headers: { 'Content-Type': 'application/json' },
117
+ body: JSON.stringify(target),
118
+ }),
119
+ );
120
+ return data.closed;
121
+ }
@@ -12,6 +12,12 @@ const OAUTH_ERROR_MESSAGES: Record<string, string> = {
12
12
  auth: 'Sign-in failed. Please try again.',
13
13
  start: 'Could not start sign-in. Please try again.',
14
14
  not_configured: 'Single sign-on is not configured on this deployment.',
15
+ admission: 'This workspace has no seat available for your account. Ask its admin.',
16
+ // Who you are was proven; nobody has given that person an account here.
17
+ not_invited: 'You do not have an account in this workspace yet. Ask its admin to invite you.',
18
+ // The provider signed the person in but does not vouch for the address.
19
+ unverified_email:
20
+ 'Your sign-in provider has not verified your email address, so it cannot be used to sign in here.',
15
21
  };
16
22
 
17
23
  export function LoginScreen() {