@coffre/ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/client/.assetsignore +2 -0
- package/dist/client/_coffre/assets/account-C3Zo1l5A.js +1 -0
- package/dist/client/_coffre/assets/account-C4bNbeO7.js +2 -0
- package/dist/client/_coffre/assets/affordances-DiuJIiR2.js +1 -0
- package/dist/client/_coffre/assets/audit-1xLyuxGz.js +2 -0
- package/dist/client/_coffre/assets/audit-Dab2GuRj.js +1 -0
- package/dist/client/_coffre/assets/auth.device-BfCfeBWe.js +2 -0
- package/dist/client/_coffre/assets/auth.device-D2pCLF-X.js +1 -0
- package/dist/client/_coffre/assets/coffre-C7qL3HGR.js +1 -0
- package/dist/client/_coffre/assets/directory-C2Ou4SQv.js +1 -0
- package/dist/client/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/client/_coffre/assets/grants-fqTtJ-aW.js +1 -0
- package/dist/client/_coffre/assets/index-BpGwbjmM.js +12 -0
- package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/client/_coffre/assets/login-CR9CBXlw.js +2 -0
- package/dist/client/_coffre/assets/login-DZizFxa4.js +1 -0
- package/dist/client/_coffre/assets/offboarding-DOLJQcXU.js +1 -0
- package/dist/client/_coffre/assets/page-BxW2MwaX.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-BHuP8_FL.js +46 -0
- package/dist/client/_coffre/assets/principal-page-xnBZVURr.js +1 -0
- package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-CrWjQmIA.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-CwRVG9Ne.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-CCDEuE-z.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-DCJsmnD7.js +1 -0
- package/dist/client/_coffre/assets/projects.index-B8eV8JIn.js +1 -0
- package/dist/client/_coffre/assets/projects.index-BNEC7Oz8.js +2 -0
- package/dist/client/_coffre/assets/settings-2BPsenNM.js +2 -0
- package/dist/client/_coffre/assets/settings-BrS0-wEt.js +1 -0
- package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-B3-YwuKp.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-D_hsbHx6.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-BdKE2Jv8.js +2 -0
- package/dist/client/_coffre/assets/tokens.index-XvA4XRxh.js +1 -0
- package/dist/client/_coffre/assets/unregistered-CTRMtBIy.js +1 -0
- package/dist/client/_coffre/assets/use-action-DgAf-tiX.js +1 -0
- package/dist/client/_coffre/assets/users._user-BFPXcJ4y.js +2 -0
- package/dist/client/_coffre/assets/users._user-DEtMeSoh.js +1 -0
- package/dist/client/_coffre/assets/users.index-B03beUHq.js +1 -0
- package/dist/client/_coffre/assets/users.index-D8hwzM6P.js +2 -0
- package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/server/.vite/manifest.json +572 -0
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-B6CZDfrB.js +133 -0
- package/dist/server/_coffre/assets/account-B71_b5xc.js +296 -0
- package/dist/server/_coffre/assets/account-BoO6ZqMc.js +176 -0
- package/dist/server/_coffre/assets/affordances-BNaXjMOb.js +46 -0
- package/dist/server/_coffre/assets/async-local-storage-C0cwgkEr.js +3107 -0
- package/dist/server/_coffre/assets/audit-CwRFnSAY.js +74 -0
- package/dist/server/_coffre/assets/audit-t1sYjtrf.js +964 -0
- package/dist/server/_coffre/assets/auth.device-1IcJ475s.js +208 -0
- package/dist/server/_coffre/assets/auth.device-CJwZYYtn.js +29 -0
- package/dist/server/_coffre/assets/coffre-1hxT2E_U.js +278 -0
- package/dist/server/_coffre/assets/directory-wm_JQUfk.js +396 -0
- package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +5 -0
- package/dist/server/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/server/_coffre/assets/grants-BmhEY1vz.js +243 -0
- package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/server/_coffre/assets/login-B5O5LPXV.js +100 -0
- package/dist/server/_coffre/assets/login-Bvc4gp0X.js +22 -0
- package/dist/server/_coffre/assets/offboarding-CvSilnSm.js +330 -0
- package/dist/server/_coffre/assets/page-BjXk0Ehu.js +2003 -0
- package/dist/server/_coffre/assets/principal-page-DkwNGzM2.js +617 -0
- package/dist/server/_coffre/assets/project-environments-lEzFHUt4.js +9 -0
- package/dist/server/_coffre/assets/projects._project._environment-7grhqlgq.js +2227 -0
- package/dist/server/_coffre/assets/projects._project._environment-ByEf6pmz.js +55 -0
- package/dist/server/_coffre/assets/projects._project.index-B1bjowP-.js +932 -0
- package/dist/server/_coffre/assets/projects._project.index-DU8wtoHD.js +22 -0
- package/dist/server/_coffre/assets/projects.index-B0DoHbCz.js +280 -0
- package/dist/server/_coffre/assets/projects.index-kMDA6pMy.js +54 -0
- package/dist/server/_coffre/assets/react-dom-qCTiwGGR.js +1352 -0
- package/dist/server/_coffre/assets/router-ChU_CwCX.js +2028 -0
- package/dist/server/_coffre/assets/settings-CM9-h7in.js +18 -0
- package/dist/server/_coffre/assets/settings-Cg5qOGij.js +60 -0
- package/dist/server/_coffre/assets/signin-errors-BEFlVDbQ.js +28 -0
- package/dist/server/_coffre/assets/start-DR3rN0St.js +4 -0
- package/dist/server/_coffre/assets/tokens._token-CCpaPMAk.js +268 -0
- package/dist/server/_coffre/assets/tokens._token-Di4OZdAA.js +18 -0
- package/dist/server/_coffre/assets/tokens.index-Do3OHR31.js +34 -0
- package/dist/server/_coffre/assets/tokens.index-tDKq4AFh.js +10 -0
- package/dist/server/_coffre/assets/ui-BNzhIAQP.js +15710 -0
- package/dist/server/_coffre/assets/unregistered-BqaWYFJK.js +51 -0
- package/dist/server/_coffre/assets/use-action-BkJXC5JM.js +953 -0
- package/dist/server/_coffre/assets/useStore-DWGPqzXR.js +892 -0
- package/dist/server/_coffre/assets/users._user-BenYva93.js +15 -0
- package/dist/server/_coffre/assets/users._user-Cp039Va-.js +10 -0
- package/dist/server/_coffre/assets/users.index-BrzG1Ecq.js +10 -0
- package/dist/server/_coffre/assets/users.index-DQ_45DQl.js +34 -0
- package/dist/server/_coffre/assets/validation-BQtqPe2V.js +27 -0
- package/dist/server/index.js +13910 -0
- package/package.json +58 -3
- package/src/components/affordances.ts +80 -0
- package/src/components/agentation.tsx +34 -0
- package/src/components/command-palette.tsx +271 -0
- package/src/components/directory.tsx +448 -0
- package/src/components/grants.tsx +204 -0
- package/src/components/icons.tsx +283 -0
- package/src/components/offboarding.tsx +286 -0
- package/src/components/page.tsx +128 -0
- package/src/components/principal-page.tsx +549 -0
- package/src/components/principal-picker.tsx +168 -0
- package/src/components/principal.tsx +53 -0
- package/src/components/route-states.tsx +60 -0
- package/src/components/service-tokens.tsx +212 -0
- package/src/components/shell.tsx +641 -0
- package/src/components/syncs.tsx +581 -0
- package/src/components/theme.tsx +141 -0
- package/src/components/tile.tsx +22 -0
- package/src/components/ui.tsx +440 -0
- package/src/entry.ts +19 -0
- package/src/lib/access-plan.ts +201 -0
- package/src/lib/audit-sentences.ts +468 -0
- package/src/lib/capabilities.ts +45 -0
- package/src/lib/coffre.ts +57 -0
- package/src/lib/project-access.ts +95 -0
- package/src/lib/project-environments.ts +23 -0
- package/src/lib/reveal.ts +21 -0
- package/src/lib/secret-edit-batch.ts +181 -0
- package/src/lib/signin-errors.ts +33 -0
- package/src/lib/use-action.ts +50 -0
- package/src/lib/validation.ts +27 -0
- package/src/routeTree.gen.ts +367 -0
- package/src/router.tsx +84 -0
- package/src/routes/__root.tsx +192 -0
- package/src/routes/access.tsx +11 -0
- package/src/routes/account.tsx +359 -0
- package/src/routes/audit.tsx +545 -0
- package/src/routes/auth.device.tsx +200 -0
- package/src/routes/index.tsx +15 -0
- package/src/routes/login.tsx +129 -0
- package/src/routes/projects.$project.$environment.tsx +1659 -0
- package/src/routes/projects.$project.index.tsx +917 -0
- package/src/routes/projects.index.tsx +353 -0
- package/src/routes/settings.tsx +72 -0
- package/src/routes/tokens.$token.tsx +35 -0
- package/src/routes/tokens.index.tsx +37 -0
- package/src/routes/unregistered.tsx +59 -0
- package/src/routes/users.$user.tsx +13 -0
- package/src/routes/users.index.tsx +37 -0
- package/src/shared/models.ts +55 -0
- package/src/styles/globals.css +4118 -0
- package/src/types.ts +21 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import type { CoffreClient } from '@coffre/client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Link, useLoaderData, useRouter } from '@tanstack/react-router';
|
|
4
|
+
import { toast } from 'sonner';
|
|
5
|
+
import { memberRef, statusOf, uiResult, useCoffre } from '../lib/coffre';
|
|
6
|
+
import { useAction } from '../lib/use-action';
|
|
7
|
+
import type { UiCapabilities } from '../lib/capabilities';
|
|
8
|
+
import { projectAccessLabel } from '../lib/project-access';
|
|
9
|
+
import {
|
|
10
|
+
accessChanges,
|
|
11
|
+
accessPatch,
|
|
12
|
+
dateFromExpiry,
|
|
13
|
+
environmentAccess,
|
|
14
|
+
expiryFromDate,
|
|
15
|
+
planFromGrants,
|
|
16
|
+
withEnvironment,
|
|
17
|
+
withLevel,
|
|
18
|
+
type AccessChange,
|
|
19
|
+
type AccessPlan,
|
|
20
|
+
} from '../lib/access-plan';
|
|
21
|
+
import type { DirectoryPrincipal, GrantRow, ProjectSummary } from '../shared/models';
|
|
22
|
+
import { ClosedDoor, PageHeader } from './page';
|
|
23
|
+
import { EmptyState, ErrorLine, Modal, Notice, Spinner } from './ui';
|
|
24
|
+
import { GrantRowView, GrantsTable, loadProject } from './grants';
|
|
25
|
+
import { InstanceRole, KIND, PrincipalActions } from './directory';
|
|
26
|
+
import { PrincipalReportCards, RemovedNotice } from './offboarding';
|
|
27
|
+
import { PrincipalAvatar } from './principal';
|
|
28
|
+
import { Tile } from './tile';
|
|
29
|
+
import { Clock, Folder, Key, Pencil, Users, X } from './icons';
|
|
30
|
+
|
|
31
|
+
type PrincipalType = DirectoryPrincipal['principalType'];
|
|
32
|
+
|
|
33
|
+
type ProjectAccess = { project: ProjectSummary; grants: GrantRow[]; grantsError: string | null };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Everything one user's or token's page shows: who it is to the instance and
|
|
37
|
+
* what it has seen (owners only), and its grants on every project where you
|
|
38
|
+
* manage access.
|
|
39
|
+
*
|
|
40
|
+
* There is no "grants of this principal" call, so this asks each project you
|
|
41
|
+
* manage for its grants and keeps this principal's. Projects where you do not
|
|
42
|
+
* hold grant.manage are skipped rather than asked: the refusal would land in
|
|
43
|
+
* the audit log as a denial in your name. The report is only asked for
|
|
44
|
+
* instance owners, for the same reason.
|
|
45
|
+
*/
|
|
46
|
+
export async function loadPrincipalPage(
|
|
47
|
+
client: CoffreClient,
|
|
48
|
+
principalType: PrincipalType,
|
|
49
|
+
principalId: string,
|
|
50
|
+
root: { projects: ProjectSummary[]; capabilities: UiCapabilities } | undefined,
|
|
51
|
+
) {
|
|
52
|
+
const managed = (root?.projects ?? []).filter((project) =>
|
|
53
|
+
project.permissions.includes('grant.manage'),
|
|
54
|
+
);
|
|
55
|
+
const [report, details] = await Promise.all([
|
|
56
|
+
root?.capabilities.canManageGrants
|
|
57
|
+
? uiResult(async () => {
|
|
58
|
+
try {
|
|
59
|
+
return { report: await client.members.get(memberRef(principalType, principalId)) };
|
|
60
|
+
} catch (error) {
|
|
61
|
+
// No such principal is an answer, not a failure.
|
|
62
|
+
if (statusOf(error) === 404) return { report: null };
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
: Promise.resolve(null),
|
|
67
|
+
Promise.all(managed.map((project) => loadProject(client, project.slug))),
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
const access: ProjectAccess[] = details.flatMap((result) =>
|
|
71
|
+
result.ok
|
|
72
|
+
? [
|
|
73
|
+
{
|
|
74
|
+
project: result.project,
|
|
75
|
+
grants: result.grants.filter(
|
|
76
|
+
(grant) =>
|
|
77
|
+
grant.principalType === principalType && grant.principalId === principalId,
|
|
78
|
+
),
|
|
79
|
+
grantsError: result.grantsError,
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
: [],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return { report, access };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function PrincipalPage({
|
|
89
|
+
principalType,
|
|
90
|
+
principalId,
|
|
91
|
+
data,
|
|
92
|
+
}: {
|
|
93
|
+
principalType: PrincipalType;
|
|
94
|
+
principalId: string;
|
|
95
|
+
data: Awaited<ReturnType<typeof loadPrincipalPage>>;
|
|
96
|
+
}) {
|
|
97
|
+
const router = useRouter();
|
|
98
|
+
const { instanceRole } = useLoaderData({ from: '__root__' });
|
|
99
|
+
const { report, access } = data;
|
|
100
|
+
const kind = KIND[principalType];
|
|
101
|
+
const people = principalType === 'user';
|
|
102
|
+
const list = people ? '/users' : '/tokens';
|
|
103
|
+
const found = report?.ok === true ? report.report : null;
|
|
104
|
+
const removed = found?.status === 'removed';
|
|
105
|
+
const entry =
|
|
106
|
+
found !== null && !removed
|
|
107
|
+
? {
|
|
108
|
+
principalType,
|
|
109
|
+
principalId,
|
|
110
|
+
instanceRole: found.instanceRole,
|
|
111
|
+
isRootAdmin: found.isRootAdmin,
|
|
112
|
+
tampered: found.status === 'tampered',
|
|
113
|
+
}
|
|
114
|
+
: undefined;
|
|
115
|
+
|
|
116
|
+
// Owners get a report about anyone ever registered, removed or not, so a
|
|
117
|
+
// miss there means there is no such user. Everyone else only reaches this
|
|
118
|
+
// page through projects they manage.
|
|
119
|
+
const unknown = report?.ok === true && found === null;
|
|
120
|
+
if (unknown || (report === null && access.length === 0)) {
|
|
121
|
+
return (
|
|
122
|
+
<ClosedDoor
|
|
123
|
+
icon={people ? <Users size={18} /> : <Key size={18} />}
|
|
124
|
+
label={<span className="mono">{principalId}</span>}
|
|
125
|
+
title={people ? 'No such user for you' : 'No such token for you'}
|
|
126
|
+
actions={
|
|
127
|
+
<Link className="btn" to={list}>
|
|
128
|
+
All {people ? 'users' : 'tokens'}
|
|
129
|
+
</Link>
|
|
130
|
+
}
|
|
131
|
+
>
|
|
132
|
+
{report === null
|
|
133
|
+
? `A ${kind}'s page lists its access to the projects where you manage access, and you manage none.`
|
|
134
|
+
: `No ${kind} by that name has ever been registered here.`}
|
|
135
|
+
</ClosedDoor>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const rows = access.flatMap(({ project, grants }) =>
|
|
140
|
+
grants.map((grant) => ({ project, grant })),
|
|
141
|
+
);
|
|
142
|
+
const errors = access.filter((entry) => entry.grantsError !== null);
|
|
143
|
+
// Grants to someone removed are refused until they are added back.
|
|
144
|
+
const editable = removed
|
|
145
|
+
? []
|
|
146
|
+
: access.filter(
|
|
147
|
+
({ project, grantsError }) => project.archivedAt === null && grantsError === null,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<>
|
|
152
|
+
<PageHeader
|
|
153
|
+
lead={<PrincipalAvatar type={principalType} id={principalId} size="lg" />}
|
|
154
|
+
title={principalId}
|
|
155
|
+
meta={
|
|
156
|
+
removed ? (
|
|
157
|
+
<span className="tag tag-red">Removed</span>
|
|
158
|
+
) : (
|
|
159
|
+
entry?.principalType === 'user' && <InstanceRole principal={entry} />
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
actions={
|
|
163
|
+
(editable.length > 0 || entry !== undefined) && (
|
|
164
|
+
<>
|
|
165
|
+
{editable.length > 0 && (
|
|
166
|
+
<EditAccess
|
|
167
|
+
principalType={principalType}
|
|
168
|
+
principalId={principalId}
|
|
169
|
+
access={editable}
|
|
170
|
+
/>
|
|
171
|
+
)}
|
|
172
|
+
{entry !== undefined && (
|
|
173
|
+
<PrincipalActions
|
|
174
|
+
principal={entry}
|
|
175
|
+
trigger="btn btn-icon"
|
|
176
|
+
onRemoved={() => router.invalidate()}
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
</>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
/>
|
|
183
|
+
|
|
184
|
+
{report?.ok === false && (
|
|
185
|
+
<div className="report-notice">
|
|
186
|
+
<Notice tone="bad">{report.error}</Notice>
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
{removed && found !== null && <RemovedNotice report={found} />}
|
|
190
|
+
|
|
191
|
+
{/* Removal ends every grant, so there is no access left to show. */}
|
|
192
|
+
{!removed && (
|
|
193
|
+
<>
|
|
194
|
+
<h2 className="section-title">Project access</h2>
|
|
195
|
+
|
|
196
|
+
{errors.map(({ project, grantsError }) => (
|
|
197
|
+
<div key={project.slug} style={{ marginBottom: '0.75rem' }}>
|
|
198
|
+
<Notice tone="bad">
|
|
199
|
+
<span className="mono">{project.slug}</span>: {grantsError}
|
|
200
|
+
</Notice>
|
|
201
|
+
</div>
|
|
202
|
+
))}
|
|
203
|
+
|
|
204
|
+
<section className="card" aria-label="Project access">
|
|
205
|
+
{rows.length === 0 ? (
|
|
206
|
+
<EmptyState title="No project access yet">
|
|
207
|
+
{editable.length > 0
|
|
208
|
+
? `Edit access gives this ${kind} access to several projects at once.`
|
|
209
|
+
: `None of the projects where you manage access has a grant for this ${kind}.`}
|
|
210
|
+
</EmptyState>
|
|
211
|
+
) : (
|
|
212
|
+
<GrantsTable
|
|
213
|
+
lead={
|
|
214
|
+
<span className="th">
|
|
215
|
+
<Folder size={14} />
|
|
216
|
+
Project
|
|
217
|
+
</span>
|
|
218
|
+
}
|
|
219
|
+
>
|
|
220
|
+
{rows.map(({ project, grant }, index) => (
|
|
221
|
+
<GrantRowView
|
|
222
|
+
key={grant.id}
|
|
223
|
+
number={index + 1}
|
|
224
|
+
project={project.slug}
|
|
225
|
+
grant={grant}
|
|
226
|
+
leadLabel="Project"
|
|
227
|
+
lead={
|
|
228
|
+
<span className="cell-project">
|
|
229
|
+
<Tile name={project.slug} />
|
|
230
|
+
<Link
|
|
231
|
+
className="cell-link"
|
|
232
|
+
to="/projects/$project"
|
|
233
|
+
params={{ project: project.slug }}
|
|
234
|
+
search={{ tab: people ? 'users' : 'tokens' }}
|
|
235
|
+
>
|
|
236
|
+
{project.name}
|
|
237
|
+
</Link>
|
|
238
|
+
{project.archivedAt !== null && <span className="tag tag-red">archived</span>}
|
|
239
|
+
</span>
|
|
240
|
+
}
|
|
241
|
+
/>
|
|
242
|
+
))}
|
|
243
|
+
</GrantsTable>
|
|
244
|
+
)}
|
|
245
|
+
</section>
|
|
246
|
+
|
|
247
|
+
{/* A root admin manages every project, so nothing is out of view. */}
|
|
248
|
+
{instanceRole !== 'root-admin' && (
|
|
249
|
+
<p className="hint section-foot">
|
|
250
|
+
Only projects where you manage access are listed.
|
|
251
|
+
</p>
|
|
252
|
+
)}
|
|
253
|
+
</>
|
|
254
|
+
)}
|
|
255
|
+
|
|
256
|
+
{found !== null && <PrincipalReportCards report={found} />}
|
|
257
|
+
</>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* One principal's access to every project you manage, edited in one place.
|
|
263
|
+
*
|
|
264
|
+
* Each project opens set to what the principal holds: a project-wide level,
|
|
265
|
+
* or read or write per environment, each with its own expiry. Saving sends
|
|
266
|
+
* only the difference, every project in one `access.set`: the server applies
|
|
267
|
+
* all of it in one transaction, or none of it.
|
|
268
|
+
*/
|
|
269
|
+
function EditAccess({
|
|
270
|
+
principalType,
|
|
271
|
+
principalId,
|
|
272
|
+
access,
|
|
273
|
+
}: {
|
|
274
|
+
principalType: PrincipalType;
|
|
275
|
+
principalId: string;
|
|
276
|
+
access: ProjectAccess[];
|
|
277
|
+
}) {
|
|
278
|
+
const coffre = useCoffre();
|
|
279
|
+
const [open, setOpen] = useState(false);
|
|
280
|
+
const [edits, setEdits] = useState<Record<string, AccessPlan>>({});
|
|
281
|
+
const { pending, error, setError, run } = useAction();
|
|
282
|
+
const kind = KIND[principalType];
|
|
283
|
+
|
|
284
|
+
const rows = access.map(({ project, grants }) => {
|
|
285
|
+
const environments = project.environments
|
|
286
|
+
.filter(
|
|
287
|
+
(environment) => environment.details !== null && environment.details.archivedAt === null,
|
|
288
|
+
)
|
|
289
|
+
.map((environment) => environment.slug);
|
|
290
|
+
const held = planFromGrants(grants, environments);
|
|
291
|
+
const plan = Object.hasOwn(edits, project.slug) ? edits[project.slug] : held;
|
|
292
|
+
return { project, grants, environments, held, plan, changes: accessChanges(grants, plan) };
|
|
293
|
+
});
|
|
294
|
+
const changed = rows.filter((row) => row.changes.length > 0);
|
|
295
|
+
|
|
296
|
+
function close() {
|
|
297
|
+
setOpen(false);
|
|
298
|
+
setEdits({});
|
|
299
|
+
setError(null);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<>
|
|
304
|
+
<button className="btn btn-primary" onClick={() => setOpen(true)}>
|
|
305
|
+
<Pencil size={14} />
|
|
306
|
+
Edit access
|
|
307
|
+
</button>
|
|
308
|
+
|
|
309
|
+
<Modal
|
|
310
|
+
open={open}
|
|
311
|
+
onOpenChange={(next) => (next ? setOpen(true) : close())}
|
|
312
|
+
title={
|
|
313
|
+
<>
|
|
314
|
+
Edit access for <span className="mono">{principalId}</span>
|
|
315
|
+
</>
|
|
316
|
+
}
|
|
317
|
+
description={`Set what this ${kind} can reach on each project you manage, and until when. Saving applies only what you changed.`}
|
|
318
|
+
wide
|
|
319
|
+
>
|
|
320
|
+
<form
|
|
321
|
+
className="form"
|
|
322
|
+
onSubmit={(event) => {
|
|
323
|
+
event.preventDefault();
|
|
324
|
+
run(
|
|
325
|
+
() =>
|
|
326
|
+
coffre.access.set(
|
|
327
|
+
memberRef(principalType, principalId),
|
|
328
|
+
Object.assign({}, ...changed.map(({ project, changes }) => accessPatch(project.slug, changes))),
|
|
329
|
+
),
|
|
330
|
+
() => {
|
|
331
|
+
toast.success(
|
|
332
|
+
`Updated ${principalId}’s access on ${changed.length} project${changed.length === 1 ? '' : 's'}`,
|
|
333
|
+
);
|
|
334
|
+
close();
|
|
335
|
+
},
|
|
336
|
+
);
|
|
337
|
+
}}
|
|
338
|
+
>
|
|
339
|
+
<ul className="plan-list">
|
|
340
|
+
<li className="plan-head" aria-hidden="true">
|
|
341
|
+
<span>Project</span>
|
|
342
|
+
<span>Access</span>
|
|
343
|
+
<span>Expires</span>
|
|
344
|
+
</li>
|
|
345
|
+
{rows.map(({ project, grants, environments, held, plan, changes }) => {
|
|
346
|
+
const id = `plan-${project.slug}`;
|
|
347
|
+
const edit = (next: AccessPlan) =>
|
|
348
|
+
setEdits((current) => ({ ...current, [project.slug]: next }));
|
|
349
|
+
return (
|
|
350
|
+
<li
|
|
351
|
+
key={project.slug}
|
|
352
|
+
className={`plan-row${changes.length > 0 ? ' is-changed' : ''}`}
|
|
353
|
+
>
|
|
354
|
+
<label className="plan-project" htmlFor={id}>
|
|
355
|
+
<Tile name={project.slug} />
|
|
356
|
+
<span className="plan-project-text">
|
|
357
|
+
<span className="plan-project-name">{project.name}</span>
|
|
358
|
+
{held.level === 'custom' && (
|
|
359
|
+
<span className="plan-project-held">
|
|
360
|
+
Holds {grants.map((grant) => projectAccessLabel(grant)).join(', ')}
|
|
361
|
+
</span>
|
|
362
|
+
)}
|
|
363
|
+
</span>
|
|
364
|
+
</label>
|
|
365
|
+
<select
|
|
366
|
+
id={id}
|
|
367
|
+
className="select select-sm"
|
|
368
|
+
value={plan.level}
|
|
369
|
+
onChange={(event) =>
|
|
370
|
+
edit(
|
|
371
|
+
withLevel(plan, event.target.value as AccessPlan['level'], environments),
|
|
372
|
+
)
|
|
373
|
+
}
|
|
374
|
+
>
|
|
375
|
+
{held.level === 'custom' && <option value="custom">Keep as is</option>}
|
|
376
|
+
<option value="none">No access</option>
|
|
377
|
+
<option value="owner">Owner</option>
|
|
378
|
+
<option value="viewer">Read: all</option>
|
|
379
|
+
<option value="developer">Write: all</option>
|
|
380
|
+
{environments.length > 0 && <option value="env">Per environment…</option>}
|
|
381
|
+
</select>
|
|
382
|
+
{(plan.level === 'owner' ||
|
|
383
|
+
plan.level === 'viewer' ||
|
|
384
|
+
plan.level === 'developer') && (
|
|
385
|
+
<ExpiryField
|
|
386
|
+
label={`${project.name} expires`}
|
|
387
|
+
expiresAt={plan.expiresAt}
|
|
388
|
+
onChange={(expiresAt) => edit({ ...plan, expiresAt })}
|
|
389
|
+
/>
|
|
390
|
+
)}
|
|
391
|
+
|
|
392
|
+
{plan.level === 'env' && (
|
|
393
|
+
<ul className="plan-envs" aria-label={`Environments of ${project.name}`}>
|
|
394
|
+
{environments.map((slug) => {
|
|
395
|
+
const current = environmentAccess(plan, slug);
|
|
396
|
+
return (
|
|
397
|
+
<li key={slug} className="plan-env">
|
|
398
|
+
<label className="mono" htmlFor={`${id}-${slug}`}>
|
|
399
|
+
{slug}
|
|
400
|
+
</label>
|
|
401
|
+
<select
|
|
402
|
+
id={`${id}-${slug}`}
|
|
403
|
+
className="select select-sm"
|
|
404
|
+
value={current?.role ?? ''}
|
|
405
|
+
onChange={(event) => {
|
|
406
|
+
const role = event.target.value;
|
|
407
|
+
edit(
|
|
408
|
+
withEnvironment(
|
|
409
|
+
plan,
|
|
410
|
+
slug,
|
|
411
|
+
role === 'viewer' || role === 'developer'
|
|
412
|
+
? { role, expiresAt: current?.expiresAt ?? null }
|
|
413
|
+
: null,
|
|
414
|
+
),
|
|
415
|
+
);
|
|
416
|
+
}}
|
|
417
|
+
>
|
|
418
|
+
<option value="">No access</option>
|
|
419
|
+
<option value="viewer">Read</option>
|
|
420
|
+
<option value="developer">Write</option>
|
|
421
|
+
</select>
|
|
422
|
+
{current !== null && (
|
|
423
|
+
<ExpiryField
|
|
424
|
+
label={`${slug} of ${project.name} expires`}
|
|
425
|
+
expiresAt={current.expiresAt}
|
|
426
|
+
onChange={(expiresAt) =>
|
|
427
|
+
edit(withEnvironment(plan, slug, { ...current, expiresAt }))
|
|
428
|
+
}
|
|
429
|
+
/>
|
|
430
|
+
)}
|
|
431
|
+
</li>
|
|
432
|
+
);
|
|
433
|
+
})}
|
|
434
|
+
</ul>
|
|
435
|
+
)}
|
|
436
|
+
|
|
437
|
+
{changes.length > 0 && (
|
|
438
|
+
<ul className="plan-changes" aria-label={`Changes to ${project.name}`}>
|
|
439
|
+
{changes.map((change) => (
|
|
440
|
+
<li
|
|
441
|
+
key={
|
|
442
|
+
change.kind === 'create'
|
|
443
|
+
? `+${change.role}@${change.environmentSlug ?? ''}`
|
|
444
|
+
: change.grant.id
|
|
445
|
+
}
|
|
446
|
+
>
|
|
447
|
+
<AccessChangeTag change={change} />
|
|
448
|
+
</li>
|
|
449
|
+
))}
|
|
450
|
+
</ul>
|
|
451
|
+
)}
|
|
452
|
+
</li>
|
|
453
|
+
);
|
|
454
|
+
})}
|
|
455
|
+
</ul>
|
|
456
|
+
|
|
457
|
+
<ErrorLine error={error} />
|
|
458
|
+
|
|
459
|
+
<div className="dialog-actions">
|
|
460
|
+
<button className="btn" type="button" onClick={close}>
|
|
461
|
+
Cancel
|
|
462
|
+
</button>
|
|
463
|
+
<button
|
|
464
|
+
className="btn btn-primary"
|
|
465
|
+
type="submit"
|
|
466
|
+
disabled={pending || changed.length === 0}
|
|
467
|
+
>
|
|
468
|
+
{pending && <Spinner />}
|
|
469
|
+
Save changes
|
|
470
|
+
</button>
|
|
471
|
+
</div>
|
|
472
|
+
</form>
|
|
473
|
+
</Modal>
|
|
474
|
+
</>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* When one grant ends, as a date: access lasts through that day, UTC. Blank
|
|
480
|
+
* reads "Never" where the browser lets the empty field be restyled.
|
|
481
|
+
*/
|
|
482
|
+
function ExpiryField({
|
|
483
|
+
label,
|
|
484
|
+
expiresAt,
|
|
485
|
+
onChange,
|
|
486
|
+
}: {
|
|
487
|
+
label: string;
|
|
488
|
+
expiresAt: string | null;
|
|
489
|
+
onChange: (expiresAt: string | null) => void;
|
|
490
|
+
}) {
|
|
491
|
+
const date = dateFromExpiry(expiresAt);
|
|
492
|
+
return (
|
|
493
|
+
<span className={`expiry${date === '' ? ' is-never' : ''}`}>
|
|
494
|
+
<input
|
|
495
|
+
className="input select-sm"
|
|
496
|
+
type="date"
|
|
497
|
+
aria-label={label}
|
|
498
|
+
min={new Date().toISOString().slice(0, 10)}
|
|
499
|
+
value={date}
|
|
500
|
+
onChange={(event) => onChange(expiryFromDate(event.target.value))}
|
|
501
|
+
/>
|
|
502
|
+
<span className="expiry-never" aria-hidden="true">
|
|
503
|
+
Never
|
|
504
|
+
</span>
|
|
505
|
+
<button
|
|
506
|
+
className="btn btn-quiet btn-sm btn-icon"
|
|
507
|
+
type="button"
|
|
508
|
+
aria-label={`${label}: never`}
|
|
509
|
+
title="Never expires"
|
|
510
|
+
onClick={() => onChange(null)}
|
|
511
|
+
>
|
|
512
|
+
<X size={12} />
|
|
513
|
+
</button>
|
|
514
|
+
</span>
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function AccessChangeTag({ change }: { change: AccessChange }) {
|
|
519
|
+
const until = (expiresAt: string | null) =>
|
|
520
|
+
expiresAt === null ? '' : ` until ${dateFromExpiry(expiresAt)}`;
|
|
521
|
+
switch (change.kind) {
|
|
522
|
+
case 'create':
|
|
523
|
+
return (
|
|
524
|
+
<span className="tag tag-green">
|
|
525
|
+
<span aria-hidden="true">+</span>
|
|
526
|
+
<span className="visually-hidden">Adds</span>
|
|
527
|
+
{projectAccessLabel({ ...change, roleName: change.role })}
|
|
528
|
+
{until(change.expiresAt)}
|
|
529
|
+
</span>
|
|
530
|
+
);
|
|
531
|
+
case 'expiry':
|
|
532
|
+
return (
|
|
533
|
+
<span className="tag tag-blue">
|
|
534
|
+
<Clock size={12} />
|
|
535
|
+
<span className="visually-hidden">Moves the expiry of</span>
|
|
536
|
+
{projectAccessLabel(change.grant)}
|
|
537
|
+
{change.expiresAt === null ? ', no expiry' : until(change.expiresAt)}
|
|
538
|
+
</span>
|
|
539
|
+
);
|
|
540
|
+
case 'revoke':
|
|
541
|
+
return (
|
|
542
|
+
<span className="tag tag-red">
|
|
543
|
+
<span aria-hidden="true">−</span>
|
|
544
|
+
<span className="visually-hidden">Removes</span>
|
|
545
|
+
{projectAccessLabel(change.grant)}
|
|
546
|
+
</span>
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
}
|