@coffre/ui 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{affordances-DAvsVz7u.js → affordances-Bqdevf7w.js} +10 -5
- package/dist/chunks/affordances-Bqdevf7w.js.map +1 -0
- package/dist/chunks/{audit-sentence-DIztXvbU.js → audit-sentence-Cm5nby5k.js} +105 -7
- package/dist/chunks/audit-sentence-Cm5nby5k.js.map +1 -0
- package/dist/chunks/{connected-apps-AZsX9Zvv.js → connected-apps-DTNS7YmY.js} +2 -2
- package/dist/chunks/{connected-apps-AZsX9Zvv.js.map → connected-apps-DTNS7YmY.js.map} +1 -1
- package/dist/chunks/{delete-place-D6LIZkg9.js → delete-place-CIaOq0mt.js} +3 -3
- package/dist/chunks/{delete-place-D6LIZkg9.js.map → delete-place-CIaOq0mt.js.map} +1 -1
- package/dist/chunks/{directory-B6FuiCir.js → directory-DSVt5Tya.js} +54 -60
- package/dist/chunks/directory-DSVt5Tya.js.map +1 -0
- package/dist/chunks/{folders-DvSqBhuu.js → folders-CoGK9oqg.js} +2 -2
- package/dist/chunks/{folders-DvSqBhuu.js.map → folders-CoGK9oqg.js.map} +1 -1
- package/dist/chunks/grants-CRU7yZhL.js +164 -0
- package/dist/chunks/grants-CRU7yZhL.js.map +1 -0
- package/dist/chunks/{offboarding-CLJaNTcD.js → offboarding-DVBSiJRZ.js} +7 -3
- package/dist/chunks/offboarding-DVBSiJRZ.js.map +1 -0
- package/dist/chunks/{principal-page-1yMztIcc.js → principal-page-BEBr_zW7.js} +350 -91
- package/dist/chunks/principal-page-BEBr_zW7.js.map +1 -0
- package/dist/chunks/{project-page-C4cEaRFa.js → project-page-B3TZ5_ig.js} +2 -2
- package/dist/chunks/{project-page-C4cEaRFa.js.map → project-page-B3TZ5_ig.js.map} +1 -1
- package/dist/chunks/{queries-Dew8mIeo.js → queries-DE5nK2y4.js} +132 -54
- package/dist/chunks/queries-DE5nK2y4.js.map +1 -0
- package/dist/chunks/{references-DWDnXNoW.js → references-uv4Mli9z.js} +4 -3
- package/dist/chunks/{references-DWDnXNoW.js.map → references-uv4Mli9z.js.map} +1 -1
- package/dist/chunks/role-field-DWhkRY6n.js +192 -0
- package/dist/chunks/role-field-DWhkRY6n.js.map +1 -0
- package/dist/chunks/use-action-BRgvbUWt.js +49 -0
- package/dist/chunks/use-action-BRgvbUWt.js.map +1 -0
- package/dist/chunks/{use-change-C4bGRhHY.js → use-change-BJ3dCFHb.js} +40 -14
- package/dist/chunks/use-change-BJ3dCFHb.js.map +1 -0
- package/dist/chunks/{use-shell-Dkv89nW1.js → use-shell-BO4ZTr1y.js} +2 -2
- package/dist/chunks/{use-shell-Dkv89nW1.js.map → use-shell-BO4ZTr1y.js.map} +1 -1
- package/dist/chunks/validation-DiHIwZRA.js +37 -0
- package/dist/chunks/validation-DiHIwZRA.js.map +1 -0
- package/dist/index.d.ts +111 -88
- package/dist/index.js +40 -21
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +8 -7
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/audit.js +2 -2
- package/dist/pages/environment.js +8 -7
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +2 -2
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/project-access.js +7 -7
- package/dist/pages/project-environments.js +26 -21
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.js +9 -8
- package/dist/pages/project-settings.js.map +1 -1
- package/dist/pages/project.js +1 -1
- package/dist/pages/projects.js +8 -13
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.js +294 -88
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +7 -7
- package/dist/pages/service-accounts.js.map +1 -1
- package/dist/pages/settings.js +91 -9
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.d.ts +1 -1
- package/dist/pages/unregistered.js +4 -4
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +2 -0
- package/dist/pages/user.js +21 -3
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +4 -4
- package/package.json +3 -3
- package/src/components/affordances.ts +7 -3
- package/src/components/command-palette.tsx +2 -0
- package/src/components/directory.tsx +58 -63
- package/src/components/grants.tsx +9 -9
- package/src/components/offboarding.tsx +3 -1
- package/src/components/principal-page.tsx +124 -74
- package/src/components/role-field.tsx +183 -0
- package/src/components/scope-picker.tsx +73 -0
- package/src/components/service-tokens.tsx +20 -9
- package/src/components/shell.tsx +6 -10
- package/src/components/trusted-workloads.tsx +121 -42
- package/src/index.ts +1 -0
- package/src/lib/audit-sentences.ts +104 -3
- package/src/lib/bindings.ts +33 -10
- package/src/lib/capabilities.ts +28 -8
- package/src/lib/changes.ts +22 -13
- package/src/lib/project-access.ts +21 -0
- package/src/lib/queries.ts +121 -44
- package/src/lib/service-setup.ts +41 -0
- package/src/lib/validation.ts +7 -0
- package/src/options.ts +31 -11
- package/src/pages/account.tsx +3 -2
- package/src/pages/login.tsx +1 -1
- package/src/pages/project-environments.tsx +12 -15
- package/src/pages/project-settings.tsx +3 -3
- package/src/pages/projects.tsx +1 -5
- package/src/pages/service-account.tsx +7 -5
- package/src/pages/service-accounts.tsx +8 -4
- package/src/pages/settings.tsx +80 -4
- package/src/pages/unregistered.tsx +3 -3
- package/src/pages/user.tsx +24 -1
- package/src/parity.ts +5 -1
- package/src/register.ts +3 -1
- package/src/shared/models.ts +8 -4
- package/src/styles/globals.css +100 -27
- package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
- package/dist/chunks/audit-sentence-DIztXvbU.js.map +0 -1
- package/dist/chunks/directory-B6FuiCir.js.map +0 -1
- package/dist/chunks/grants-9kIV6uZ7.js +0 -669
- package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
- package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
- package/dist/chunks/principal-page-1yMztIcc.js.map +0 -1
- package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
- package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
- package/dist/chunks/validation-DvPinn8V.js +0 -87
- package/dist/chunks/validation-DvPinn8V.js.map +0 -1
- package/src/components/every-project.tsx +0 -287
package/src/lib/bindings.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BindingPlan, BindingView } from '@coffre/client';
|
|
2
|
-
import { fullRef, githubReusable, githubWorkflow, gitlabProject, type BindingClaims } from '@coffre/core/workloads';
|
|
2
|
+
import { claimValues, fullRef, githubReusable, githubWorkflow, gitlabProject, type BindingClaims } from '@coffre/core/workloads';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Trust bindings as the pages show and make them. A binding is its claims;
|
|
@@ -9,24 +9,43 @@ import { fullRef, githubReusable, githubWorkflow, gitlabProject, type BindingCla
|
|
|
9
9
|
|
|
10
10
|
/** A binding in a line: what it trusts, and at which ref. */
|
|
11
11
|
export function summary(binding: Pick<BindingView, 'profile' | 'issuer' | 'claims'>): { title: string; detail: string } {
|
|
12
|
-
|
|
12
|
+
// Every claim is one value, but what started the run, which may be several.
|
|
13
|
+
const claims = binding.claims as Record<string, string | undefined>;
|
|
14
|
+
const events = claimValues(binding.claims.event_name).join(', ');
|
|
13
15
|
const short = (ref: string | undefined) => ref?.replace(/^refs\/(heads|tags)\//, '') ?? '';
|
|
14
16
|
const [workflow, at] = (claims.workflow_ref ?? '').split('@');
|
|
15
17
|
if (binding.profile === 'github') {
|
|
16
18
|
const [owner, repository, , , file] = (workflow ?? '').split('/');
|
|
17
|
-
return { title: `${owner}/${repository} · ${file}`, detail: `${
|
|
19
|
+
return { title: `${owner}/${repository} · ${file}`, detail: `${events} at ${short(at)}` };
|
|
18
20
|
}
|
|
19
21
|
if (binding.profile.startsWith('github-reusable')) {
|
|
20
22
|
const called = (claims.job_workflow_ref ?? '').split('@')[0]!.replace('/.github/workflows/', ' · ');
|
|
21
23
|
const from = binding.profile === 'github-reusable-organization' ? 'any repository of the organization' : `repository ${claims.repository_id}`;
|
|
22
|
-
return { title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`, detail: `${
|
|
24
|
+
return { title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`, detail: `${events} at ${short(claims.ref)}, from ${from}` };
|
|
23
25
|
}
|
|
24
26
|
if (binding.profile === 'gitlab') {
|
|
25
|
-
return { title: `GitLab project ${claims.project_id}`, detail: `${claims.pipeline_source} at ${claims.ref_type} ${claims.ref}` };
|
|
27
|
+
return { title: `GitLab project ${claims.project_id}`, detail: `${claimValues(binding.claims.pipeline_source).join(', ')} at ${claims.ref_type} ${claims.ref}` };
|
|
26
28
|
}
|
|
27
29
|
return { title: new URL(binding.issuer).host, detail: `sub ${claims.sub}` };
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* What a new binding reaches, in the Trust dialog: what the person chose in
|
|
34
|
+
* the picker, or until they do, what the server makes it, which the request
|
|
35
|
+
* leaves out: what the bindings it replaces reached, or all the account
|
|
36
|
+
* holds. Once a plan says it, the picker shows it.
|
|
37
|
+
*/
|
|
38
|
+
export type ScopeChoice = { scope: BindingPlan['scope']; chosen: boolean };
|
|
39
|
+
|
|
40
|
+
/** The scope the dialog asks for: the person's, or none, for the server's own. */
|
|
41
|
+
export function askedScope(choice: ScopeChoice): { scope?: BindingPlan['scope'] } {
|
|
42
|
+
return choice.chosen ? { scope: choice.scope } : {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The picker once a plan came back: what the server would make, unless the person chose. */
|
|
46
|
+
export function planned(choice: ScopeChoice, plan: Pick<BindingPlan, 'scope'>): ScopeChoice {
|
|
47
|
+
return choice.chosen ? choice : { scope: plan.scope, chosen: false };
|
|
48
|
+
}
|
|
30
49
|
|
|
31
50
|
export type Platform = 'github' | 'gitlab' | 'other';
|
|
32
51
|
export type RefKind = 'branch' | 'tag';
|
|
@@ -40,7 +59,7 @@ export const EMPTY_FORM = {
|
|
|
40
59
|
repositoryId: '',
|
|
41
60
|
ownerId: '',
|
|
42
61
|
workflow: '',
|
|
43
|
-
|
|
62
|
+
events: ['push'] as string[],
|
|
44
63
|
refKind: 'branch' as RefKind,
|
|
45
64
|
refName: 'main',
|
|
46
65
|
called: '',
|
|
@@ -51,7 +70,7 @@ export const EMPTY_FORM = {
|
|
|
51
70
|
project: '',
|
|
52
71
|
projectId: '',
|
|
53
72
|
namespaceId: '',
|
|
54
|
-
|
|
73
|
+
sources: ['push'] as string[],
|
|
55
74
|
// Any other issuer
|
|
56
75
|
issuer: '',
|
|
57
76
|
sub: '',
|
|
@@ -66,6 +85,10 @@ export function bindingOf(form: Form): { profile: BindingPlan['profile']; issuer
|
|
|
66
85
|
if (value.trim() === '') throw new Error(`${what} is needed`);
|
|
67
86
|
return value.trim();
|
|
68
87
|
};
|
|
88
|
+
const some = (values: string[], what: string) => {
|
|
89
|
+
if (values.length === 0) throw new Error(`Choose at least one ${what}`);
|
|
90
|
+
return values;
|
|
91
|
+
};
|
|
69
92
|
if (form.platform === 'github') {
|
|
70
93
|
const ref = fullRef(form.refKind, needed(form.refName, form.refKind === 'branch' ? 'The branch' : 'The tag'));
|
|
71
94
|
if (form.reusable) {
|
|
@@ -74,7 +97,7 @@ export function bindingOf(form: Form): { profile: BindingPlan['profile']; issuer
|
|
|
74
97
|
const ownerId = needed(form.ownerId, "The owner's ID");
|
|
75
98
|
const caller = form.workflow.trim() === '' ? undefined : { repository: needed(form.repository, 'The repository'), workflow: form.workflow.trim() };
|
|
76
99
|
const repositoryId = form.anyRepository ? null : needed(form.repositoryId, "The repository's ID");
|
|
77
|
-
return { ...githubReusable({ repositoryId, ownerId, ref,
|
|
100
|
+
return { ...githubReusable({ repositoryId, ownerId, ref, events: some(form.events, 'event'), called, sha, caller }), issuer: null };
|
|
78
101
|
}
|
|
79
102
|
return {
|
|
80
103
|
...githubWorkflow({
|
|
@@ -83,7 +106,7 @@ export function bindingOf(form: Form): { profile: BindingPlan['profile']; issuer
|
|
|
83
106
|
ownerId: needed(form.ownerId, "The owner's ID"),
|
|
84
107
|
workflow: needed(form.workflow, 'The workflow file'),
|
|
85
108
|
ref,
|
|
86
|
-
|
|
109
|
+
events: some(form.events, 'event'),
|
|
87
110
|
}),
|
|
88
111
|
issuer: null,
|
|
89
112
|
};
|
|
@@ -95,7 +118,7 @@ export function bindingOf(form: Form): { profile: BindingPlan['profile']; issuer
|
|
|
95
118
|
projectId: needed(form.projectId, "The project's ID"),
|
|
96
119
|
refType: form.refKind,
|
|
97
120
|
ref: needed(form.refName, form.refKind === 'branch' ? 'The branch' : 'The tag'),
|
|
98
|
-
|
|
121
|
+
sources: some(form.sources, 'pipeline source'),
|
|
99
122
|
}),
|
|
100
123
|
issuer: form.gitlabUrl.trim() === '' ? null : form.gitlabUrl.trim(),
|
|
101
124
|
};
|
package/src/lib/capabilities.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { administers, makesProjects, type InstanceRole } from '@coffre/core/access';
|
|
2
|
+
|
|
1
3
|
import type { Me, Permission, ProjectSummary } from '../shared/models';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -8,13 +10,28 @@ import type { Me, Permission, ProjectSummary } from '../shared/models';
|
|
|
8
10
|
* live outside one resource page.
|
|
9
11
|
*/
|
|
10
12
|
export type UiCapabilities = {
|
|
13
|
+
/** Admins and owners, scoped or not, and root admins: the Users and Service accounts pages. */
|
|
11
14
|
canManageGrants: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Admins and owners whose scope narrows nothing, and root admins: adding
|
|
17
|
+
* and removing people and service accounts, instance roles, tokens and
|
|
18
|
+
* trust bindings, offboarding reports, the instance's keys.
|
|
19
|
+
*/
|
|
20
|
+
runsInstance: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Who sets up service accounts: those who run the instance, and a person
|
|
23
|
+
* who holds access somewhere the instance's setting takes in. The Service
|
|
24
|
+
* accounts page lists them the ones they manage.
|
|
25
|
+
*/
|
|
26
|
+
setsUpServices: boolean;
|
|
12
27
|
canReadAudit: boolean;
|
|
13
28
|
canCreateProject: boolean;
|
|
14
29
|
};
|
|
15
30
|
|
|
16
31
|
const NONE: UiCapabilities = {
|
|
17
32
|
canManageGrants: false,
|
|
33
|
+
runsInstance: false,
|
|
34
|
+
setsUpServices: false,
|
|
18
35
|
canReadAudit: false,
|
|
19
36
|
canCreateProject: false,
|
|
20
37
|
};
|
|
@@ -25,17 +42,20 @@ export function deriveUiCapabilities(
|
|
|
25
42
|
): UiCapabilities {
|
|
26
43
|
if (me === null) return NONE;
|
|
27
44
|
|
|
28
|
-
const
|
|
29
|
-
|
|
45
|
+
const isRootAdmin = me.instanceRole === 'root-admin';
|
|
46
|
+
const role: InstanceRole = me.instanceRole === 'root-admin' ? 'owner' : me.instanceRole;
|
|
30
47
|
|
|
31
48
|
return {
|
|
32
|
-
// Users and
|
|
33
|
-
// Project access managers keep their
|
|
34
|
-
|
|
49
|
+
// Users and Service accounts list the instance's directory, for those
|
|
50
|
+
// who manage access across projects. Project access managers keep their
|
|
51
|
+
// grant controls on each project page.
|
|
52
|
+
canManageGrants: isRootAdmin || administers(role),
|
|
53
|
+
runsInstance: me.runsInstance,
|
|
54
|
+
setsUpServices: me.setsUpServices,
|
|
35
55
|
canReadAudit: me.canReadAudit,
|
|
36
|
-
//
|
|
37
|
-
// the
|
|
38
|
-
canCreateProject:
|
|
56
|
+
// A new project is one no `only` list names: as the server decides,
|
|
57
|
+
// from the role and the scope, projects by slug.
|
|
58
|
+
canCreateProject: makesProjects({ isRootAdmin, role, scope: me.scope, grants: [] }),
|
|
39
59
|
};
|
|
40
60
|
}
|
|
41
61
|
|
package/src/lib/changes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CoffreClient, ConnectedApp, IdentityRow, OffboardingReport, SecretKey, SessionRow } from '@coffre/client';
|
|
2
|
-
import type
|
|
2
|
+
import { EVERYWHERE, unscoped, type InstanceRole, type Role, type Scope } from '@coffre/core/access';
|
|
3
3
|
import type { QueryKey } from '@tanstack/react-query';
|
|
4
4
|
|
|
5
5
|
import { failureMessage, memberRef, Refusal } from './coffre.ts';
|
|
@@ -42,10 +42,10 @@ const removing = (id: string): Target => ({ id, kind: 'removing' });
|
|
|
42
42
|
|
|
43
43
|
type Grants = ({ ok: true; grants: GrantRow[] } | Failure);
|
|
44
44
|
|
|
45
|
-
/** A grant's identity, before the server has given it an id: who, and where. */
|
|
45
|
+
/** A grant's identity, before the server has given it an id: who, and where; or who, by their instance role. */
|
|
46
46
|
export function grantId(grant: Pick<GrantRow, 'principalType' | 'principalId' | 'environmentSlug'> & { scope?: GrantRow['scope'] }): string {
|
|
47
|
-
const
|
|
48
|
-
return
|
|
47
|
+
const member = memberRef(grant.principalType, grant.principalId);
|
|
48
|
+
return grant.scope === 'instance-role' ? `${member}#role` : `${member}@${grant.environmentSlug ?? ''}`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function grantsList(project: string) {
|
|
@@ -127,10 +127,18 @@ type Directory = ({ ok: true; principals: DirectoryPrincipal[] } | Failure);
|
|
|
127
127
|
const principalId = (principal: Pick<DirectoryPrincipal, 'principalType' | 'principalId'>) =>
|
|
128
128
|
memberRef(principal.principalType, principal.principalId);
|
|
129
129
|
|
|
130
|
-
/** The directory as owners read it: the only ones who change it. */
|
|
130
|
+
/** The directory as admins and owners read it: the only ones who change it. */
|
|
131
131
|
export const directoryList = listOf<DirectoryPrincipal, Directory>([...keys.directory, { owner: true }], 'principals', principalId);
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
/** A person's instance role and where it applies, projects by slug: what Add and Change role set. */
|
|
134
|
+
export type RoleVars = { role: InstanceRole; scope: Scope };
|
|
135
|
+
|
|
136
|
+
export type InviteVars = { principalType: DirectoryPrincipal['principalType']; principalId: string } & RoleVars;
|
|
137
|
+
|
|
138
|
+
/** What the API takes for a role: the scope only when it narrows anything. */
|
|
139
|
+
function roleInput({ role, scope }: RoleVars): RoleVars | { role: InstanceRole } {
|
|
140
|
+
return role === 'member' || unscoped(scope) ? { role } : { role, scope };
|
|
141
|
+
}
|
|
134
142
|
|
|
135
143
|
export function invite(client: CoffreClient): Change<Directory, DirectoryPrincipal, InviteVars, void> {
|
|
136
144
|
return {
|
|
@@ -144,7 +152,8 @@ export function invite(client: CoffreClient): Change<Directory, DirectoryPrincip
|
|
|
144
152
|
{
|
|
145
153
|
principalType: vars.principalType,
|
|
146
154
|
principalId: vars.principalId,
|
|
147
|
-
instanceRole: vars.
|
|
155
|
+
instanceRole: vars.principalType === 'user' ? vars.role : 'member',
|
|
156
|
+
scope: vars.principalType === 'user' ? vars.scope : EVERYWHERE,
|
|
148
157
|
isRootAdmin: false,
|
|
149
158
|
},
|
|
150
159
|
],
|
|
@@ -155,12 +164,12 @@ export function invite(client: CoffreClient): Change<Directory, DirectoryPrincip
|
|
|
155
164
|
const member = memberRef(vars.principalType, vars.principalId);
|
|
156
165
|
const { members } = await client.members.list();
|
|
157
166
|
if (members.some((entry) => entry.member === member)) throw new Refusal('That principal already exists.');
|
|
158
|
-
await client.members.add(member,
|
|
167
|
+
await client.members.add(member, vars.principalType === 'user' ? roleInput(vars) : {});
|
|
159
168
|
},
|
|
160
169
|
};
|
|
161
170
|
}
|
|
162
171
|
|
|
163
|
-
export function changeRole(client: CoffreClient): Change<Directory, DirectoryPrincipal, { principalId: string
|
|
172
|
+
export function changeRole(client: CoffreClient): Change<Directory, DirectoryPrincipal, { principalId: string } & RoleVars, unknown> {
|
|
164
173
|
const id = (vars: { principalId: string }) => memberRef('user', vars.principalId);
|
|
165
174
|
return {
|
|
166
175
|
list: directoryList,
|
|
@@ -168,10 +177,10 @@ export function changeRole(client: CoffreClient): Change<Directory, DirectoryPri
|
|
|
168
177
|
targets: (vars) => [saving(id(vars))],
|
|
169
178
|
apply: (principals, vars) =>
|
|
170
179
|
principals.map((principal) =>
|
|
171
|
-
principalId(principal) === id(vars) ? { ...principal, instanceRole: vars.
|
|
180
|
+
principalId(principal) === id(vars) ? { ...principal, instanceRole: vars.role, scope: vars.scope } : principal,
|
|
172
181
|
),
|
|
173
182
|
affects: (vars) => affects.role(id(vars)),
|
|
174
|
-
run: (vars) => client.members.add(id(vars),
|
|
183
|
+
run: (vars) => client.members.add(id(vars), roleInput(vars)),
|
|
175
184
|
};
|
|
176
185
|
}
|
|
177
186
|
|
|
@@ -295,8 +304,8 @@ export function createProject(client: CoffreClient): Change<Projects, ProjectSum
|
|
|
295
304
|
name: vars.name,
|
|
296
305
|
archivedAt: null,
|
|
297
306
|
folder: null,
|
|
298
|
-
//
|
|
299
|
-
permissions: ['
|
|
307
|
+
// Its maker manages it by their instance role, an Admin's or an Owner's.
|
|
308
|
+
permissions: ['audit.read', 'environment.manage', 'grant.manage', 'project.manage'],
|
|
300
309
|
environments: [],
|
|
301
310
|
secretCount: null,
|
|
302
311
|
},
|
|
@@ -81,3 +81,24 @@ export function projectAccessRoles(
|
|
|
81
81
|
if (currentRole) allowed.add(currentRole);
|
|
82
82
|
return roles.filter((role) => allowed.has(role.slug));
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
/** A project on someone's Access tab: their grants there, or why those could not be read. */
|
|
86
|
+
export type ProjectAccess = { project: ProjectSummary; grants: GrantRow[]; grantsError: string | null };
|
|
87
|
+
|
|
88
|
+
/** A row of the Access tab: one of their grants, or a project whose grants could not be read. */
|
|
89
|
+
export type AccessRow =
|
|
90
|
+
| { project: ProjectSummary; grant: GrantRow; error: null }
|
|
91
|
+
| { project: ProjectSummary; grant: null; error: string };
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The Access tab's rows, project by project: a row per grant, and a project
|
|
95
|
+
* whose read failed keeps a row of its own that says why, so a failure
|
|
96
|
+
* never reads as no access.
|
|
97
|
+
*/
|
|
98
|
+
export function accessRows(access: ProjectAccess[]): AccessRow[] {
|
|
99
|
+
return access.flatMap(({ project, grants, grantsError }): AccessRow[] =>
|
|
100
|
+
grantsError === null
|
|
101
|
+
? grants.map((grant) => ({ project, grant, error: null }))
|
|
102
|
+
: [{ project, grant: null, error: grantsError }],
|
|
103
|
+
);
|
|
104
|
+
}
|
package/src/lib/queries.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AuthInfo, CoffreClient, Member } from '@coffre/client';
|
|
2
|
+
import { EVERYWHERE, INSTANCE_ROLES } from '@coffre/core/access';
|
|
2
3
|
import { QueryClient, queryOptions, type QueryKey } from '@tanstack/react-query';
|
|
3
4
|
|
|
4
5
|
import { deriveUiCapabilities } from './capabilities.ts';
|
|
@@ -51,6 +52,7 @@ export const keys = {
|
|
|
51
52
|
missing: ({ project, environment }: Place) => ['missing', project, environment],
|
|
52
53
|
directory: ['directory'],
|
|
53
54
|
report: (member: string) => ['report', member],
|
|
55
|
+
memberAccess: (member: string) => ['member-access', member],
|
|
54
56
|
credentials: (member: string) => ['credentials', member],
|
|
55
57
|
bindings: (member: string) => ['bindings', member],
|
|
56
58
|
identities: ['identities'],
|
|
@@ -58,35 +60,51 @@ export const keys = {
|
|
|
58
60
|
apps: ['apps'],
|
|
59
61
|
audit: ['audit'],
|
|
60
62
|
auditKeys: ['audit', 'keys'],
|
|
63
|
+
settings: ['settings'],
|
|
61
64
|
} satisfies Record<string, QueryKey | ((...args: never[]) => QueryKey)>;
|
|
62
65
|
|
|
63
|
-
/**
|
|
66
|
+
/** Members' grants, as rows, and a row for each one whose instance role reaches the place listed. */
|
|
64
67
|
function grantRows(members: Member[]): GrantRow[] {
|
|
65
|
-
return members.flatMap((member) =>
|
|
66
|
-
member.
|
|
68
|
+
return members.flatMap((member): GrantRow[] => [
|
|
69
|
+
...(member.reachesByRole && member.instanceRole !== 'root-admin'
|
|
70
|
+
? [{
|
|
71
|
+
id: `${member.member}/instance-role`,
|
|
72
|
+
principalType: member.principalType,
|
|
73
|
+
principalId: member.principalId,
|
|
74
|
+
role: member.instanceRole,
|
|
75
|
+
roleName: INSTANCE_ROLES[member.instanceRole].name,
|
|
76
|
+
permissions: [...INSTANCE_ROLES[member.instanceRole].permissions],
|
|
77
|
+
scope: 'instance-role' as const,
|
|
78
|
+
environmentSlug: null,
|
|
79
|
+
expiresAt: null,
|
|
80
|
+
}]
|
|
81
|
+
: []),
|
|
82
|
+
...member.grants.map((grant) => ({
|
|
67
83
|
id: grant.id,
|
|
68
84
|
principalType: member.principalType,
|
|
69
85
|
principalId: member.principalId,
|
|
70
86
|
role: grant.role,
|
|
71
87
|
roleName: grant.roleName,
|
|
72
88
|
permissions: grant.permissions,
|
|
73
|
-
scope: grant.
|
|
89
|
+
scope: grant.environment === null ? ('project' as const) : ('environment' as const),
|
|
74
90
|
environmentSlug: grant.environment,
|
|
75
91
|
expiresAt: grant.expiresAt,
|
|
76
92
|
})),
|
|
77
|
-
);
|
|
93
|
+
]);
|
|
78
94
|
}
|
|
79
95
|
|
|
80
96
|
function listDirectory(client: CoffreClient) {
|
|
81
97
|
return uiResult(async () => {
|
|
82
98
|
const { members, removed } = await client.members.list();
|
|
83
99
|
const principals: DirectoryPrincipal[] = members.map(
|
|
84
|
-
({ principalType, principalId, instanceRole, isRootAdmin, tampered, grants }) => ({
|
|
100
|
+
({ principalType, principalId, instanceRole, scope, isRootAdmin, tampered, managed, grants }) => ({
|
|
85
101
|
principalType,
|
|
86
102
|
principalId,
|
|
87
103
|
instanceRole,
|
|
104
|
+
scope,
|
|
88
105
|
isRootAdmin,
|
|
89
106
|
tampered,
|
|
107
|
+
managed,
|
|
90
108
|
grants: grants.map(({ project, environment }) => ({ project, environment })),
|
|
91
109
|
}),
|
|
92
110
|
);
|
|
@@ -154,8 +172,8 @@ export const queries = {
|
|
|
154
172
|
|
|
155
173
|
/**
|
|
156
174
|
* Everyone in the directory, and who was removed. The API shows grant
|
|
157
|
-
* managers the members of their projects; the directory pages
|
|
158
|
-
* owners'
|
|
175
|
+
* managers the members of their projects; the directory pages are admins'
|
|
176
|
+
* and owners', and asking for anyone else would only log a refusal, so
|
|
159
177
|
* nobody else is asked.
|
|
160
178
|
*/
|
|
161
179
|
directory: (client: CoffreClient, owner: boolean) =>
|
|
@@ -166,11 +184,22 @@ export const queries = {
|
|
|
166
184
|
? listDirectory(client)
|
|
167
185
|
: Promise.resolve({
|
|
168
186
|
ok: false as const,
|
|
169
|
-
error: 'Only owners
|
|
187
|
+
error: 'Only admins and owners manage users, and service accounts are set up by those who hold access where the instance lets them.',
|
|
170
188
|
signedOut: false,
|
|
171
189
|
}),
|
|
172
190
|
}),
|
|
173
191
|
|
|
192
|
+
/**
|
|
193
|
+
* One member's instance role and scope, and the grants you manage, in one
|
|
194
|
+
* read: their page's Access tab. Null for whoever may list nobody, which
|
|
195
|
+
* asking would only log as a refusal.
|
|
196
|
+
*/
|
|
197
|
+
memberAccess: (client: CoffreClient, member: string, allowed: boolean) =>
|
|
198
|
+
queryOptions({
|
|
199
|
+
queryKey: [...keys.memberAccess(member), { allowed }],
|
|
200
|
+
queryFn: () => (allowed ? uiResult(() => client.members.access(member)) : Promise.resolve(null)),
|
|
201
|
+
}),
|
|
202
|
+
|
|
174
203
|
/** What one member can reach and has seen; null for anyone but owners, who alone may ask. */
|
|
175
204
|
report: (client: CoffreClient, member: string, owner: boolean) =>
|
|
176
205
|
queryOptions({
|
|
@@ -232,6 +261,13 @@ export const queries = {
|
|
|
232
261
|
queryFn: () => (allowed ? uiResult(() => client.audit.keys()) : Promise.resolve(null)),
|
|
233
262
|
}),
|
|
234
263
|
|
|
264
|
+
/** The instance's settings: null for anyone but those who run it, who alone may ask. */
|
|
265
|
+
settings: (client: CoffreClient, allowed: boolean) =>
|
|
266
|
+
queryOptions({
|
|
267
|
+
queryKey: [...keys.settings, { allowed }],
|
|
268
|
+
queryFn: () => (allowed ? uiResult(() => client.settings.get()) : Promise.resolve(null)),
|
|
269
|
+
}),
|
|
270
|
+
|
|
235
271
|
/** A page of the log, as filtered: always read fresh. */
|
|
236
272
|
auditEntries: (client: CoffreClient, search: AuditSearch) =>
|
|
237
273
|
queryOptions({
|
|
@@ -273,8 +309,9 @@ export const queries = {
|
|
|
273
309
|
};
|
|
274
310
|
|
|
275
311
|
/**
|
|
276
|
-
* Whether the log holds, or why that is not known. Verifying is for
|
|
277
|
-
*
|
|
312
|
+
* Whether the log holds, or why that is not known. Verifying is for those
|
|
313
|
+
* who read the whole log (an Auditor, Admin or Owner whose scope narrows
|
|
314
|
+
* nothing, a root admin): anyone else reads their projects' part of it, and a part cannot be
|
|
278
315
|
* checked as a chain, so for them it is a fact about the page, not a fault.
|
|
279
316
|
*/
|
|
280
317
|
async function verifyChain(client: CoffreClient) {
|
|
@@ -324,6 +361,8 @@ export function shellOf(
|
|
|
324
361
|
auth,
|
|
325
362
|
principal: me === null ? null : me.principal,
|
|
326
363
|
instanceRole: member?.instanceRole ?? null,
|
|
364
|
+
/** Where their instance role applies, projects by slug. */
|
|
365
|
+
scope: member?.scope ?? EVERYWHERE,
|
|
327
366
|
projects: listed,
|
|
328
367
|
capabilities: deriveUiCapabilities(member, listed),
|
|
329
368
|
registrationRequired: me !== null && !me.registered,
|
|
@@ -331,6 +370,10 @@ export function shellOf(
|
|
|
331
370
|
accessTampered: me?.tampered === true,
|
|
332
371
|
/** What the deployment's configuration turns on: MCP clients, as their endpoint's URL, and CI runs signing in by their ID tokens. */
|
|
333
372
|
features: member?.features ?? { mcp: null, workloads: false },
|
|
373
|
+
/** Every environment you hold something in, and what: what you may give a service account there (`givable`). */
|
|
374
|
+
environments: member?.environments ?? [],
|
|
375
|
+
/** Where you set up service accounts yourself, the instance's setting, projects by slug. */
|
|
376
|
+
serviceSetup: member?.serviceSetup ?? null,
|
|
334
377
|
};
|
|
335
378
|
}
|
|
336
379
|
|
|
@@ -372,15 +415,31 @@ export async function loadDirectory(queryClient: QueryClient, client: CoffreClie
|
|
|
372
415
|
return queryClient.fetchQuery(queries.directory(client, shell.capabilities.canManageGrants));
|
|
373
416
|
}
|
|
374
417
|
|
|
375
|
-
/** The instance's settings: the directory's counts, and what its keys are checked against. */
|
|
418
|
+
/** The instance's settings: the directory's counts, where people set up service accounts, and what its keys are checked against. */
|
|
376
419
|
export async function loadSettings(queryClient: QueryClient, client: CoffreClient) {
|
|
377
420
|
const shell = await loadShell(queryClient, client);
|
|
378
421
|
await Promise.all([
|
|
379
422
|
loadDirectory(queryClient, client),
|
|
380
|
-
queryClient.fetchQuery(queries.
|
|
423
|
+
queryClient.fetchQuery(queries.settings(client, shell.capabilities.runsInstance)),
|
|
424
|
+
queryClient.fetchQuery(queries.auditKeys(client, shell.capabilities.runsInstance)),
|
|
381
425
|
]);
|
|
382
426
|
}
|
|
383
427
|
|
|
428
|
+
/** Whether the Service accounts page lists anyone: to admins and owners, and to whoever sets one up, those they manage. */
|
|
429
|
+
export function listsServices(shell: Shell): boolean {
|
|
430
|
+
return shell.capabilities.canManageGrants || shell.capabilities.setsUpServices;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* How the caller may have a service account sign in, from its list entry
|
|
435
|
+
* or its access: bearer tokens under coffre's own sign-in, trusted
|
|
436
|
+
* workloads where the deployment trusts them, each only for an account they
|
|
437
|
+
* manage.
|
|
438
|
+
*/
|
|
439
|
+
export function waysFor(shell: Shell, managed: boolean): { tokens: boolean; workloads: boolean } {
|
|
440
|
+
return { tokens: managed && shell.auth.signin !== null, workloads: managed && shell.features.workloads };
|
|
441
|
+
}
|
|
442
|
+
|
|
384
443
|
/**
|
|
385
444
|
* The service accounts page: the directory, and each account's bindings and
|
|
386
445
|
* tokens, read here as its own page reads them, so the list shows how each
|
|
@@ -389,56 +448,74 @@ export async function loadSettings(queryClient: QueryClient, client: CoffreClien
|
|
|
389
448
|
*/
|
|
390
449
|
export async function loadServiceDirectory(queryClient: QueryClient, client: CoffreClient) {
|
|
391
450
|
const shell = await loadShell(queryClient, client);
|
|
392
|
-
const directory = await
|
|
393
|
-
|
|
394
|
-
const trusts = shell.capabilities.canManageGrants && shell.features.workloads;
|
|
395
|
-
if (!directory.ok || !allowed) return directory;
|
|
451
|
+
const directory = await queryClient.fetchQuery(queries.directory(client, listsServices(shell)));
|
|
452
|
+
if (!directory.ok) return directory;
|
|
396
453
|
await Promise.all(
|
|
397
454
|
directory.principals
|
|
398
455
|
.filter((principal) => principal.principalType === 'service')
|
|
399
456
|
.flatMap((principal) => {
|
|
400
457
|
const member = memberRef('service', principal.principalId);
|
|
458
|
+
const ways = waysFor(shell, principal.managed === true);
|
|
401
459
|
return [
|
|
402
|
-
queryClient.fetchQuery(queries.credentials(client, member,
|
|
403
|
-
queryClient.fetchQuery(queries.bindings(client, member,
|
|
460
|
+
queryClient.fetchQuery(queries.credentials(client, member, ways.tokens)),
|
|
461
|
+
queryClient.fetchQuery(queries.bindings(client, member, ways.workloads)),
|
|
404
462
|
];
|
|
405
463
|
}),
|
|
406
464
|
);
|
|
407
465
|
return directory;
|
|
408
466
|
}
|
|
409
467
|
|
|
410
|
-
/** Who a user or service account is to the instance, its pages' header: null to anyone
|
|
468
|
+
/** Who a user or service account is to the instance, its pages' header: null to anyone who does not run it. */
|
|
411
469
|
export async function loadMember(queryClient: QueryClient, client: CoffreClient, member: string) {
|
|
412
470
|
const shell = await loadShell(queryClient, client);
|
|
413
|
-
return queryClient.fetchQuery(queries.report(client, member, shell.capabilities.
|
|
471
|
+
return queryClient.fetchQuery(queries.report(client, member, shell.capabilities.runsInstance));
|
|
414
472
|
}
|
|
415
473
|
|
|
416
474
|
export type MemberReport = Awaited<ReturnType<typeof loadMember>>;
|
|
417
475
|
|
|
418
476
|
/**
|
|
419
|
-
* What a user's or service account's Access tab reads:
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* keeps this member's. Projects where you do not hold grant.manage are
|
|
423
|
-
* skipped rather than asked: the refusal would land in the audit log as a
|
|
424
|
-
* denial in your name.
|
|
477
|
+
* What a user's or service account's Access tab reads: their role, scope
|
|
478
|
+
* and the grants you manage, in one request, which the server answers in
|
|
479
|
+
* one query, however many projects they hold grants in.
|
|
425
480
|
*/
|
|
426
|
-
export async function loadAccess(queryClient: QueryClient, client: CoffreClient) {
|
|
481
|
+
export async function loadAccess(queryClient: QueryClient, client: CoffreClient, member: string) {
|
|
427
482
|
const shell = await loadShell(queryClient, client);
|
|
428
|
-
|
|
483
|
+
return queryClient.fetchQuery(queries.memberAccess(client, member, listsAccess(shell)));
|
|
429
484
|
}
|
|
430
485
|
|
|
486
|
+
/**
|
|
487
|
+
* Whether the caller may ask what someone holds: admins and owners,
|
|
488
|
+
* whoever manages a project's access, and whoever sets up service accounts,
|
|
489
|
+
* of those they manage.
|
|
490
|
+
*/
|
|
491
|
+
export function listsAccess(shell: Shell): boolean {
|
|
492
|
+
return shell.capabilities.canManageGrants || shell.capabilities.setsUpServices || managedProjects(shell.projects).length > 0;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export type MemberAccessResult = Awaited<ReturnType<typeof loadAccess>>;
|
|
496
|
+
|
|
431
497
|
/**
|
|
432
498
|
* How a service account's page lets it sign in: bearer tokens under
|
|
433
499
|
* coffre's own sign-in, trusted workloads where the deployment trusts them.
|
|
434
|
-
* Null where it shows neither: to anyone
|
|
435
|
-
* that is not active, which can be
|
|
500
|
+
* Null where it shows neither: to anyone who does not manage it (its access
|
|
501
|
+
* says, `managed`), and for an account that is not active, which can be
|
|
502
|
+
* issued nothing.
|
|
503
|
+
*/
|
|
504
|
+
export function signInWays(shell: Shell, access: MemberAccessResult): { tokens: boolean; workloads: boolean } | null {
|
|
505
|
+
const managed = access?.ok === true && access.managed && access.status === 'active';
|
|
506
|
+
const ways = waysFor(shell, managed);
|
|
507
|
+
return ways.tokens || ways.workloads ? ways : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Whether a user has a Connected apps tab: for an owner, where the
|
|
512
|
+
* deployment serves MCP, and while the user is registered and not removed,
|
|
513
|
+
* since removal disconnects every app. The tab, and the route under it,
|
|
514
|
+
* both ask.
|
|
436
515
|
*/
|
|
437
|
-
export function
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
const active = report?.ok === true && report.report?.status === 'active';
|
|
441
|
-
return active && (ways.tokens || ways.workloads) ? ways : null;
|
|
516
|
+
export function hasAppsTab(shell: Shell, report: MemberReport): boolean {
|
|
517
|
+
const found = report?.ok === true ? report.report : null;
|
|
518
|
+
return Boolean(shell.features.mcp) && shell.capabilities.runsInstance && found !== null && found.status !== 'removed';
|
|
442
519
|
}
|
|
443
520
|
|
|
444
521
|
export function managedProjects(projects: ProjectSummary[]): ProjectSummary[] {
|
|
@@ -460,25 +537,25 @@ export const affects = {
|
|
|
460
537
|
*/
|
|
461
538
|
access: (project: string, member: string): QueryKey[] => [
|
|
462
539
|
keys.grants(project),
|
|
540
|
+
keys.memberAccess(member),
|
|
463
541
|
keys.report(member),
|
|
464
542
|
keys.projects,
|
|
465
543
|
keys.me,
|
|
466
544
|
],
|
|
467
|
-
/**
|
|
468
|
-
* Someone's access on every project changed: every project's grants, which
|
|
469
|
-
* list it where it reaches, the list of them, their report, and what you
|
|
470
|
-
* can see, as it may be your own.
|
|
471
|
-
*/
|
|
472
|
-
everyProject: (member: string): QueryKey[] => [['grants'], keys.projects, keys.report(member), keys.me],
|
|
473
545
|
/** Someone let in: the directory. */
|
|
474
546
|
admission: (): QueryKey[] => [keys.directory],
|
|
475
547
|
/**
|
|
476
548
|
* An instance role changed: the directory, their report, and, as it may be
|
|
477
549
|
* your own, what you can see and do.
|
|
478
550
|
*/
|
|
479
|
-
role: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.me, keys.projects],
|
|
551
|
+
role: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.memberAccess(member), keys.me, keys.projects],
|
|
480
552
|
/** Someone removed: the directory, their report, and every grant, which removal ends, those on every project too. */
|
|
481
|
-
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), ['grants'], keys.projects],
|
|
553
|
+
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.memberAccess(member), ['grants'], keys.projects],
|
|
554
|
+
/**
|
|
555
|
+
* Where people set up service accounts changed: the setting, and what you
|
|
556
|
+
* may do, which the directory and `/me` say.
|
|
557
|
+
*/
|
|
558
|
+
settings: (): QueryKey[] => [keys.settings, keys.me, keys.directory],
|
|
482
559
|
credentials: (member: string): QueryKey[] => [keys.credentials(member)],
|
|
483
560
|
bindings: (member: string): QueryKey[] => [keys.bindings(member)],
|
|
484
561
|
/** Unlinking an account also ends the sessions it signed in. */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { inScope, ROLE_NAMES, ROLES, type Permission, type Role, type Scope } from '@coffre/core/access';
|
|
2
|
+
|
|
3
|
+
import type { ProjectSummary } from '../shared/models';
|
|
4
|
+
|
|
5
|
+
/** What `givable` reads of the shell: the projects, what you hold in each environment, and the setting. */
|
|
6
|
+
type Holder = {
|
|
7
|
+
projects: readonly ProjectSummary[];
|
|
8
|
+
environments: readonly { project: string; environment: string; permissions: Permission[] }[];
|
|
9
|
+
/** The instance's setting as `/me` says it, projects by slug, those you see; null for a service account. */
|
|
10
|
+
serviceSetup: Scope | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The roles you may give a service account at a project, or one of its
|
|
15
|
+
* environments, as the server decides it (`givesService` in
|
|
16
|
+
* @coffre/core/access): any, where you manage access; otherwise, inside the
|
|
17
|
+
* instance's setting, those whose every permission you hold there.
|
|
18
|
+
*
|
|
19
|
+
* a Developer of every dev, at market/dev viewer, developer
|
|
20
|
+
* the same, at market none: a project takes holding all of it
|
|
21
|
+
*/
|
|
22
|
+
export function givable(holder: Holder, project: ProjectSummary, environment: string | null): Role[] {
|
|
23
|
+
const held = environment === null
|
|
24
|
+
? project.permissions
|
|
25
|
+
: holder.environments.find((entry) => entry.project === project.slug && entry.environment === environment)?.permissions ?? [];
|
|
26
|
+
if (held.includes('grant.manage')) return [...ROLE_NAMES];
|
|
27
|
+
const setting = holder.serviceSetup;
|
|
28
|
+
// The setting names projects by slug here, so a place is matched by its slugs.
|
|
29
|
+
const place = environment === null
|
|
30
|
+
? { projectId: project.slug }
|
|
31
|
+
: { projectId: project.slug, environmentId: environment, environmentSlug: environment };
|
|
32
|
+
if (setting === null || !inScope(setting, place)) return [];
|
|
33
|
+
return ROLE_NAMES.filter((role) => ROLES[role].permissions.every((permission) => held.includes(permission)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The projects where you may give a service account something: on the project, or on one of its environments. */
|
|
37
|
+
export function serviceProjects(holder: Holder): ProjectSummary[] {
|
|
38
|
+
return holder.projects.filter((project) =>
|
|
39
|
+
givable(holder, project, null).length > 0 ||
|
|
40
|
+
project.environments.some((environment) => givable(holder, project, environment.slug).length > 0));
|
|
41
|
+
}
|