@crombolo/server 0.61.0 → 0.63.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/package.json +14 -14
- package/src/access.ts +5 -5
- package/src/adapters/content.ts +13 -1
- package/src/adapters/file-system.ts +27 -3
- package/src/adapters/template-files.ts +10 -0
- package/src/adapters/users.ts +55 -84
- package/src/bundle-admin.ts +21 -1
- package/src/bundle-api.ts +1 -3
- package/src/bundle-code.ts +93 -5
- package/src/bundle-install.ts +28 -5
- package/src/bundle-sections.ts +10 -0
- package/src/config.ts +46 -7
- package/src/content-query.ts +2 -4
- package/src/core.ts +83 -25
- package/src/extension-install.ts +631 -0
- package/src/extension-process.ts +30 -7
- package/src/external-sign-in.ts +10 -0
- package/src/form-workflows.ts +110 -12
- package/src/grant-policy.ts +23 -3
- package/src/grant-trust.ts +73 -0
- package/src/identity-provider-overrides.ts +186 -36
- package/src/identity-providers.ts +23 -0
- package/src/index.ts +7 -0
- package/src/marketplace.ts +54 -338
- package/src/member-auth.ts +5 -1
- package/src/outbound-address.ts +1 -1
- package/src/ports.ts +24 -7
- package/src/provenance.ts +13 -1
- package/src/remote.ts +23 -8
- package/src/server.ts +87 -3
- package/src/settings.ts +22 -0
- package/src/site-trust.ts +16 -0
- package/src/transfer-dashboard.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@crombolo/api-delivery": "0.
|
|
35
|
-
"@crombolo/api-management": "0.
|
|
36
|
-
"@crombolo/auth": "0.
|
|
37
|
-
"@crombolo/backoffice-host": "0.
|
|
38
|
-
"@crombolo/common": "0.
|
|
39
|
-
"@crombolo/content": "0.
|
|
40
|
-
"@crombolo/contracts": "0.
|
|
41
|
-
"@crombolo/core": "0.
|
|
42
|
-
"@crombolo/data": "0.
|
|
43
|
-
"@crombolo/extension": "0.
|
|
44
|
-
"@crombolo/render": "0.
|
|
45
|
-
"@crombolo/schema": "0.
|
|
46
|
-
"@crombolo/transfer": "0.
|
|
34
|
+
"@crombolo/api-delivery": "0.63.0",
|
|
35
|
+
"@crombolo/api-management": "0.63.0",
|
|
36
|
+
"@crombolo/auth": "0.63.0",
|
|
37
|
+
"@crombolo/backoffice-host": "0.63.0",
|
|
38
|
+
"@crombolo/common": "0.63.0",
|
|
39
|
+
"@crombolo/content": "0.63.0",
|
|
40
|
+
"@crombolo/contracts": "0.63.0",
|
|
41
|
+
"@crombolo/core": "0.63.0",
|
|
42
|
+
"@crombolo/data": "0.63.0",
|
|
43
|
+
"@crombolo/extension": "0.63.0",
|
|
44
|
+
"@crombolo/render": "0.63.0",
|
|
45
|
+
"@crombolo/schema": "0.63.0",
|
|
46
|
+
"@crombolo/transfer": "0.63.0",
|
|
47
47
|
"@logtape/logtape": "^2.3.8",
|
|
48
48
|
"@opentelemetry/api": "1.10.0",
|
|
49
49
|
"@opentelemetry/context-async-hooks": "3.0.0",
|
package/src/access.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* and each signed-in user's combined start nodes, group verbs and languages.
|
|
4
4
|
*/
|
|
5
5
|
import type { NodeChain, NodeLookup, Principal } from '@crombolo/api-management/domain'
|
|
6
|
-
import {
|
|
6
|
+
import { normaliseUuid, ObjectTypes, unionStartNodes } from '@crombolo/core'
|
|
7
7
|
import { type Db, fromDbBool, UserRepository } from '@crombolo/data'
|
|
8
8
|
|
|
9
9
|
async function chains(
|
|
@@ -98,7 +98,7 @@ export function createNodeLookup(db: Db): NodeLookup {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
/** A user's languages,
|
|
101
|
+
/** A user's languages, their groups' start nodes per tree (story 339), and group verbs. */
|
|
102
102
|
export async function loadAccess(
|
|
103
103
|
db: Db,
|
|
104
104
|
userId: number,
|
|
@@ -108,9 +108,9 @@ export async function loadAccess(
|
|
|
108
108
|
languages: data.languages,
|
|
109
109
|
groups: data.groups,
|
|
110
110
|
startNodes: {
|
|
111
|
-
document:
|
|
112
|
-
media:
|
|
113
|
-
element:
|
|
111
|
+
document: unionStartNodes(data.groupStartNodes.document),
|
|
112
|
+
media: unionStartNodes(data.groupStartNodes.media),
|
|
113
|
+
element: unionStartNodes(data.groupStartNodes.element),
|
|
114
114
|
},
|
|
115
115
|
}
|
|
116
116
|
}
|
package/src/adapters/content.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
TemplatePort,
|
|
15
15
|
TreePage,
|
|
16
16
|
} from '@crombolo/api-management/domain'
|
|
17
|
+
import { CONTENT_FILES_READ_ONLY } from '@crombolo/api-management/domain'
|
|
17
18
|
import {
|
|
18
19
|
type ComponentModel,
|
|
19
20
|
type ContentTypeAggregate,
|
|
@@ -330,8 +331,18 @@ export function createContentTypePort(
|
|
|
330
331
|
if (refused) return refused
|
|
331
332
|
const alias = template.alias || aggregate.alias
|
|
332
333
|
const name = template.name || aggregate.name
|
|
334
|
+
const existing = await templates.byAlias(alias)
|
|
335
|
+
// Story 337: a site that keeps its templates read-only adds them in its code.
|
|
336
|
+
if (!existing && options.componentFiles?.readOnly) {
|
|
337
|
+
const failure: PortFailure = {
|
|
338
|
+
ok: false,
|
|
339
|
+
reason: `${CONTENT_FILES_READ_ONLY} Add the template to the site's code.`,
|
|
340
|
+
status: 403,
|
|
341
|
+
}
|
|
342
|
+
return failure
|
|
343
|
+
}
|
|
333
344
|
const saved =
|
|
334
|
-
|
|
345
|
+
existing ??
|
|
335
346
|
(await templates.save({
|
|
336
347
|
key: crypto.randomUUID(),
|
|
337
348
|
name,
|
|
@@ -733,6 +744,7 @@ export function createTemplatePort(db: Db, files: ComponentFileStore): TemplateP
|
|
|
733
744
|
})
|
|
734
745
|
|
|
735
746
|
return {
|
|
747
|
+
readOnly: files.readOnly === true,
|
|
736
748
|
async byKey(key) {
|
|
737
749
|
const model = await repo.byKey(key)
|
|
738
750
|
if (!model) return undefined
|
|
@@ -15,6 +15,8 @@ export interface FileAreaOptions {
|
|
|
15
15
|
rewrites?: readonly string[]
|
|
16
16
|
/** Other extensions a file here may have, kept as they are. */
|
|
17
17
|
also?: readonly string[]
|
|
18
|
+
/** The site keeps these files read-only in the back office (story 337). */
|
|
19
|
+
readOnly?: boolean
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
const INVALID_CHARACTERS = /[<>:"|?*\\/]/
|
|
@@ -93,7 +95,7 @@ export function createFileSystemPort(root: string, options: FileAreaOptions): Fi
|
|
|
93
95
|
return (await kindOf(parent.file)) === 'folder' ? parent : undefined
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
const port: FileSystemPort = {
|
|
97
99
|
async children(parentPath) {
|
|
98
100
|
const parent = locate(parentPath)
|
|
99
101
|
if (!parent) return undefined
|
|
@@ -194,8 +196,30 @@ export function createFileSystemPort(root: string, options: FileAreaOptions): Fi
|
|
|
194
196
|
return { ok: true, path: entry.path }
|
|
195
197
|
},
|
|
196
198
|
}
|
|
199
|
+
return options.readOnly ? readOnlyPort(port) : port
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Reads as `port` does, and refuses every change (story 337). */
|
|
203
|
+
function readOnlyPort(port: FileSystemPort): FileSystemPort {
|
|
204
|
+
const refused = async (): Promise<FileResult> => ({ ok: false, status: 'ReadOnly' })
|
|
205
|
+
return {
|
|
206
|
+
children: (path) => port.children(path),
|
|
207
|
+
entry: (path) => port.entry(path),
|
|
208
|
+
read: (path) => port.read(path),
|
|
209
|
+
create: refused,
|
|
210
|
+
update: refused,
|
|
211
|
+
rename: refused,
|
|
212
|
+
delete: refused,
|
|
213
|
+
createFolder: refused,
|
|
214
|
+
deleteFolder: refused,
|
|
215
|
+
}
|
|
197
216
|
}
|
|
198
217
|
|
|
199
218
|
/** The components tree: its views, and the plain modules they import. */
|
|
200
|
-
export const createComponentsPort = (root: string): FileSystemPort =>
|
|
201
|
-
createFileSystemPort(root, {
|
|
219
|
+
export const createComponentsPort = (root: string, readOnly = false): FileSystemPort =>
|
|
220
|
+
createFileSystemPort(root, {
|
|
221
|
+
extension: '.tsx',
|
|
222
|
+
also: ['.ts'],
|
|
223
|
+
rewrites: ['.cshtml'],
|
|
224
|
+
readOnly,
|
|
225
|
+
})
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { existsSync } from 'node:fs'
|
|
8
8
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
9
9
|
import { join } from 'node:path'
|
|
10
|
+
import { CONTENT_FILES_READ_ONLY } from '@crombolo/api-management/domain'
|
|
10
11
|
import type { ComponentFileStore } from '@crombolo/data'
|
|
11
12
|
|
|
12
13
|
/** Aliases become filenames, so they must not be able to escape the directory. */
|
|
@@ -24,6 +25,7 @@ function safeAlias(alias: string): string | undefined {
|
|
|
24
25
|
export function createTemplateFileStore(
|
|
25
26
|
dir: string,
|
|
26
27
|
onChange?: (alias: string) => void | Promise<void>,
|
|
28
|
+
readOnly = false,
|
|
27
29
|
): ComponentFileStore {
|
|
28
30
|
const fileFor = (alias: string): string | undefined => {
|
|
29
31
|
const safe = safeAlias(alias)
|
|
@@ -34,7 +36,13 @@ export function createTemplateFileStore(
|
|
|
34
36
|
return !existsSync(file) && existsSync(folder) ? folder : file
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
// Callers check `readOnly` first; this is the backstop (story 337).
|
|
40
|
+
const refuse = () => {
|
|
41
|
+
if (readOnly) throw new Error(CONTENT_FILES_READ_ONLY)
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
return {
|
|
45
|
+
readOnly,
|
|
38
46
|
async read(alias) {
|
|
39
47
|
const file = fileFor(alias)
|
|
40
48
|
if (!file) return undefined
|
|
@@ -45,6 +53,7 @@ export function createTemplateFileStore(
|
|
|
45
53
|
}
|
|
46
54
|
},
|
|
47
55
|
async write(alias, content) {
|
|
56
|
+
refuse()
|
|
48
57
|
const file = fileFor(alias)
|
|
49
58
|
if (!file) throw new Error(`Unsafe template alias '${alias}'.`)
|
|
50
59
|
await mkdir(dir, { recursive: true })
|
|
@@ -54,6 +63,7 @@ export function createTemplateFileStore(
|
|
|
54
63
|
await onChange?.(alias)
|
|
55
64
|
},
|
|
56
65
|
async remove(alias) {
|
|
66
|
+
refuse()
|
|
57
67
|
const file = fileFor(alias)
|
|
58
68
|
if (!file) return
|
|
59
69
|
await rm(file, { force: true })
|
package/src/adapters/users.ts
CHANGED
|
@@ -26,17 +26,16 @@ import {
|
|
|
26
26
|
verifyPassword,
|
|
27
27
|
} from '@crombolo/auth'
|
|
28
28
|
import {
|
|
29
|
+
ADMIN_GROUP_ALIAS,
|
|
29
30
|
DEFAULT_PASSWORD_CONFIGURATION,
|
|
30
31
|
generateUserPassword,
|
|
31
|
-
|
|
32
|
+
isRemotePermission,
|
|
32
33
|
isValidEmail,
|
|
33
34
|
isValidPassword,
|
|
34
35
|
normaliseUuid,
|
|
35
36
|
type Page,
|
|
36
37
|
permissionsForPath,
|
|
37
|
-
type StartNodes,
|
|
38
38
|
sectionAppAlias,
|
|
39
|
-
sectionKey,
|
|
40
39
|
sectionName,
|
|
41
40
|
} from '@crombolo/core'
|
|
42
41
|
import {
|
|
@@ -105,8 +104,6 @@ function toUserResponse(user: UserRecord, adminKey: string | undefined): UserRes
|
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
type Tree = 'document' | 'media' | 'element'
|
|
109
|
-
|
|
110
107
|
export interface UserPortOptions {
|
|
111
108
|
config: Pick<
|
|
112
109
|
CromboloConfig,
|
|
@@ -145,27 +142,8 @@ export function createUserPorts(
|
|
|
145
142
|
return !targets.some((t) => isAdmin(t, admin))
|
|
146
143
|
}
|
|
147
144
|
|
|
148
|
-
const chainsFor = async (tree: Tree, keys: readonly string[]) =>
|
|
149
|
-
tree === 'media' ? nodes.media(keys) : nodes.documents(keys)
|
|
150
|
-
|
|
151
|
-
/** Newly granted start nodes must lie where the performing user may work; root needs root. */
|
|
152
|
-
const mayGrantStartNodes = async (
|
|
153
|
-
performing: StartNodes,
|
|
154
|
-
tree: Tree,
|
|
155
|
-
granted: { root: boolean; keys: readonly string[] },
|
|
156
|
-
had: { root: boolean; keys: readonly string[] },
|
|
157
|
-
) => {
|
|
158
|
-
if (granted.root && !had.root && !performing.root) return false
|
|
159
|
-
const added = granted.keys.filter((k) => !had.keys.includes(normaliseUuid(k)))
|
|
160
|
-
if (added.length === 0 || tree === 'element') return true
|
|
161
|
-
const found = await chainsFor(tree, added)
|
|
162
|
-
return added.every((key) => {
|
|
163
|
-
const node = found.get(normaliseUuid(key))
|
|
164
|
-
return !node || hasPathAccess(performing, node.chain, node.trashed)
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
145
|
/** Umbraco's `UserEditorAuthorizationHelper`: who may give which groups to whom. */
|
|
146
|
+
/** Story 302: each group added to or taken from a user must be one the caller owns. */
|
|
169
147
|
const mayAssignGroups = async (
|
|
170
148
|
principal: Principal,
|
|
171
149
|
target: UserRecord | undefined,
|
|
@@ -174,11 +152,15 @@ export function createUserPorts(
|
|
|
174
152
|
if (principal.isAdmin) return true
|
|
175
153
|
const admin = await adminKey()
|
|
176
154
|
if (target && isAdmin(target, admin)) return false
|
|
177
|
-
const wanted = groupKeys.map(normaliseUuid)
|
|
178
|
-
if (admin && wanted.includes(admin)) return false
|
|
155
|
+
const wanted = new Set(groupKeys.map(normaliseUuid))
|
|
179
156
|
const had = new Set(target?.groupKeys ?? [])
|
|
180
|
-
const
|
|
181
|
-
|
|
157
|
+
const changed = [
|
|
158
|
+
...[...wanted].filter((k) => !had.has(k)),
|
|
159
|
+
...[...had].filter((k) => !wanted.has(k)),
|
|
160
|
+
]
|
|
161
|
+
if (changed.length === 0) return true
|
|
162
|
+
const owned = new Set(await groups.ownedBy(principal.groupKeys))
|
|
163
|
+
return changed.every((k) => owned.has(k))
|
|
182
164
|
}
|
|
183
165
|
|
|
184
166
|
const visibleTo = async (principal: Principal) => {
|
|
@@ -254,7 +236,7 @@ export function createUserPorts(
|
|
|
254
236
|
if ((await groups.byKeys(input.groupKeys)).length !== new Set(input.groupKeys).size)
|
|
255
237
|
return { status: 'MissingUserGroup' }
|
|
256
238
|
if (!(await mayAssignGroups(principal, undefined, input.groupKeys)))
|
|
257
|
-
return { status: '
|
|
239
|
+
return { status: 'NotGroupOwner' }
|
|
258
240
|
const created = await users.create({
|
|
259
241
|
key: input.key ?? crypto.randomUUID(),
|
|
260
242
|
name: input.name || input.userName,
|
|
@@ -432,35 +414,17 @@ export function createUserPorts(
|
|
|
432
414
|
if (input.groupKeys.length === 0) return 'NoUserGroup'
|
|
433
415
|
if ((await groups.byKeys(input.groupKeys)).length !== new Set(input.groupKeys).size)
|
|
434
416
|
return 'MissingUserGroup'
|
|
435
|
-
if (!(await mayAssignGroups(principal, user, input.groupKeys))) return '
|
|
436
|
-
|
|
437
|
-
document: { root: input.hasDocumentRootAccess, keys: input.documentStartNodeKeys },
|
|
438
|
-
media: { root: input.hasMediaRootAccess, keys: input.mediaStartNodeKeys },
|
|
439
|
-
element: { root: input.hasElementRootAccess, keys: input.elementStartNodeKeys },
|
|
440
|
-
}
|
|
441
|
-
for (const tree of ['document', 'media', 'element'] as const)
|
|
442
|
-
if (
|
|
443
|
-
!(await mayGrantStartNodes(
|
|
444
|
-
principal.startNodes[tree],
|
|
445
|
-
tree,
|
|
446
|
-
startNodes[tree],
|
|
447
|
-
user.startNodes[tree],
|
|
448
|
-
))
|
|
449
|
-
)
|
|
450
|
-
return 'Unauthorized'
|
|
417
|
+
if (!(await mayAssignGroups(principal, user, input.groupKeys))) return 'NotGroupOwner'
|
|
418
|
+
// Story 339: where a user works is their groups'; start nodes sent here are not kept.
|
|
451
419
|
const result = await users.update(key, {
|
|
452
420
|
name: input.name,
|
|
453
421
|
userName: input.userName,
|
|
454
422
|
email: input.email,
|
|
455
423
|
languageIsoCode: input.languageIsoCode || null,
|
|
456
424
|
groupKeys: input.groupKeys,
|
|
457
|
-
startNodes,
|
|
458
425
|
})
|
|
459
426
|
if (result === 'not-found') return 'UserNotFound'
|
|
460
427
|
if (result === 'missing-group') return 'MissingUserGroup'
|
|
461
|
-
if (result === 'document') return 'ContentStartNodeNotFound'
|
|
462
|
-
if (result === 'media') return 'MediaStartNodeNotFound'
|
|
463
|
-
if (result === 'element') return 'ElementStartNodeNotFound'
|
|
464
428
|
return 'Success'
|
|
465
429
|
},
|
|
466
430
|
|
|
@@ -503,7 +467,7 @@ export function createUserPorts(
|
|
|
503
467
|
if (!found) return 'UserNotFound'
|
|
504
468
|
if (!(await mayActOn(principal, found))) return 'Forbidden'
|
|
505
469
|
for (const user of found)
|
|
506
|
-
if (!(await mayAssignGroups(principal, user, groupKeys))) return '
|
|
470
|
+
if (!(await mayAssignGroups(principal, user, groupKeys))) return 'NotGroupOwner'
|
|
507
471
|
return (await users.setGroups(userKeys, groupKeys)) ? 'Success' : 'MissingUserGroup'
|
|
508
472
|
},
|
|
509
473
|
|
|
@@ -805,7 +769,8 @@ function sameFileFields(a: SchemaUserGroup, b: SchemaUserGroup): boolean {
|
|
|
805
769
|
sameMembers(a.permissions, b.permissions) &&
|
|
806
770
|
(a.languages === 'all' || b.languages === 'all'
|
|
807
771
|
? a.languages === b.languages
|
|
808
|
-
: sameMembers(a.languages, b.languages))
|
|
772
|
+
: sameMembers(a.languages, b.languages)) &&
|
|
773
|
+
(a.owners === undefined || b.owners === undefined || sameMembers(a.owners, b.owners))
|
|
809
774
|
)
|
|
810
775
|
}
|
|
811
776
|
|
|
@@ -842,16 +807,26 @@ function createUserGroupPort(
|
|
|
842
807
|
elementRootAccess: group.startNodes.element.root,
|
|
843
808
|
fallbackPermissions: group.permissions,
|
|
844
809
|
permissions: toPermissions(group.granular),
|
|
810
|
+
owners: group.owners.map((id) => ({ id })),
|
|
845
811
|
})
|
|
846
812
|
|
|
847
813
|
const isMember = (principal: Principal, key: string) =>
|
|
848
|
-
principal.
|
|
814
|
+
principal.groupKeys.map(normaliseUuid).includes(normaliseUuid(key))
|
|
815
|
+
/** Story 302: the members of any of a group's owners choose who is in it. */
|
|
816
|
+
const owns = async (principal: Principal, key: string) =>
|
|
817
|
+
principal.isAdmin || (await groups.ownedBy(principal.groupKeys)).includes(normaliseUuid(key))
|
|
818
|
+
const maySee = async (principal: Principal, key: string) =>
|
|
819
|
+
isMember(principal, key) || (await owns(principal, key))
|
|
820
|
+
|
|
821
|
+
/** Only the admin group and a group holding a remote verb may not have owners. */
|
|
822
|
+
const ownable = (alias: string, permissions: readonly string[]) =>
|
|
823
|
+
alias.toLowerCase() !== ADMIN_GROUP_ALIAS && !permissions.some(isRemotePermission)
|
|
849
824
|
|
|
850
825
|
/** Umbraco's `UserGroupService.ValidateAccess` and input rules for create and update. */
|
|
851
826
|
const validate = async (
|
|
852
827
|
principal: Principal,
|
|
853
828
|
input: UserGroupInput,
|
|
854
|
-
existing?: { key: string; alias: string },
|
|
829
|
+
existing?: { key: string; alias: string; owners: string[] },
|
|
855
830
|
): Promise<UserGroupStatus> => {
|
|
856
831
|
if (!input.name) return 'MissingName'
|
|
857
832
|
if (input.name.length > 200) return 'NameTooLong'
|
|
@@ -860,25 +835,14 @@ function createUserGroupPort(
|
|
|
860
835
|
return 'CanNotUpdateAliasIsSystemUserGroup'
|
|
861
836
|
const clash = await groups.byAlias(input.alias)
|
|
862
837
|
if (clash && clash.key !== existing?.key) return 'DuplicateAlias'
|
|
863
|
-
|
|
864
|
-
if (!
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
['media', input.mediaStartNode],
|
|
872
|
-
] as const) {
|
|
873
|
-
if (!key) continue
|
|
874
|
-
const found = await (tree === 'media'
|
|
875
|
-
? deps.nodes.media([key])
|
|
876
|
-
: deps.nodes.documents([key]))
|
|
877
|
-
const node = found.get(normaliseUuid(key))
|
|
878
|
-
if (node && !hasPathAccess(principal.startNodes[tree], node.chain, node.trashed))
|
|
879
|
-
return 'Unauthorized'
|
|
880
|
-
}
|
|
881
|
-
}
|
|
838
|
+
// Story 302: what a group grants is an administrator's to decide.
|
|
839
|
+
if (!principal.isAdmin) return 'AdministratorsOnly'
|
|
840
|
+
const owners = input.owners ?? existing?.owners ?? []
|
|
841
|
+
if (owners.length > 0 && !ownable(input.alias, input.fallbackPermissions))
|
|
842
|
+
return 'CannotBeOwned'
|
|
843
|
+
const self = normaliseUuid(existing?.key ?? input.key ?? '')
|
|
844
|
+
const others = [...new Set(input.owners?.map(normaliseUuid) ?? [])].filter((k) => k !== self)
|
|
845
|
+
if ((await groups.byKeys(others)).length !== others.length) return 'OwnerNotFound'
|
|
882
846
|
return 'Success'
|
|
883
847
|
}
|
|
884
848
|
|
|
@@ -959,8 +923,10 @@ function createUserGroupPort(
|
|
|
959
923
|
async filter(principal, filter, skip, take) {
|
|
960
924
|
const admin = await deps.adminKey()
|
|
961
925
|
const text = filter.toLowerCase()
|
|
926
|
+
// Story 302: anyone else is offered the groups they own, the ones they may hand out.
|
|
927
|
+
const owned = principal.isAdmin ? [] : await groups.ownedBy(principal.groupKeys)
|
|
962
928
|
const list = (await groups.all())
|
|
963
|
-
.filter((g) => principal.isAdmin || (g.key !== admin &&
|
|
929
|
+
.filter((g) => principal.isAdmin || (g.key !== admin && owned.includes(g.key)))
|
|
964
930
|
.filter((g) => !text || g.name.toLowerCase().includes(text))
|
|
965
931
|
return page(list, skip, take)
|
|
966
932
|
},
|
|
@@ -968,8 +934,8 @@ function createUserGroupPort(
|
|
|
968
934
|
async get(principal, key) {
|
|
969
935
|
const group = await groups.byKey(key)
|
|
970
936
|
if (!group) return 'NotFound'
|
|
971
|
-
if (!
|
|
972
|
-
return toResponse(group)
|
|
937
|
+
if (!principal.isAdmin && !(await maySee(principal, group.key))) return 'Forbidden'
|
|
938
|
+
return { ...(await toResponse(group)), canManageMembers: await owns(principal, group.key) }
|
|
973
939
|
},
|
|
974
940
|
|
|
975
941
|
async items(keys) {
|
|
@@ -983,33 +949,38 @@ function createUserGroupPort(
|
|
|
983
949
|
},
|
|
984
950
|
|
|
985
951
|
async create(principal, input) {
|
|
986
|
-
const valid = await validate(principal, input)
|
|
987
|
-
if (valid !== 'Success') return { status: valid }
|
|
988
952
|
const key = normaliseUuid(input.key ?? crypto.randomUUID())
|
|
953
|
+
const valid = await validate(principal, { ...input, key })
|
|
954
|
+
if (valid !== 'Success') return { status: valid }
|
|
989
955
|
if (await groups.byKey(key)) return { status: 'DuplicateAlias' }
|
|
990
956
|
const saved = await save(input, key)
|
|
991
957
|
if (saved !== 'Success') return { status: saved }
|
|
958
|
+
if (input.owners?.length) await groups.setOwners(key, input.owners)
|
|
992
959
|
await announcePermissions(principal, new Map(), key)
|
|
993
|
-
// A non-admin who creates a group joins it, as in Umbraco
|
|
994
|
-
if (!principal.isAdmin) await users.addToGroup(key, [principal.id])
|
|
995
960
|
return { status: 'Success', key }
|
|
996
961
|
},
|
|
997
962
|
|
|
998
963
|
async update(principal, key, input) {
|
|
999
964
|
const group = await groups.byKey(key)
|
|
1000
965
|
if (!group) return 'NotFound'
|
|
1001
|
-
if (!isMember(principal, group.key)) return 'Forbidden'
|
|
1002
966
|
const valid = await validate(principal, input, group)
|
|
1003
967
|
if (valid !== 'Success') return valid
|
|
1004
968
|
// Story 228: its file owns what it is; where it starts is this environment's.
|
|
1005
969
|
const file = fileOf(group.alias)
|
|
1006
970
|
const owned = fileFieldsOf(input)
|
|
971
|
+
// Owners are the file's only when it names them; otherwise this environment's.
|
|
972
|
+
if (file?.owners !== undefined) {
|
|
973
|
+
const keys = input.owners ?? group.owners
|
|
974
|
+
const byKey = new Map((await groups.byKeys(keys)).map((g) => [g.key, g.alias]))
|
|
975
|
+
owned.owners = keys.map((k) => byKey.get(normaliseUuid(k)) ?? group.alias)
|
|
976
|
+
}
|
|
1007
977
|
const rewrite = file !== undefined && !sameFileFields(owned, file)
|
|
1008
978
|
if (file && (input.alias !== group.alias || (rewrite && !deps.declared?.().writable)))
|
|
1009
979
|
return 'DeclaredInFiles'
|
|
1010
980
|
const before = pageVerbs(group)
|
|
1011
981
|
const saved = await save(input, group.key)
|
|
1012
982
|
if (saved === 'Success') {
|
|
983
|
+
if (input.owners) await groups.setOwners(group.key, input.owners)
|
|
1013
984
|
if (rewrite) deps.declared?.().write(owned)
|
|
1014
985
|
await announcePermissions(principal, before, group.key)
|
|
1015
986
|
}
|
|
@@ -1019,7 +990,7 @@ function createUserGroupPort(
|
|
|
1019
990
|
async delete(principal, keys) {
|
|
1020
991
|
const found = await groups.byKeys(keys)
|
|
1021
992
|
if (found.length !== new Set(keys.map(normaliseUuid)).size) return 'NotFound'
|
|
1022
|
-
if (!
|
|
993
|
+
if (!principal.isAdmin) return 'AdministratorsOnly'
|
|
1023
994
|
if (found.some((g) => SYSTEM_GROUPS.has(g.alias))) return 'IsSystemUserGroup'
|
|
1024
995
|
if (found.some((g) => fileOf(g.alias))) return 'DeclaredInFiles'
|
|
1025
996
|
for (const group of found) await groups.delete(group.key)
|
|
@@ -1029,7 +1000,7 @@ function createUserGroupPort(
|
|
|
1029
1000
|
async addUsers(principal, key, userKeys) {
|
|
1030
1001
|
const group = await groups.byKey(key)
|
|
1031
1002
|
if (!group) return 'NotFound'
|
|
1032
|
-
if (!
|
|
1003
|
+
if (!(await owns(principal, group.key))) return 'NotGroupOwner'
|
|
1033
1004
|
if ((await users.byKeys(userKeys)).length !== new Set(userKeys.map(normaliseUuid)).size)
|
|
1034
1005
|
return 'UserNotFound'
|
|
1035
1006
|
await users.addToGroup(group.key, userKeys)
|
|
@@ -1039,7 +1010,7 @@ function createUserGroupPort(
|
|
|
1039
1010
|
async removeUsers(principal, key, userKeys) {
|
|
1040
1011
|
const group = await groups.byKey(key)
|
|
1041
1012
|
if (!group) return 'NotFound'
|
|
1042
|
-
if (!
|
|
1013
|
+
if (!(await owns(principal, group.key))) return 'NotGroupOwner'
|
|
1043
1014
|
if ((await users.byKeys(userKeys)).length !== new Set(userKeys.map(normaliseUuid)).size)
|
|
1044
1015
|
return 'UserNotFound'
|
|
1045
1016
|
if (await adminWouldBeEmpty(group.key, userKeys)) return 'AdminGroupCannotBeEmpty'
|
package/src/bundle-admin.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
import { describeProvenance, type ProvenancePolicy } from './provenance.ts'
|
|
50
50
|
import { markRestartPending, type RestartPending, restartPending } from './restart-pending.ts'
|
|
51
51
|
import { sealSecret } from './secrets.ts'
|
|
52
|
+
import { signerTrusted } from './site-trust.ts'
|
|
52
53
|
import { MASKED } from './webhooks.ts'
|
|
53
54
|
|
|
54
55
|
/** Who acted, and from where, for the audit log. */
|
|
@@ -165,7 +166,8 @@ export function createBundleAdmin(options: {
|
|
|
165
166
|
config: CromboloConfig
|
|
166
167
|
marketplace: Marketplace
|
|
167
168
|
extensions: Pick<ExtensionRegistry, 'bundles'>
|
|
168
|
-
bundleGrants: Pick<BundleGrants, 'disable' | 'enable' | 'grant' | 'state' | 'forget'>
|
|
169
|
+
bundleGrants: Pick<BundleGrants, 'disable' | 'enable' | 'grant' | 'state' | 'forget'> &
|
|
170
|
+
Partial<Pick<BundleGrants, 'granted'>>
|
|
169
171
|
/** Granted extensions that could not start, and why (story 311). */
|
|
170
172
|
failed?: () => readonly { id: string; reason: string }[]
|
|
171
173
|
/** Stops an extension's running process, where this node runs one (story 328). */
|
|
@@ -545,6 +547,23 @@ export function createBundleAdmin(options: {
|
|
|
545
547
|
ok: false,
|
|
546
548
|
message: `No installed extension with a server half is called "${id}".`,
|
|
547
549
|
}
|
|
550
|
+
// Story 335: turning on an upper level is granting it again, held to the same rule.
|
|
551
|
+
if (enabled) {
|
|
552
|
+
const level = levelOf(bundleGrants.granted?.(pkg.id) ?? [])
|
|
553
|
+
if (isUpperLevel(level)) {
|
|
554
|
+
const provenance = (await marketplace.installed()).find(
|
|
555
|
+
(item) => item.id === pkg.id,
|
|
556
|
+
)?.provenance
|
|
557
|
+
const refused = grantRefusal({
|
|
558
|
+
level,
|
|
559
|
+
grants: true,
|
|
560
|
+
isAdmin: actor.isAdmin,
|
|
561
|
+
provenance,
|
|
562
|
+
from: config.unrestrictedExtensions ?? 'backoffice',
|
|
563
|
+
})
|
|
564
|
+
if (refused) return { status: 403, ok: false, message: `${pkg.name}: ${refused}` }
|
|
565
|
+
}
|
|
566
|
+
}
|
|
548
567
|
const state = enabled
|
|
549
568
|
? await bundleGrants.enable(pkg)
|
|
550
569
|
: await bundleGrants.disable(pkg, actor.email ?? actor.name)
|
|
@@ -588,6 +607,7 @@ export async function localBundleAdmin(
|
|
|
588
607
|
keyword: config.packageKeyword,
|
|
589
608
|
marketplaceUrl: config.marketplaceUrl,
|
|
590
609
|
componentsDir: config.componentsDir,
|
|
610
|
+
trustSigner: (provenance) => signerTrusted(db, config, provenance),
|
|
591
611
|
extensions,
|
|
592
612
|
siteDir: config.siteDir,
|
|
593
613
|
grants: bundleGrants,
|
package/src/bundle-api.ts
CHANGED
|
@@ -140,9 +140,7 @@ export const sectionOfPermission = (permission: string): string | undefined => {
|
|
|
140
140
|
/** The verbs a set of permissions needs, for the API's own permission checks. */
|
|
141
141
|
function verbsOf(granted: ReadonlySet<string>): string[] {
|
|
142
142
|
const verbs = new Set<string>()
|
|
143
|
-
if (granted.has('content.read'))
|
|
144
|
-
for (const verb of [DocumentPermissions.Read, DocumentPermissions.PropertyValueRead])
|
|
145
|
-
verbs.add(verb)
|
|
143
|
+
if (granted.has('content.read')) verbs.add(DocumentPermissions.Read)
|
|
146
144
|
if (granted.has('content.write'))
|
|
147
145
|
for (const verb of Object.values(DocumentPermissions)) {
|
|
148
146
|
if (verb === DocumentPermissions.Permissions || verb === DocumentPermissions.PublicAccess)
|