@coffre/ui 0.2.0 → 0.4.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/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
- package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
- package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
- package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
- package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
- package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
- package/dist/chunks/folders-DoBmCwOi.js +207 -0
- package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
- package/dist/chunks/grants-Cw1FyGID.js +669 -0
- package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
- package/dist/chunks/offboarding-CE6d7um1.js +305 -0
- package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
- package/dist/chunks/one-time-DXEl9hbg.js +35 -0
- package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
- package/dist/chunks/page-DvsgZ2Hd.js +391 -0
- package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
- package/dist/chunks/principal-BIN-xwZw.js +42 -0
- package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
- package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
- package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
- package/dist/chunks/project-page-SRCtRe2g.js +17 -0
- package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
- package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
- package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
- package/dist/chunks/references-B6pLT1uQ.js +343 -0
- package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
- package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
- package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
- package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
- package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
- package/dist/chunks/tabs-BmwKfUeK.js +22 -0
- package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
- package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
- package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
- package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
- package/dist/chunks/ui-DJje3gST.js.map +1 -0
- package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
- package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
- package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
- package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
- package/dist/chunks/validation-D312_NLf.js +87 -0
- package/dist/chunks/validation-D312_NLf.js.map +1 -0
- package/dist/index.d.ts +361 -27
- package/dist/index.js +188 -98
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +2 -2
- package/dist/pages/account.js +297 -135
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.d.ts +9 -0
- package/dist/pages/approval.js +207 -0
- package/dist/pages/approval.js.map +1 -0
- package/dist/pages/audit.js +17 -542
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -3
- package/dist/pages/device-login.js.map +1 -1
- package/dist/pages/environment.js +647 -257
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +18 -7
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.d.ts +10 -0
- package/dist/pages/oauth-authorize.js +249 -0
- package/dist/pages/oauth-authorize.js.map +1 -0
- package/dist/pages/project-access.d.ts +6 -0
- package/dist/pages/project-access.js +370 -0
- package/dist/pages/project-access.js.map +1 -0
- package/dist/pages/project-environments.d.ts +4 -0
- package/dist/pages/project-environments.js +593 -0
- package/dist/pages/project-environments.js.map +1 -0
- package/dist/pages/project-settings.d.ts +4 -0
- package/dist/pages/project-settings.js +242 -0
- package/dist/pages/project-settings.js.map +1 -0
- package/dist/pages/project.d.ts +10 -2
- package/dist/pages/project.js +57 -934
- package/dist/pages/project.js.map +1 -1
- package/dist/pages/projects.js +53 -21
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.d.ts +10 -0
- package/dist/pages/{token.js → service-account.js} +115 -56
- package/dist/pages/service-account.js.map +1 -0
- package/dist/pages/service-accounts.d.ts +3 -0
- package/dist/pages/service-accounts.js +38 -0
- package/dist/pages/service-accounts.js.map +1 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +104 -42
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -3
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +6 -1
- package/dist/pages/user.js +18 -6
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +6 -10
- package/dist/pages/users.js.map +1 -1
- package/package.json +3 -3
- package/src/components/actions-log.tsx +117 -0
- package/src/components/audit-sentence.tsx +55 -0
- package/src/components/command-palette.tsx +4 -4
- package/src/components/delete-place.tsx +180 -0
- package/src/components/directory.tsx +259 -110
- package/src/components/every-project.tsx +287 -0
- package/src/components/expiry-field.tsx +42 -0
- package/src/components/folders.tsx +219 -0
- package/src/components/grants.tsx +11 -4
- package/src/components/icons.tsx +2 -0
- package/src/components/missing.tsx +110 -0
- package/src/components/offboarding.tsx +61 -33
- package/src/components/page.tsx +4 -1
- package/src/components/principal-page.tsx +136 -106
- package/src/components/principal-picker.tsx +5 -5
- package/src/components/principal.tsx +4 -4
- package/src/components/references.tsx +323 -0
- package/src/components/service-tokens.tsx +115 -95
- package/src/components/shell.tsx +11 -32
- package/src/components/tabs.tsx +18 -0
- package/src/components/trusted-workloads.tsx +97 -79
- package/src/components/ui.tsx +8 -1
- package/src/index.ts +13 -2
- package/src/layout.tsx +2 -2
- package/src/lib/access-plan.ts +2 -2
- package/src/lib/audit-sentences.ts +161 -77
- package/src/lib/changes.ts +56 -5
- package/src/lib/coffre.ts +3 -2
- package/src/lib/one-time.ts +32 -0
- package/src/lib/project-access.ts +11 -23
- package/src/lib/project-page.ts +14 -0
- package/src/lib/queries.ts +126 -32
- package/src/lib/search.ts +25 -0
- package/src/lib/signin-errors.ts +45 -1
- package/src/lib/validation.ts +14 -0
- package/src/options.ts +187 -35
- package/src/pages/account.tsx +274 -129
- package/src/pages/approval.tsx +197 -0
- package/src/pages/audit.tsx +9 -61
- package/src/pages/environment.tsx +585 -286
- package/src/pages/login.tsx +8 -2
- package/src/pages/oauth-authorize.tsx +233 -0
- package/src/pages/project-access.tsx +219 -0
- package/src/pages/project-environments.tsx +582 -0
- package/src/pages/project-settings.tsx +259 -0
- package/src/pages/project.tsx +52 -879
- package/src/pages/projects.tsx +55 -18
- package/src/pages/service-account.tsx +50 -0
- package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
- package/src/pages/settings.tsx +62 -8
- package/src/pages/user.tsx +16 -4
- package/src/pages/users.tsx +2 -2
- package/src/parity.ts +160 -0
- package/src/register.ts +58 -9
- package/src/router.tsx +4 -0
- package/src/shared/models.ts +6 -2
- package/src/styles/globals.css +536 -31
- package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
- package/dist/chunks/grants-saMQagmG.js +0 -160
- package/dist/chunks/grants-saMQagmG.js.map +0 -1
- package/dist/chunks/icons-D-PfAfnH.js +0 -203
- package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
- package/dist/chunks/offboarding-C6l30DZR.js +0 -263
- package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
- package/dist/chunks/page-C5HcNqf2.js +0 -190
- package/dist/chunks/page-C5HcNqf2.js.map +0 -1
- package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
- package/dist/chunks/queries-CQ81o4so.js.map +0 -1
- package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
- package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
- package/dist/chunks/use-action-CWsg_YWU.js +0 -49
- package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
- package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
- package/dist/chunks/validation-BQtqPe2V.js +0 -29
- package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
- package/dist/pages/token.d.ts +0 -3
- package/dist/pages/token.js.map +0 -1
- package/dist/pages/tokens.d.ts +0 -3
- package/dist/pages/tokens.js +0 -39
- package/dist/pages/tokens.js.map +0 -1
- package/dist/project-BqIy8gYR.d.ts +0 -5
- package/src/lib/instance.ts +0 -13
- package/src/pages/token.tsx +0 -34
package/src/pages/login.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useShell } from '../lib/use-shell';
|
|
4
4
|
import { signinErrorMessage } from '../lib/signin-errors';
|
|
5
|
+
import { useOneTime } from '../lib/one-time';
|
|
5
6
|
import { ErrorLine, Spinner } from '../components/ui';
|
|
6
7
|
import { ClosedDoor } from '../components/page';
|
|
7
8
|
import { Lock, ProviderMark, ShieldCheck } from '../components/icons';
|
|
@@ -67,8 +68,13 @@ function ProviderLoginPage({
|
|
|
67
68
|
note: string | null;
|
|
68
69
|
providers: { id: string; label: string; brand: string }[];
|
|
69
70
|
}) {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
71
|
+
const search = Route.useSearch();
|
|
72
|
+
const { next } = search;
|
|
73
|
+
// Shown once: a reload is a clean retry.
|
|
74
|
+
const once = useOneTime(search, ['error', 'with', 'via']);
|
|
75
|
+
const label = (id: string) => providers.find((provider) => provider.id === id)?.label;
|
|
76
|
+
const already = (once.with ?? '').split(',').map(label).filter((name): name is string => name !== undefined);
|
|
77
|
+
const message = signinErrorMessage(once.error, { providers: already, via: once.via === undefined ? undefined : label(once.via) });
|
|
72
78
|
const [leaving, setLeaving] = useState<string | null>(null);
|
|
73
79
|
const query = next === undefined ? '' : `?next=${encodeURIComponent(next)}`;
|
|
74
80
|
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { AuthorizationView, RouteInput } from '@coffre/client';
|
|
3
|
+
import { MCP_SCOPE_INFO, supersedes, type McpScope } from '@coffre/core/mcp';
|
|
4
|
+
|
|
5
|
+
import { failureMessage, statusOf, useCoffre } from '../lib/coffre';
|
|
6
|
+
import { ClosedDoor } from '../components/page';
|
|
7
|
+
import { ErrorLine, Notice, Spinner } from '../components/ui';
|
|
8
|
+
import { ArrowRight, Link as LinkIcon, SlashCircle } from '../components/icons';
|
|
9
|
+
import { pageRoute } from '../lib/page-route';
|
|
10
|
+
import type { oauthAuthorize } from '../options';
|
|
11
|
+
|
|
12
|
+
const Route = pageRoute<typeof oauthAuthorize>();
|
|
13
|
+
|
|
14
|
+
type Ready = Extract<AuthorizationView, { status: 'ready' }>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Where an MCP client, such as Claude, sends you to connect: who it is,
|
|
18
|
+
* where coffre's answer goes, and what it may do as you. Nothing is granted
|
|
19
|
+
* until you press Approve, and every connection asks again: there is no
|
|
20
|
+
* silent re-consent. Either answer goes back to the app by `location`,
|
|
21
|
+
* never a form post, which the page's `form-action 'self'` would stop.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function OauthAuthorizePage() {
|
|
25
|
+
const loaded = Route.useLoaderData();
|
|
26
|
+
const [leaving, setLeaving] = useState(false);
|
|
27
|
+
|
|
28
|
+
if (leaving) {
|
|
29
|
+
return (
|
|
30
|
+
<ClosedDoor icon={<ArrowRight size={18} />} label="Connect an app" title="Sending you back to the app">
|
|
31
|
+
<p>You can close this tab if the app has already opened.</p>
|
|
32
|
+
</ClosedDoor>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (!loaded.result.ok) return <CannotConnect message={loaded.result.error} />;
|
|
36
|
+
const view = loaded.result;
|
|
37
|
+
if (view.status === 'invalid') return <CannotConnect message={view.message} />;
|
|
38
|
+
if (view.status === 'refused') {
|
|
39
|
+
return (
|
|
40
|
+
<ClosedDoor
|
|
41
|
+
icon={<SlashCircle size={18} />}
|
|
42
|
+
label="Connect an app"
|
|
43
|
+
title="This request can't be approved"
|
|
44
|
+
actions={
|
|
45
|
+
<button
|
|
46
|
+
className="btn"
|
|
47
|
+
onClick={() => {
|
|
48
|
+
setLeaving(true);
|
|
49
|
+
location.assign(view.redirect);
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
Back to the app
|
|
53
|
+
</button>
|
|
54
|
+
}
|
|
55
|
+
>
|
|
56
|
+
<p>{view.message}. Nothing was granted; the app is told why.</p>
|
|
57
|
+
</ClosedDoor>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
<Approve
|
|
62
|
+
view={view}
|
|
63
|
+
email={loaded.email}
|
|
64
|
+
request={loaded.request}
|
|
65
|
+
onLeave={(redirect) => {
|
|
66
|
+
setLeaving(true);
|
|
67
|
+
location.assign(redirect);
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A client or redirect that fails its checks: said here, and never redirected to, which would be an open redirect. */
|
|
74
|
+
function CannotConnect({ message }: { message: string }) {
|
|
75
|
+
return (
|
|
76
|
+
<ClosedDoor icon={<SlashCircle size={18} />} label="Connect an app" title="This app can't connect">
|
|
77
|
+
<p>{message}</p>
|
|
78
|
+
<p>Nothing was sent to it. If you were trying to connect it, tell whoever makes it.</p>
|
|
79
|
+
</ClosedDoor>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Approve({
|
|
84
|
+
view,
|
|
85
|
+
email,
|
|
86
|
+
request,
|
|
87
|
+
onLeave,
|
|
88
|
+
}: {
|
|
89
|
+
view: Ready;
|
|
90
|
+
email: string;
|
|
91
|
+
request: RouteInput<'GET /oauth/authorizations'>;
|
|
92
|
+
onLeave: (redirect: string) => void;
|
|
93
|
+
}) {
|
|
94
|
+
const coffre = useCoffre();
|
|
95
|
+
const [chosen, setChosen] = useState<ReadonlySet<McpScope>>(() => new Set(view.scopes));
|
|
96
|
+
const [pending, setPending] = useState<'approve' | 'deny' | null>(null);
|
|
97
|
+
const [error, setError] = useState<string | null>(null);
|
|
98
|
+
const { client } = view;
|
|
99
|
+
const unverified = client.registration === 'dcr';
|
|
100
|
+
// A step-up: the connections this one grants all of and more end once the app has its new one.
|
|
101
|
+
const granted = view.scopes.filter((scope) => chosen.has(scope));
|
|
102
|
+
const replaced = view.connections.filter((held) => supersedes(granted, held)).length;
|
|
103
|
+
const kept = view.connections.length - replaced;
|
|
104
|
+
|
|
105
|
+
async function decide(approve: boolean) {
|
|
106
|
+
setPending(approve ? 'approve' : 'deny');
|
|
107
|
+
try {
|
|
108
|
+
const { redirect } = await coffre.oauth.decide({ request, approve, scopes: [...chosen] });
|
|
109
|
+
onLeave(redirect);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
setError(
|
|
112
|
+
statusOf(error) === undefined ? 'The answer could not be sent. Nothing was approved.' : failureMessage(error),
|
|
113
|
+
);
|
|
114
|
+
setPending(null);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function toggle(scope: McpScope, on: boolean) {
|
|
119
|
+
const next = new Set(chosen);
|
|
120
|
+
if (on) next.add(scope);
|
|
121
|
+
else next.delete(scope);
|
|
122
|
+
setChosen(next);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<section className="card signin" aria-labelledby="consent-title">
|
|
127
|
+
<div className="signin-head">
|
|
128
|
+
<h1 className="signin-title" id="consent-title">
|
|
129
|
+
Connect {client.name} to coffre?
|
|
130
|
+
</h1>
|
|
131
|
+
<p className="signin-lede">
|
|
132
|
+
Only if you just asked it to connect. It acts as you, and can never do more than you can.
|
|
133
|
+
</p>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<div className="consent-client">
|
|
137
|
+
<LinkIcon size={16} />
|
|
138
|
+
{/* The website first, which a name cannot fake; a registration has none, and says so. */}
|
|
139
|
+
<span className="cell-stack">
|
|
140
|
+
{client.host !== null ? (
|
|
141
|
+
<span className="consent-host mono">{client.host}</span>
|
|
142
|
+
) : (
|
|
143
|
+
<span className="consent-host">{client.name}</span>
|
|
144
|
+
)}
|
|
145
|
+
<span>
|
|
146
|
+
{client.host !== null && <>{client.name} </>}
|
|
147
|
+
{unverified && <span className="tag tag-amber">Unverified</span>}
|
|
148
|
+
{unverified && <small> It registered itself: its name is its own claim.</small>}
|
|
149
|
+
</span>
|
|
150
|
+
</span>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<dl className="facts device-facts">
|
|
154
|
+
<div className="fact">
|
|
155
|
+
<dt>As</dt>
|
|
156
|
+
<dd className="mono">{email}</dd>
|
|
157
|
+
</div>
|
|
158
|
+
<div className="fact">
|
|
159
|
+
<dt>Answer goes to</dt>
|
|
160
|
+
<dd className="mono">{view.redirectHost}</dd>
|
|
161
|
+
</div>
|
|
162
|
+
<div className="fact">
|
|
163
|
+
<dt>For</dt>
|
|
164
|
+
<dd>{view.days} days, or until you disconnect it on your account page</dd>
|
|
165
|
+
</div>
|
|
166
|
+
</dl>
|
|
167
|
+
|
|
168
|
+
<fieldset className="consent-scopes">
|
|
169
|
+
<legend className="label">It may</legend>
|
|
170
|
+
{view.scopes.map((scope) => {
|
|
171
|
+
const { label, description } = MCP_SCOPE_INFO[scope];
|
|
172
|
+
const locked = scope === 'browse';
|
|
173
|
+
return (
|
|
174
|
+
<label key={scope} className="consent-scope">
|
|
175
|
+
<input
|
|
176
|
+
type="checkbox"
|
|
177
|
+
checked={chosen.has(scope)}
|
|
178
|
+
disabled={locked || pending !== null}
|
|
179
|
+
onChange={(event) => toggle(scope, event.target.checked)}
|
|
180
|
+
/>
|
|
181
|
+
<span className="cell-stack">
|
|
182
|
+
<span>
|
|
183
|
+
{label}
|
|
184
|
+
{locked && <span className="hint"> · always</span>}
|
|
185
|
+
</span>
|
|
186
|
+
<small>{description}</small>
|
|
187
|
+
</span>
|
|
188
|
+
</label>
|
|
189
|
+
);
|
|
190
|
+
})}
|
|
191
|
+
</fieldset>
|
|
192
|
+
|
|
193
|
+
<div className="consent-notices">
|
|
194
|
+
{chosen.has('read-values') && (
|
|
195
|
+
<Notice tone="bad">
|
|
196
|
+
Values will be sent to {client.name}. They become part of the conversation: whoever can read
|
|
197
|
+
that conversation, and wherever {client.name} stores it, has them.
|
|
198
|
+
</Notice>
|
|
199
|
+
)}
|
|
200
|
+
{view.loopbackOnly && (
|
|
201
|
+
<Notice tone="warn">
|
|
202
|
+
The answer goes to a program on this computer, <span className="mono">{view.redirectHost}</span>.
|
|
203
|
+
Any program running here could be it: approve only if you just started {client.name} yourself.
|
|
204
|
+
</Notice>
|
|
205
|
+
)}
|
|
206
|
+
{replaced > 0 && (
|
|
207
|
+
<Notice tone="info">
|
|
208
|
+
This replaces your earlier connection{replaced === 1 ? '' : 's'} of {client.name}, with fewer scopes: {replaced === 1 ? 'it ends' : 'they end'} once
|
|
209
|
+
the app has this one.
|
|
210
|
+
</Notice>
|
|
211
|
+
)}
|
|
212
|
+
{kept > 0 && (
|
|
213
|
+
<Notice tone="info">
|
|
214
|
+
You have connected {client.name} {kept === 1 ? 'once' : `${kept} times`} already.
|
|
215
|
+
This adds another connection; your account page lists them.
|
|
216
|
+
</Notice>
|
|
217
|
+
)}
|
|
218
|
+
<ErrorLine error={error} />
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
<div className="device-actions">
|
|
222
|
+
<button className="btn" disabled={pending !== null} onClick={() => void decide(false)}>
|
|
223
|
+
{pending === 'deny' && <Spinner />}
|
|
224
|
+
Deny
|
|
225
|
+
</button>
|
|
226
|
+
<button className="btn btn-primary" disabled={pending !== null} onClick={() => void decide(true)}>
|
|
227
|
+
{pending === 'approve' && <Spinner />}
|
|
228
|
+
Approve
|
|
229
|
+
</button>
|
|
230
|
+
</div>
|
|
231
|
+
</section>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react';
|
|
2
|
+
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { useShell } from '../lib/use-shell';
|
|
4
|
+
import { useCoffre } from '../lib/coffre';
|
|
5
|
+
import { grantAccess, grantId } from '../lib/changes';
|
|
6
|
+
import { queries } from '../lib/queries';
|
|
7
|
+
import { useChange } from '../lib/use-change';
|
|
8
|
+
import type { GrantRow, ProjectSummary } from '../shared/models';
|
|
9
|
+
import { ReferencesInto } from '../components/references';
|
|
10
|
+
import { EmptyState, Modal, Notice } from '../components/ui';
|
|
11
|
+
import { GrantRowView, GrantsTable, RefusedGrants, useRefusedGrants } from '../components/grants';
|
|
12
|
+
import { KIND } from '../components/directory';
|
|
13
|
+
import { PrincipalLink } from '../components/principal';
|
|
14
|
+
import { PrincipalPicker } from '../components/principal-picker';
|
|
15
|
+
import { parseProjectAccess, projectAccessOptions } from '../lib/project-access';
|
|
16
|
+
import { Key, Plus, User } from '../components/icons';
|
|
17
|
+
import { pageRoute } from '../lib/page-route';
|
|
18
|
+
import { useProject } from '../lib/project-page';
|
|
19
|
+
import type { projectServiceAccounts, projectUsers } from '../options';
|
|
20
|
+
|
|
21
|
+
/** A project's users: who holds access, and what others read of it through references. */
|
|
22
|
+
export function ProjectUsersPage() {
|
|
23
|
+
const { project: slug } = pageRoute<typeof projectUsers>().useParams();
|
|
24
|
+
return (
|
|
25
|
+
<ProjectAccess slug={slug} principalType="user">
|
|
26
|
+
<ReferencesInto project={slug} />
|
|
27
|
+
</ProjectAccess>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A project's service accounts: which hold access. */
|
|
32
|
+
export function ProjectServiceAccountsPage() {
|
|
33
|
+
const { project: slug } = pageRoute<typeof projectServiceAccounts>().useParams();
|
|
34
|
+
return <ProjectAccess slug={slug} principalType="service" />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function ProjectAccess({ slug, principalType, children }: { slug: string; principalType: 'user' | 'service'; children?: ReactNode }) {
|
|
38
|
+
const { project } = useProject(slug);
|
|
39
|
+
const { data: result } = useSuspenseQuery(queries.grants(useCoffre(), slug));
|
|
40
|
+
if (!result.ok) return <Notice tone="bad">{result.error}</Notice>;
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<AccessPanel principalType={principalType} project={slug} environments={project.environments} grants={result.grants} />
|
|
44
|
+
{children}
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One kind's grants on the project, and below them the way to add one. */
|
|
50
|
+
function AccessPanel({
|
|
51
|
+
principalType,
|
|
52
|
+
project,
|
|
53
|
+
environments,
|
|
54
|
+
grants: all,
|
|
55
|
+
}: {
|
|
56
|
+
principalType: 'user' | 'service';
|
|
57
|
+
project: string;
|
|
58
|
+
environments: ProjectSummary['environments'];
|
|
59
|
+
/** Every grant on the project: the picker shows what each candidate already holds. */
|
|
60
|
+
grants: GrantRow[];
|
|
61
|
+
}) {
|
|
62
|
+
const people = principalType === 'user';
|
|
63
|
+
const kind = KIND[principalType];
|
|
64
|
+
const grants = all.filter((grant) => grant.principalType === principalType);
|
|
65
|
+
const refused = useRefusedGrants(project, grants, principalType);
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<section className="card" aria-label={people ? 'Users with access' : 'Service accounts with access'}>
|
|
69
|
+
{grants.length === 0 && refused.length === 0 ? (
|
|
70
|
+
<EmptyState title={`No ${kind} has access`}>
|
|
71
|
+
Add a {kind} with permissions on the whole project or on one environment.
|
|
72
|
+
</EmptyState>
|
|
73
|
+
) : (
|
|
74
|
+
<GrantsTable
|
|
75
|
+
lead={
|
|
76
|
+
<span className="th">
|
|
77
|
+
{people ? <User size={14} /> : <Key size={14} />}
|
|
78
|
+
{people ? 'Email' : 'Name'}
|
|
79
|
+
</span>
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
{grants.map((grant, index) => (
|
|
83
|
+
<GrantRowView
|
|
84
|
+
key={grantId(grant)}
|
|
85
|
+
number={index + 1}
|
|
86
|
+
project={project}
|
|
87
|
+
grant={grant}
|
|
88
|
+
leadLabel={people ? 'Email' : 'Name'}
|
|
89
|
+
lead={<PrincipalLink type={grant.principalType} id={grant.principalId} />}
|
|
90
|
+
/>
|
|
91
|
+
))}
|
|
92
|
+
<RefusedGrants refused={refused} />
|
|
93
|
+
</GrantsTable>
|
|
94
|
+
)}
|
|
95
|
+
</section>
|
|
96
|
+
<div className="table-actions">
|
|
97
|
+
<NewGrant
|
|
98
|
+
principalType={principalType}
|
|
99
|
+
project={project}
|
|
100
|
+
environments={environments}
|
|
101
|
+
grants={all}
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function NewGrant({
|
|
109
|
+
principalType,
|
|
110
|
+
project,
|
|
111
|
+
environments,
|
|
112
|
+
grants,
|
|
113
|
+
}: {
|
|
114
|
+
principalType: 'user' | 'service';
|
|
115
|
+
project: string;
|
|
116
|
+
environments: ProjectSummary['environments'];
|
|
117
|
+
grants: GrantRow[];
|
|
118
|
+
}) {
|
|
119
|
+
const { capabilities } = useShell();
|
|
120
|
+
const [open, setOpen] = useState(false);
|
|
121
|
+
const [principalId, setPrincipalId] = useState('');
|
|
122
|
+
const [permission, setPermission] = useState('viewer:');
|
|
123
|
+
const [expiresAt, setExpiresAt] = useState('');
|
|
124
|
+
const grant = useChange(grantAccess(useCoffre(), project));
|
|
125
|
+
const permissionOptions = projectAccessOptions(environments);
|
|
126
|
+
const kind = KIND[principalType];
|
|
127
|
+
|
|
128
|
+
function close() {
|
|
129
|
+
setOpen(false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<button className="btn btn-primary" onClick={() => setOpen(true)}>
|
|
135
|
+
<Plus size={14} />
|
|
136
|
+
Add {kind}
|
|
137
|
+
</button>
|
|
138
|
+
|
|
139
|
+
<Modal
|
|
140
|
+
open={open}
|
|
141
|
+
onOpenChange={(next) => (next ? setOpen(true) : close())}
|
|
142
|
+
title={
|
|
143
|
+
<>
|
|
144
|
+
Give a {kind} access to <span className="mono">{project}</span>
|
|
145
|
+
</>
|
|
146
|
+
}
|
|
147
|
+
wide
|
|
148
|
+
description="Owners manage the whole project and its access. Read and write can cover every environment, or one."
|
|
149
|
+
>
|
|
150
|
+
<form
|
|
151
|
+
className="form"
|
|
152
|
+
onSubmit={(event) => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
const access = parseProjectAccess(permission);
|
|
155
|
+
// Shown in the list at once, marked as saving; the list says if the server refuses.
|
|
156
|
+
grant({
|
|
157
|
+
principalType,
|
|
158
|
+
principalId: principalId.trim(),
|
|
159
|
+
role: access.role,
|
|
160
|
+
roleName: permissionOptions.find((option) => option.value === permission)?.label ?? access.role,
|
|
161
|
+
environmentSlug: access.environmentSlug,
|
|
162
|
+
expiresAt: expiresAt === '' ? null : new Date(`${expiresAt}T23:59:59Z`).toISOString(),
|
|
163
|
+
});
|
|
164
|
+
setPrincipalId('');
|
|
165
|
+
setExpiresAt('');
|
|
166
|
+
setPermission('viewer:');
|
|
167
|
+
close();
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
<PrincipalPicker
|
|
171
|
+
principalType={principalType}
|
|
172
|
+
canList={capabilities.canManageGrants}
|
|
173
|
+
grants={grants}
|
|
174
|
+
value={principalId}
|
|
175
|
+
onChange={setPrincipalId}
|
|
176
|
+
/>
|
|
177
|
+
|
|
178
|
+
<div className="form-row">
|
|
179
|
+
<label className="field" style={{ flexGrow: 2 }}>
|
|
180
|
+
<span className="label">Permissions</span>
|
|
181
|
+
<select
|
|
182
|
+
className="select"
|
|
183
|
+
value={permission}
|
|
184
|
+
onChange={(event) => setPermission(event.target.value)}
|
|
185
|
+
>
|
|
186
|
+
{permissionOptions.map((option) => (
|
|
187
|
+
<option key={option.value} value={option.value}>
|
|
188
|
+
{option.label}
|
|
189
|
+
</option>
|
|
190
|
+
))}
|
|
191
|
+
</select>
|
|
192
|
+
</label>
|
|
193
|
+
|
|
194
|
+
<label className="field">
|
|
195
|
+
<span className="label">
|
|
196
|
+
Expires <span className="hint">(optional)</span>
|
|
197
|
+
</span>
|
|
198
|
+
<input
|
|
199
|
+
className="input"
|
|
200
|
+
type="date"
|
|
201
|
+
value={expiresAt}
|
|
202
|
+
onChange={(event) => setExpiresAt(event.target.value)}
|
|
203
|
+
/>
|
|
204
|
+
</label>
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
<div className="dialog-actions">
|
|
208
|
+
<button className="btn" type="button" onClick={close}>
|
|
209
|
+
Cancel
|
|
210
|
+
</button>
|
|
211
|
+
<button className="btn btn-primary" type="submit" disabled={principalId.trim() === ''}>
|
|
212
|
+
Grant access
|
|
213
|
+
</button>
|
|
214
|
+
</div>
|
|
215
|
+
</form>
|
|
216
|
+
</Modal>
|
|
217
|
+
</>
|
|
218
|
+
);
|
|
219
|
+
}
|