@crombolo/server 0.62.0 → 0.64.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 +79 -12
- package/src/adapters/documents.ts +6 -2
- package/src/adapters/file-system.ts +27 -3
- package/src/adapters/schema-files.ts +19 -27
- package/src/adapters/template-files.ts +10 -0
- package/src/adapters/users.ts +55 -84
- package/src/approvals.ts +2 -2
- package/src/bundle-admin.ts +21 -1
- package/src/bundle-api.ts +1 -3
- package/src/bundle-install.ts +28 -5
- package/src/bundle-sections.ts +10 -0
- package/src/config.ts +32 -1
- package/src/content-notifications.ts +6 -3
- package/src/content-operations.ts +4 -3
- package/src/content-query.ts +2 -4
- package/src/core.ts +11 -3
- package/src/email-notice.ts +2 -2
- package/src/email-settings.ts +394 -0
- package/src/email.ts +9 -4
- package/src/form-workflows.ts +3 -3
- package/src/grant-policy.ts +23 -3
- package/src/grant-trust.ts +73 -0
- package/src/index.ts +3 -0
- package/src/marketplace.ts +14 -6
- package/src/ports.ts +37 -18
- package/src/provenance.ts +13 -1
- package/src/remote.ts +23 -8
- package/src/schema-transfer.ts +472 -0
- package/src/seed/values.ts +126 -85
- package/src/server.ts +116 -11
- package/src/settings.ts +9 -0
- package/src/site-public.ts +2 -1
- package/src/site-trust.ts +16 -0
- package/src/status.ts +3 -0
- package/src/telemetry.ts +9 -2
- package/src/transfer-dashboard.ts +3 -0
- package/src/zip.ts +86 -3
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/approvals.ts
CHANGED
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
UserGroupRepository,
|
|
48
48
|
} from '@crombolo/data'
|
|
49
49
|
import type { ContentNotifier } from './content-notifications.ts'
|
|
50
|
-
import type
|
|
50
|
+
import { type EmailPort, emailReady } from './email.ts'
|
|
51
51
|
|
|
52
52
|
/** What publishing and unpublishing go through when approval says yes. */
|
|
53
53
|
export interface ApprovalPublisher {
|
|
@@ -388,7 +388,7 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
388
388
|
subject: string,
|
|
389
389
|
body: string,
|
|
390
390
|
) => {
|
|
391
|
-
if (!options.email) return
|
|
391
|
+
if (!emailReady(options.email)) return
|
|
392
392
|
let emails: string[] = []
|
|
393
393
|
if (to === 'editor') {
|
|
394
394
|
const rows = await db.q
|
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)
|
package/src/bundle-install.ts
CHANGED
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
carriedSections,
|
|
75
75
|
carriesSections,
|
|
76
76
|
changedFileSections,
|
|
77
|
+
componentChanges,
|
|
77
78
|
type FileAction,
|
|
78
79
|
keepDictionary,
|
|
79
80
|
keptDictionary,
|
|
@@ -324,10 +325,19 @@ export interface TransferInput extends SectionOptions {
|
|
|
324
325
|
* asked, as story 192 had it. Only where runtime installs are on.
|
|
325
326
|
*/
|
|
326
327
|
installCode?: boolean
|
|
328
|
+
/**
|
|
329
|
+
* Install the templates it adds or changes, which are code the server runs
|
|
330
|
+
* (story 336); `installCode` unless said. The Transfer dashboard asks for these
|
|
331
|
+
* alone, for a user given "Install code on this site".
|
|
332
|
+
*/
|
|
333
|
+
installTemplates?: boolean
|
|
327
334
|
/** Apply a site bundle older than one this site applied from the same signer (story 316). */
|
|
328
335
|
allowDowngrade?: boolean
|
|
329
336
|
}
|
|
330
337
|
|
|
338
|
+
/** Why a bundle's code, migrations or templates are refused where installs are off (story 336). */
|
|
339
|
+
export const RUNTIME_INSTALLS_OFF = 'installing code while the site runs is turned off on this site'
|
|
340
|
+
|
|
331
341
|
/**
|
|
332
342
|
* Who vouches for a bundle's source in place of a signer, given only by code in
|
|
333
343
|
* this process and never from a request (story 319):
|
|
@@ -769,10 +779,7 @@ export async function installBundleContent(
|
|
|
769
779
|
)
|
|
770
780
|
// The code half (story 241): only when asked, only where installs happen here.
|
|
771
781
|
const code = effective.installCode ? codeChanges(planCode(config, carried)) : []
|
|
772
|
-
|
|
773
|
-
config.installsElsewhere?.message ??
|
|
774
|
-
"this site does not install code while it runs: add the bundle's code to the site and deploy it"
|
|
775
|
-
if (code.length > 0 && !config.runtimeInstalls) return refuse([installsElsewhere], backup)
|
|
782
|
+
if (code.length > 0 && !config.runtimeInstalls) return refuse([RUNTIME_INSTALLS_OFF], backup)
|
|
776
783
|
// A bundle's value migrations are code too (story 300), unless they are the site's own.
|
|
777
784
|
const migrations =
|
|
778
785
|
vouch?.vouchedBy === 'site' || effective.withoutSchema ? [] : migrationChanges(config, carried)
|
|
@@ -780,12 +787,28 @@ export async function installBundleContent(
|
|
|
780
787
|
return refuse(
|
|
781
788
|
[
|
|
782
789
|
effective.installCode
|
|
783
|
-
?
|
|
790
|
+
? RUNTIME_INSTALLS_OFF
|
|
784
791
|
: 'this bundle brings schema migrations, which are code: install its code to bring them',
|
|
785
792
|
...migrations.map((file) => file.path),
|
|
786
793
|
],
|
|
787
794
|
backup,
|
|
788
795
|
)
|
|
796
|
+
// Templates are code as well (story 336): the server imports and runs them.
|
|
797
|
+
const templates =
|
|
798
|
+
vouch?.vouchedBy === 'site' || effective.withoutFiles ? [] : componentChanges(config, carried)
|
|
799
|
+
if (
|
|
800
|
+
templates.length > 0 &&
|
|
801
|
+
(!(effective.installTemplates ?? effective.installCode) || !config.runtimeInstalls)
|
|
802
|
+
)
|
|
803
|
+
return refuse(
|
|
804
|
+
[
|
|
805
|
+
config.runtimeInstalls
|
|
806
|
+
? 'this bundle adds or changes templates, which are code: installing them needs the permission to install code on this site'
|
|
807
|
+
: RUNTIME_INSTALLS_OFF,
|
|
808
|
+
...templates.map((file) => file.path),
|
|
809
|
+
],
|
|
810
|
+
backup,
|
|
811
|
+
)
|
|
789
812
|
const needingPermission = [
|
|
790
813
|
...(plan ? replacementsNeedingPermission(plan, effective) : []),
|
|
791
814
|
...(effective.replaceFiles ? [] : code.filter((file) => file.action === 'overwrite')),
|
package/src/bundle-sections.ts
CHANGED
|
@@ -140,6 +140,16 @@ export function migrationChanges(config: CromboloConfig, carried: CarriedSection
|
|
|
140
140
|
.filter((file) => file.action !== 'unchanged')
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/** The templates a bundle would add or change here: code the server runs (story 336). */
|
|
144
|
+
export function componentChanges(config: CromboloConfig, carried: CarriedSections): SectionFile[] {
|
|
145
|
+
return (carried.carries.components ?? [])
|
|
146
|
+
.map((path) => {
|
|
147
|
+
const target = join(config.componentsDir, withinSection(path, 'components'))
|
|
148
|
+
return { path, target, action: actionFor(target, sourceOf(carried, path)) }
|
|
149
|
+
})
|
|
150
|
+
.filter((file) => file.action !== 'unchanged')
|
|
151
|
+
}
|
|
152
|
+
|
|
143
153
|
/** Compared as bytes: a public file is an image as often as it is text. */
|
|
144
154
|
function actionFor(target: string, source: string): FileAction {
|
|
145
155
|
if (!existsSync(target)) return 'create'
|
package/src/config.ts
CHANGED
|
@@ -91,6 +91,25 @@ export interface RemoteSettings {
|
|
|
91
91
|
oidcIssuers?: string[]
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
export type ContentMode = 'development' | 'production'
|
|
95
|
+
|
|
96
|
+
/** `CROMBOLO_CONTENT_MODE`, refusing the switch it replaced so locked files never quietly unlock. */
|
|
97
|
+
function contentModeSetting(): ContentMode {
|
|
98
|
+
// Read directly: it is no longer a setting, only a name to refuse.
|
|
99
|
+
if (Bun.env.CROMBOLO_CONTENT_FILES_READONLY !== undefined)
|
|
100
|
+
throw new Error(
|
|
101
|
+
'CROMBOLO_CONTENT_FILES_READONLY has gone: set CROMBOLO_CONTENT_MODE to production to keep templates, stylesheets and scripts read-only, or to development (story 343).',
|
|
102
|
+
)
|
|
103
|
+
const value = (setting('CROMBOLO_CONTENT_MODE') ?? 'development').trim().toLowerCase()
|
|
104
|
+
if (value !== 'development' && value !== 'production')
|
|
105
|
+
throw new Error(`CROMBOLO_CONTENT_MODE is "${value}": it is development or production.`)
|
|
106
|
+
return value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Whether the back office must leave templates, stylesheets and scripts alone. */
|
|
110
|
+
export const contentFilesLocked = (config: Pick<CromboloConfig, 'contentMode'>) =>
|
|
111
|
+
config.contentMode === 'production'
|
|
112
|
+
|
|
94
113
|
/** `CROMBOLO_REMOTE_ACCESS`, refusing the switch it replaced so a site does not quietly stop being a remote. */
|
|
95
114
|
function remoteAccessSetting(): RemoteAccess {
|
|
96
115
|
// Read directly: it is no longer a setting, only a name to refuse.
|
|
@@ -341,6 +360,12 @@ export interface CromboloConfig {
|
|
|
341
360
|
* CROMBOLO_SCHEMA_WRITABLE says otherwise outright.
|
|
342
361
|
*/
|
|
343
362
|
schemaWritable: boolean
|
|
363
|
+
/**
|
|
364
|
+
* `production` keeps templates, stylesheets and scripts read-only in the back
|
|
365
|
+
* office, for a site whose files come from its repository (stories 337, 343).
|
|
366
|
+
* `development` unless set, in production too. `CROMBOLO_CONTENT_MODE`.
|
|
367
|
+
*/
|
|
368
|
+
contentMode: ContentMode
|
|
344
369
|
/** Sync `schema/` at boot; a pipeline that runs `crombolo types sync` turns this off. */
|
|
345
370
|
syncSchemaAtBoot: boolean
|
|
346
371
|
/** Which database engine; from CROMBOLO_DB. */
|
|
@@ -898,6 +923,7 @@ export function loadConfig(
|
|
|
898
923
|
? setting('CROMBOLO_SCHEMA_WRITABLE') === 'true'
|
|
899
924
|
: setting('NODE_ENV') !== 'production',
|
|
900
925
|
syncSchemaAtBoot: setting('CROMBOLO_SYNC_SCHEMA_AT_BOOT') !== 'false',
|
|
926
|
+
contentMode: contentModeSetting(),
|
|
901
927
|
dialect: setting('CROMBOLO_DB') === 'postgres' ? 'postgres' : 'sqlite',
|
|
902
928
|
pgDump: setting('CROMBOLO_PG_DUMP'),
|
|
903
929
|
upgradePolicy:
|
|
@@ -1050,6 +1076,11 @@ export function loadConfig(
|
|
|
1050
1076
|
host: undefined,
|
|
1051
1077
|
}
|
|
1052
1078
|
const merged: CromboloConfig = { ...fromEnv, ...stripUndefined(overrides) }
|
|
1079
|
+
// The file is checked as the environment is: an unknown mode must not fall back to editable.
|
|
1080
|
+
if (merged.contentMode !== 'development' && merged.contentMode !== 'production')
|
|
1081
|
+
throw new Error(
|
|
1082
|
+
`contentMode is "${String(merged.contentMode)}" in crombolo.config.ts: it is development or production.`,
|
|
1083
|
+
)
|
|
1053
1084
|
checkIdentityProviders(merged.memberIdentityProviders, 'member')
|
|
1054
1085
|
checkIdentityProviders(merged.backofficeIdentityProviders, 'backoffice')
|
|
1055
1086
|
// Field by field, so a site setting its title suffix keeps the environment's switches.
|
|
@@ -1193,7 +1224,7 @@ export function describeDatabase(
|
|
|
1193
1224
|
}
|
|
1194
1225
|
}
|
|
1195
1226
|
|
|
1196
|
-
export const VERSION = '0.
|
|
1227
|
+
export const VERSION = '0.64.0'
|
|
1197
1228
|
|
|
1198
1229
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1199
1230
|
/** A positive number from a setting, else the default. */
|
|
@@ -40,7 +40,7 @@ export interface Actor {
|
|
|
40
40
|
|
|
41
41
|
export interface ContentNotifierOptions {
|
|
42
42
|
/** False when the site cannot send e-mail: nothing is queued, and nothing piles up. */
|
|
43
|
-
canSend: boolean
|
|
43
|
+
canSend: boolean | (() => boolean)
|
|
44
44
|
delayMs?: number
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -82,6 +82,9 @@ const pathIds = (path: string): number[] =>
|
|
|
82
82
|
.filter((id) => Number.isFinite(id) && id > 0)
|
|
83
83
|
|
|
84
84
|
export function createContentNotifier(db: Db, options: ContentNotifierOptions): ContentNotifier {
|
|
85
|
+
// Asked each time: e-mail set up in Settings starts and stops without a restart (story 340).
|
|
86
|
+
const canSend = () =>
|
|
87
|
+
typeof options.canSend === 'function' ? options.canSend() : options.canSend
|
|
85
88
|
const factsFor: ContentNotifier['factsFor'] = async (on, change, actor, detail) => {
|
|
86
89
|
const nodes = new NodeRepository(on)
|
|
87
90
|
const documents = new DocumentRepository(on)
|
|
@@ -126,7 +129,7 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
126
129
|
|
|
127
130
|
const enqueueFor: ContentNotifier['enqueueFor'] = async (on, eventId, facts) => {
|
|
128
131
|
// A site that cannot send e-mail queues nothing, so nothing piles up.
|
|
129
|
-
if (!
|
|
132
|
+
if (!canSend()) return
|
|
130
133
|
const subscriptions = new NotificationRepository(on)
|
|
131
134
|
const actorId = facts.actorUserKey
|
|
132
135
|
? (await new UserRepository(on).byKey(facts.actorUserKey))?.id
|
|
@@ -165,7 +168,7 @@ export function createContentNotifier(db: Db, options: ContentNotifierOptions):
|
|
|
165
168
|
factsFor,
|
|
166
169
|
enqueueFor,
|
|
167
170
|
async raise(change, actor, detail) {
|
|
168
|
-
if (!
|
|
171
|
+
if (!canSend()) return
|
|
169
172
|
try {
|
|
170
173
|
const facts = await factsFor(db, change, actor, detail)
|
|
171
174
|
if (facts) await enqueueFor(db, undefined, facts)
|
|
@@ -14,7 +14,8 @@ import { backOfficeUrl } from './back-office-url.ts'
|
|
|
14
14
|
import type { CromboloConfig } from './config.ts'
|
|
15
15
|
import { createContentEventSink } from './content-events.ts'
|
|
16
16
|
import { createContentNotifier } from './content-notifications.ts'
|
|
17
|
-
import {
|
|
17
|
+
import { emailReady } from './email.ts'
|
|
18
|
+
import { siteEmail } from './email-settings.ts'
|
|
18
19
|
import { MediaFileStore, mediaStoreFor } from './media-files.ts'
|
|
19
20
|
import { createNodeOperations } from './node-operations.ts'
|
|
20
21
|
import { createWebhookService } from './webhooks.ts'
|
|
@@ -31,8 +32,8 @@ export async function siteDocumentOperations(
|
|
|
31
32
|
): Promise<SiteOperations> {
|
|
32
33
|
const state = await currentSchemaState(db)
|
|
33
34
|
const nodeState = { version: state.version, revision: state.revision }
|
|
34
|
-
const email =
|
|
35
|
-
const notifier = createContentNotifier(db, { canSend:
|
|
35
|
+
const email = await siteEmail(db, config)
|
|
36
|
+
const notifier = createContentNotifier(db, { canSend: () => emailReady(email) })
|
|
36
37
|
const webhooks = createWebhookService({
|
|
37
38
|
db,
|
|
38
39
|
schemaDir: config.schemaDir,
|
package/src/content-query.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
DocumentPermissions,
|
|
10
10
|
type GroupGrant,
|
|
11
11
|
permissionsForPath,
|
|
12
|
-
propertyValuePermissions,
|
|
13
12
|
ROOT_ACCESS,
|
|
14
13
|
} from '@crombolo/core'
|
|
15
14
|
import {
|
|
@@ -37,9 +36,8 @@ export function contentQueryScope(principal: Principal): QueryScope {
|
|
|
37
36
|
principal.isAdmin || browsesEverything(groups)
|
|
38
37
|
? undefined
|
|
39
38
|
: (chain) => permissionsForPath(groups, chain).has(DocumentPermissions.Read),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
propertyValuePermissions(groups, key).has(DocumentPermissions.PropertyValueRead),
|
|
39
|
+
// Story 338: a field is never hidden from someone who may see the page.
|
|
40
|
+
readsProperty: () => true,
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
package/src/core.ts
CHANGED
|
@@ -66,7 +66,8 @@ import { createContentNotificationRunner, createContentNotifier } from './conten
|
|
|
66
66
|
import { databaseFor, openTables, siteTablesProblems, tablesChains } from './custom-tables.ts'
|
|
67
67
|
import { attachDatabase, bootstrapDatabase } from './database.ts'
|
|
68
68
|
import { createDiagnostics } from './diagnostics.ts'
|
|
69
|
-
import {
|
|
69
|
+
import { emailReady } from './email.ts'
|
|
70
|
+
import { siteEmail } from './email-settings.ts'
|
|
70
71
|
import { createActivityRecorder, personOf, timed } from './extension-activity.ts'
|
|
71
72
|
import { createExtensionComponents } from './extension-components.ts'
|
|
72
73
|
import {
|
|
@@ -78,6 +79,7 @@ import {
|
|
|
78
79
|
import { createFormRegistry, formSigningSecret, signFormToken } from './form-submit.ts'
|
|
79
80
|
import { formTypesOf } from './form-types.ts'
|
|
80
81
|
import { createWorkflowRunner } from './form-workflows.ts'
|
|
82
|
+
import { switchOffUntrusted } from './grant-trust.ts'
|
|
81
83
|
import {
|
|
82
84
|
createBundleIdentityProviders,
|
|
83
85
|
IdentityProviderOverrides,
|
|
@@ -341,6 +343,11 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
341
343
|
detail: `narrowed to what it asks for: ${declaredPermissions(pkg).join(', ') || 'nothing'}`,
|
|
342
344
|
source: 'boot',
|
|
343
345
|
})
|
|
346
|
+
// Story 335: before any extension runs, one nobody this site trusts vouches for loses its upper level.
|
|
347
|
+
if (owns)
|
|
348
|
+
await switchOffUntrusted(db, config, extensions, bundleGrants).catch((error: unknown) =>
|
|
349
|
+
log.error('Checking who vouches for extensions failed: {error}', { error: String(error) }),
|
|
350
|
+
)
|
|
344
351
|
// A configured schema store is copied down before anything reads `schema/`, and
|
|
345
352
|
// becomes the schema directory for this boot. Everything after here — loading,
|
|
346
353
|
// validation, hashing, sync, the writer — works on files exactly as it always has.
|
|
@@ -486,10 +493,11 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
486
493
|
)
|
|
487
494
|
// Resolved once: constructing it twice would warn twice about a provider that
|
|
488
495
|
// is half-configured, and the adapters are cheap but not free of side effects.
|
|
489
|
-
|
|
496
|
+
// Story 340: the config's, or one that follows Settings without a restart.
|
|
497
|
+
const email = tracedEmail(await siteEmail(db, config))
|
|
490
498
|
// Story 045: a change queues the e-mails its subscribers asked for. Nothing is
|
|
491
499
|
// queued on a site that cannot send; development sends to the console.
|
|
492
|
-
const notifier = createContentNotifier(db, { canSend:
|
|
500
|
+
const notifier = createContentNotifier(db, { canSend: () => emailReady(email) })
|
|
493
501
|
const mediaFiles = new MediaFileStore(mediaStore)
|
|
494
502
|
const webhooks = createWebhookService({
|
|
495
503
|
db,
|