@crombolo/api-management 0.69.0 → 0.70.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/api-management",
3
- "version": "0.69.0",
3
+ "version": "0.70.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Umbraco-compatible Management API handlers for crombolo.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -29,8 +29,8 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@crombolo/content": "0.69.0",
33
- "@crombolo/contracts": "0.69.0",
34
- "@crombolo/core": "0.69.0"
32
+ "@crombolo/content": "0.70.0",
33
+ "@crombolo/contracts": "0.70.0",
34
+ "@crombolo/core": "0.70.0"
35
35
  }
36
36
  }
@@ -71,6 +71,10 @@ export interface NodeLookup {
71
71
  type Sections = readonly AppAlias[]
72
72
 
73
73
  const CONTENT: Sections = ['content']
74
+ /** The places under Content (story 385): Pages, Structure and Code each a grant of its own. */
75
+ const PAGES: Sections = ['pages']
76
+ const STRUCTURE: Sections = ['structure']
77
+ const CODE: Sections = ['components']
74
78
  const MEDIA: Sections = ['media']
75
79
  const SETTINGS: Sections = ['settings']
76
80
  const USERS: Sections = ['users']
@@ -78,22 +82,32 @@ const MEMBERS: Sections = ['members']
78
82
  const TRANSLATION: Sections = ['translation']
79
83
  const LIBRARY: Sections = ['library']
80
84
  /** SectionAccessFor{Content,Media,Element}Tree: pickers open these trees from anywhere. */
81
- const ANY_TREE: Sections = ['content', 'media', 'users', 'settings', 'members', 'library']
85
+ const ANY_TREE: Sections = [
86
+ 'content',
87
+ 'pages',
88
+ 'media',
89
+ 'users',
90
+ 'settings',
91
+ 'structure',
92
+ 'components',
93
+ 'members',
94
+ 'library',
95
+ ]
82
96
 
83
97
  const TREES: Record<string, Sections> = {
84
98
  document: ANY_TREE,
85
99
  media: ANY_TREE,
86
100
  element: ANY_TREE,
87
- 'document-type': SETTINGS,
88
- 'document-blueprint': SETTINGS,
89
- 'data-type': SETTINGS,
90
- 'media-type': SETTINGS,
91
- 'member-type': ['settings', 'members'],
92
- template: ['settings', 'content'],
101
+ 'document-type': STRUCTURE,
102
+ 'document-blueprint': STRUCTURE,
103
+ 'data-type': STRUCTURE,
104
+ 'media-type': STRUCTURE,
105
+ 'member-type': ['structure', 'members'],
106
+ template: ['components', 'content'],
93
107
  dictionary: ['translation', 'settings'],
94
- 'partial-view': SETTINGS,
95
- script: SETTINGS,
96
- stylesheet: SETTINGS,
108
+ 'partial-view': CODE,
109
+ script: CODE,
110
+ stylesheet: CODE,
97
111
  'relation-type': SETTINGS,
98
112
  'static-file': ['settings', 'content', 'media', 'members'],
99
113
  'member-group': MEMBERS,
@@ -111,11 +125,11 @@ const SETTINGS_AREAS = new Set([
111
125
  'telemetry',
112
126
  'webhook',
113
127
  'relation-type',
114
- 'partial-view',
115
- 'script',
116
- 'stylesheet',
117
128
  ])
118
129
 
130
+ /** Code's areas (story 385): what Settings held for components before. */
131
+ const CODE_AREAS = new Set(['partial-view', 'script', 'stylesheet'])
132
+
119
133
  /** Type actions only the Settings section may take, beyond every write. */
120
134
  const TYPE_ADMIN_ACTIONS = new Set([
121
135
  'configuration',
@@ -142,57 +156,59 @@ export function sectionRequirements(operation: OperationInfo): Array<Sections |
142
156
  const action = second.startsWith('{') ? third : second
143
157
  const typeAdmin = write || TYPE_ADMIN_ACTIONS.has(action)
144
158
  if (SETTINGS_AREAS.has(area)) return [SETTINGS]
159
+ if (CODE_AREAS.has(area)) return [CODE]
145
160
  switch (area) {
146
161
  case 'tree':
147
162
  return TREES[second] ? [TREES[second]] : []
148
163
  case 'recycle-bin':
149
- return [second === 'media' ? MEDIA : second === 'element' ? LIBRARY : CONTENT]
164
+ return [second === 'media' ? MEDIA : second === 'element' ? LIBRARY : PAGES]
150
165
  case 'collection':
151
- return [second === 'media' ? MEDIA : CONTENT]
166
+ return [second === 'media' ? MEDIA : PAGES]
152
167
  case 'filter':
153
- if (second === 'data-type') return [['content', 'settings']]
168
+ if (second === 'data-type') return [['content', 'structure']]
154
169
  if (second === 'user' || second === 'user-group') return [USERS]
155
170
  if (second === 'member') return [MEMBERS]
156
171
  return []
157
172
  case 'redirect-management':
158
173
  // Tracking on or off is a setting for the whole site, not an edit to content
159
- return second === 'status' && write ? [SETTINGS] : [CONTENT]
174
+ return second === 'status' && write ? [SETTINGS] : [PAGES]
160
175
  case 'document':
161
176
  case 'document-version':
177
+ return [PAGES]
162
178
  case 'relation':
163
179
  case 'oembed':
164
180
  case 'dynamic-root':
165
181
  return [CONTENT]
166
182
  case 'document-type':
167
- if (second === 'folder') return [SETTINGS]
168
- if (third === 'blueprint') return [['content', 'library', 'settings'], CONTENT]
183
+ if (second === 'folder') return [STRUCTURE]
184
+ if (third === 'blueprint') return [['content', 'library', 'structure'], CONTENT]
169
185
  return typeAdmin
170
- ? [['content', 'library', 'settings'], SETTINGS]
171
- : [['content', 'library', 'settings']]
186
+ ? [['content', 'library', 'structure'], STRUCTURE]
187
+ : [['content', 'library', 'structure']]
172
188
  case 'document-blueprint':
173
189
  if (second === 'from-document' || third === 'scaffold') return [CONTENT]
174
- if (!write && second.startsWith('{') && third === '') return [['content', 'settings']]
175
- return [SETTINGS]
190
+ if (!write && second.startsWith('{') && third === '') return [['content', 'structure']]
191
+ return [STRUCTURE]
176
192
  case 'data-type':
177
- if (second === 'folder') return [SETTINGS]
193
+ if (second === 'folder') return [STRUCTURE]
178
194
  return typeAdmin
179
- ? [['content', 'library', 'media', 'members', 'settings'], SETTINGS]
180
- : [['content', 'library', 'media', 'members', 'settings']]
195
+ ? [['content', 'library', 'media', 'members', 'structure'], STRUCTURE]
196
+ : [['content', 'library', 'media', 'members', 'structure']]
181
197
  case 'media':
182
198
  return [MEDIA]
183
199
  case 'media-type':
184
- if (second === 'folder') return [SETTINGS]
185
- return typeAdmin ? [['media', 'settings'], SETTINGS] : [['media', 'settings']]
200
+ if (second === 'folder') return [STRUCTURE]
201
+ return typeAdmin ? [['media', 'structure'], STRUCTURE] : [['media', 'structure']]
186
202
  case 'member-type':
187
- if (second === 'folder') return [SETTINGS]
188
- return typeAdmin ? [['settings', 'members'], SETTINGS] : [['settings', 'members']]
203
+ if (second === 'folder') return [STRUCTURE]
204
+ return typeAdmin ? [['structure', 'members'], STRUCTURE] : [['structure', 'members']]
189
205
  case 'member':
190
206
  case 'member-group':
191
207
  return [MEMBERS]
192
208
  case 'template':
193
- return write ? [['settings', 'content'], SETTINGS] : [['settings', 'content']]
209
+ return write ? [['components', 'content'], CODE] : [['components', 'content']]
194
210
  case 'language':
195
- return write ? [SETTINGS] : []
211
+ return write ? [STRUCTURE] : []
196
212
  case 'dictionary':
197
213
  return [TRANSLATION]
198
214
  case 'user':
@@ -473,6 +489,21 @@ export function canReadDocumentAt(
473
489
  return permissionsForPath(principal.groups, chain).has(D.Read)
474
490
  }
475
491
 
492
+ /**
493
+ * Whether the caller holds every verb on a document at a place, its ancestors'
494
+ * keys then its own: what a workspace's merge checks for each change (story 380). Pure.
495
+ */
496
+ export function mayDocumentAt(
497
+ principal: Principal,
498
+ chain: readonly string[],
499
+ verbs: readonly string[],
500
+ ): boolean {
501
+ if (!hasSection(principal, 'content') || !hasSection(principal, 'pages')) return false
502
+ if (!hasPathAccess(principal.startNodes.document, chain, false)) return false
503
+ const granted = permissionsForPath(principal.groups, chain)
504
+ return verbs.every((v) => granted.has(v))
505
+ }
506
+
476
507
  /**
477
508
  * What a token exchanged through a provider may not do (story 364): set or
478
509
  * reset a password, change two-factor sign-in, or make an API key, any of
@@ -69,3 +69,331 @@ export const ELEMENT_WRITE_OPERATIONS: ReadonlySet<string> = new Set([
69
69
  'PutElementFolderByIdMove',
70
70
  'PutElementFolderByIdMoveToRecycleBin',
71
71
  ])
72
+
73
+ /**
74
+ * The operations a workspace changes the answer to (story 375): a page read in
75
+ * it is the workspace's, and a write lands there. The `Crombolo-Workspace`
76
+ * header is honoured on these.
77
+ */
78
+ export const WORKSPACE_OPERATIONS: ReadonlySet<string> = new Set([
79
+ // Story 392: blueprints, held as pages are; their folders are Shared's.
80
+ 'PostDocumentBlueprint',
81
+ 'GetDocumentBlueprintById',
82
+ 'PutDocumentBlueprintById',
83
+ 'DeleteDocumentBlueprintById',
84
+ 'GetDocumentBlueprintByIdScaffold',
85
+ 'PostDocumentBlueprintFromDocument',
86
+ 'GetItemDocumentBlueprint',
87
+ 'GetTreeDocumentBlueprintAncestors',
88
+ 'GetTreeDocumentBlueprintChildren',
89
+ 'GetTreeDocumentBlueprintRoot',
90
+ 'GetTreeDocumentBlueprintSiblings',
91
+ 'GetDocumentTypeByIdBlueprint',
92
+ // Story 392: the form and workflow designers (Crombolo's own routes), in a workspace's copy.
93
+ 'CromboloFormDesigner',
94
+ 'CromboloWorkflowDesigner',
95
+ // Story 392: the languages and dictionary a workspace holds, read and changed there.
96
+ 'GetLanguage',
97
+ 'GetLanguageByIsoCode',
98
+ 'GetItemLanguage',
99
+ 'GetItemLanguageDefault',
100
+ 'PostLanguage',
101
+ 'PutLanguageByIsoCode',
102
+ 'DeleteLanguageByIsoCode',
103
+ 'GetDictionary',
104
+ 'GetDictionaryById',
105
+ 'PostDictionary',
106
+ 'PutDictionaryById',
107
+ 'DeleteDictionaryById',
108
+ 'PutDictionaryByIdMove',
109
+ 'GetItemDictionary',
110
+ 'GetTreeDictionaryRoot',
111
+ 'GetTreeDictionaryChildren',
112
+ 'GetTreeDictionaryAncestors',
113
+ 'GetDocumentById',
114
+ 'GetItemDocument',
115
+ 'GetTreeDocumentRoot',
116
+ 'GetTreeDocumentChildren',
117
+ 'GetTreeDocumentAncestors',
118
+ 'GetTreeDocumentSiblings',
119
+ 'PostDocument',
120
+ 'PutDocumentById',
121
+ 'PatchDocumentByIdPatch',
122
+ 'PostDocumentCreateAndPublish',
123
+ 'PutDocumentByIdUpdateAndPublish',
124
+ 'PutDocumentByIdPublish',
125
+ 'PutDocumentByIdUnpublish',
126
+ 'PutDocumentByIdMoveToRecycleBin',
127
+ 'DeleteDocumentById',
128
+ 'PutDocumentByIdMove',
129
+ 'PutDocumentSort',
130
+ 'PutDocumentByIdSortChildren',
131
+ 'PutDocumentRootSortChildren',
132
+ // Story 390: its media and Library items, made and changed as its pages are.
133
+ 'PostMedia',
134
+ 'PutMediaById',
135
+ 'DeleteMediaById',
136
+ 'PutMediaByIdMoveToRecycleBin',
137
+ 'PutMediaByIdMove',
138
+ 'PutMediaSort',
139
+ 'PutMediaByIdSortChildren',
140
+ 'PutMediaRootSortChildren',
141
+ 'GetMediaById',
142
+ 'GetItemMedia',
143
+ 'GetCollectionMedia',
144
+ 'GetTreeMediaRoot',
145
+ 'GetTreeMediaChildren',
146
+ 'GetTreeMediaAncestors',
147
+ 'GetTreeMediaSiblings',
148
+ 'PostElement',
149
+ 'PutElementById',
150
+ 'PostElementCreateAndPublish',
151
+ 'PutElementByIdUpdateAndPublish',
152
+ 'PutElementByIdPublish',
153
+ 'PutElementByIdUnpublish',
154
+ 'PutElementByIdMove',
155
+ 'PutElementByIdMoveToRecycleBin',
156
+ 'GetElementById',
157
+ 'GetItemElement',
158
+ 'GetTreeElementRoot',
159
+ 'GetTreeElementChildren',
160
+ 'GetTreeElementAncestors',
161
+ 'GetTreeElementSiblings',
162
+ // Story 377: its components, stylesheets and scripts, read and written in its own copy.
163
+ 'PostPartialView',
164
+ 'GetPartialViewByPath',
165
+ 'PutPartialViewByPath',
166
+ 'DeletePartialViewByPath',
167
+ 'PutPartialViewByPathRename',
168
+ 'GetPartialViewFolderByPath',
169
+ 'GetTreePartialViewRoot',
170
+ 'GetTreePartialViewChildren',
171
+ 'GetTreePartialViewAncestors',
172
+ 'GetTreePartialViewSiblings',
173
+ 'GetItemPartialView',
174
+ 'PostScript',
175
+ 'GetScriptByPath',
176
+ 'PutScriptByPath',
177
+ 'DeleteScriptByPath',
178
+ 'PutScriptByPathRename',
179
+ 'GetScriptFolderByPath',
180
+ 'GetTreeScriptRoot',
181
+ 'GetTreeScriptChildren',
182
+ 'GetTreeScriptAncestors',
183
+ 'GetTreeScriptSiblings',
184
+ 'GetItemScript',
185
+ 'PostStylesheet',
186
+ 'GetStylesheetByPath',
187
+ 'PutStylesheetByPath',
188
+ 'DeleteStylesheetByPath',
189
+ 'PutStylesheetByPathRename',
190
+ 'GetStylesheetFolderByPath',
191
+ 'GetTreeStylesheetRoot',
192
+ 'GetTreeStylesheetChildren',
193
+ 'GetTreeStylesheetAncestors',
194
+ 'GetTreeStylesheetSiblings',
195
+ 'GetItemStylesheet',
196
+ // Story 376: a workspace's types and data types, read and written in its own copy.
197
+ 'PostDocumentType',
198
+ 'GetDocumentTypeById',
199
+ 'PutDocumentTypeById',
200
+ 'DeleteDocumentTypeById',
201
+ 'GetDocumentTypeByIdCompositionReferences',
202
+ 'GetDocumentTypeAllowedAtRoot',
203
+ 'PostDocumentTypeAvailableCompositions',
204
+ 'GetDocumentTypeBatch',
205
+ 'GetDocumentTypeByIdSchema',
206
+ 'GetDocumentTypeByIdExport',
207
+ 'GetDocumentTypeByIdAllowedChildren',
208
+ 'GetDocumentTypeByIdAllowedParents',
209
+ 'PostMediaType',
210
+ 'GetMediaTypeById',
211
+ 'PutMediaTypeById',
212
+ 'DeleteMediaTypeById',
213
+ 'GetMediaTypeByIdCompositionReferences',
214
+ 'GetMediaTypeAllowedAtRoot',
215
+ 'PostMediaTypeAvailableCompositions',
216
+ 'GetMediaTypeBatch',
217
+ 'GetMediaTypeByIdSchema',
218
+ 'GetMediaTypeByIdExport',
219
+ 'GetMediaTypeByIdAllowedChildren',
220
+ 'GetMediaTypeByIdAllowedParents',
221
+ 'PostMemberType',
222
+ 'GetMemberTypeById',
223
+ 'PutMemberTypeById',
224
+ 'DeleteMemberTypeById',
225
+ 'GetMemberTypeByIdCompositionReferences',
226
+ 'GetMemberTypeAllowedAtRoot',
227
+ 'PostMemberTypeAvailableCompositions',
228
+ 'GetMemberTypeBatch',
229
+ 'GetMemberTypeByIdSchema',
230
+ 'GetMemberTypeByIdExport',
231
+ 'GetDocumentTypeAllowedInLibrary',
232
+ 'PostDataType',
233
+ 'GetDataTypeById',
234
+ 'PutDataTypeById',
235
+ 'DeleteDataTypeById',
236
+ 'GetDataTypeByIdIsUsed',
237
+ 'GetDataTypeByIdReferencedBy',
238
+ 'GetDataTypeByIdSchema',
239
+ 'GetDataTypeBatch',
240
+ 'GetFilterDataType',
241
+ 'GetDataTypeSchemasBatch',
242
+ ])
243
+
244
+ /**
245
+ * Type and data-type operations that are the site's whatever the header says
246
+ * (story 376): the trees, item lookups, search and configuration read Shared's.
247
+ * A guard test holds every type and data-type operation to one of the lists.
248
+ */
249
+ export const WORKSPACE_SHARED_SCHEMA_READS: ReadonlySet<string> = new Set(
250
+ [
251
+ // Story 392: a blueprint's folders and history are Shared's.
252
+ 'GetDocumentBlueprintFolderById',
253
+ 'GetDocumentBlueprintByIdAuditLog',
254
+ 'GetDataTypeConfiguration',
255
+ 'GetDataTypeFolderById',
256
+ 'GetItemDataType',
257
+ 'GetItemDataTypeAncestors',
258
+ 'GetItemDataTypeSearch',
259
+ 'GetTreeDataTypeAncestors',
260
+ 'GetTreeDataTypeChildren',
261
+ 'GetTreeDataTypeRoot',
262
+ 'GetTreeDataTypeSearch',
263
+ 'GetTreeDataTypeSiblings',
264
+ 'GetDocumentTypeByIdBlueprint',
265
+ 'GetItemMediaTypeAllowed',
266
+ 'GetItemMediaTypeFolders',
267
+ 'GetTreeDocumentTypeSearch',
268
+ // Story 377: snippets, and the id-addressed template reads, are the site's.
269
+ 'GetPartialViewSnippet',
270
+ 'GetPartialViewSnippetById',
271
+ 'GetItemTemplate',
272
+ 'GetItemTemplateAncestors',
273
+ 'GetItemTemplateSearch',
274
+ 'GetTemplateById',
275
+ 'GetTemplateConfiguration',
276
+ 'PostTemplateQueryExecute',
277
+ 'GetTemplateQuerySettings',
278
+ 'GetTreeTemplateAncestors',
279
+ 'GetTreeTemplateChildren',
280
+ 'GetTreeTemplateRoot',
281
+ 'GetTreeTemplateSiblings',
282
+ ].concat(
283
+ ['DocumentType', 'MediaType', 'MemberType'].flatMap((t) => [
284
+ `Get${t}Configuration`,
285
+ `Get${t}FolderById`,
286
+ `GetItem${t}`,
287
+ `GetItem${t}Ancestors`,
288
+ `GetItem${t}Search`,
289
+ `GetTree${t}Ancestors`,
290
+ `GetTree${t}Children`,
291
+ `GetTree${t}Root`,
292
+ `GetTree${t}Siblings`,
293
+ ]),
294
+ ),
295
+ )
296
+
297
+ /**
298
+ * What a workspace does not hold yet (story 375), refused with the header and
299
+ * why, rather than done in Shared. Anything in neither list is the site's, as
300
+ * users and settings are, and the header does not change it.
301
+ */
302
+ export const WORKSPACE_REFUSALS: ReadonlyMap<string, string> = new Map([
303
+ ...[
304
+ 'PostDocumentBlueprintFolder',
305
+ 'PutDocumentBlueprintFolderById',
306
+ 'DeleteDocumentBlueprintFolderById',
307
+ 'PutDocumentBlueprintByIdMove',
308
+ ].map((id) => [id, 'Blueprint folders are the site’s, and are changed in Shared.'] as const),
309
+ ['GetDictionaryByIdExport', 'A dictionary file is exported from Shared, for now.'],
310
+ ['PostDictionaryImport', 'A dictionary file is imported into Shared, for now.'],
311
+ // Story 390: media and the Library are held, but not their bins or the Library's folders.
312
+ ...[
313
+ 'PutRecycleBinMediaByIdRestore',
314
+ 'DeleteRecycleBinMediaById',
315
+ 'DeleteRecycleBinMedia',
316
+ 'PutRecycleBinElementByIdRestore',
317
+ 'DeleteRecycleBinElementById',
318
+ 'DeleteRecycleBinElement',
319
+ 'PutRecycleBinElementFolderByIdRestore',
320
+ 'DeleteRecycleBinElementFolderById',
321
+ ].map((id) => [id, 'The recycle bin is Shared’s: change it there.'] as const),
322
+ ...[
323
+ 'PostElementFolder',
324
+ 'PutElementFolderById',
325
+ 'PutElementFolderByIdMove',
326
+ 'PutElementFolderByIdMoveToRecycleBin',
327
+ 'DeleteElementFolderById',
328
+ ].map((id) => [id, 'The Library’s folders are the site’s, and are changed in Shared.'] as const),
329
+ ['PostElementByIdCopy', 'Copying a Library item is done in Shared only, for now.'],
330
+ [
331
+ 'PostElementVersionByIdRollback',
332
+ 'An earlier version can be brought back in Shared only, for now.',
333
+ ],
334
+ [
335
+ 'PutDocumentByIdPublishWithDescendants',
336
+ 'Publish each page in a workspace; a whole branch is published in Shared.',
337
+ ],
338
+ ['PostDocumentByIdCopy', 'Copying a page is done in Shared only, for now.'],
339
+ [
340
+ 'PostDocumentVersionByIdRollback',
341
+ 'An earlier version can be brought back in Shared only, for now.',
342
+ ],
343
+ ['PutRecycleBinDocumentByIdRestore', 'The recycle bin is Shared’s: restore a page there.'],
344
+ ['DeleteRecycleBinDocumentById', 'The recycle bin is Shared’s: empty it there.'],
345
+ ['DeleteRecycleBinDocument', 'The recycle bin is Shared’s: empty it there.'],
346
+ ['PutDocumentByIdDomains', 'A page’s hostnames are the site’s, and are set in Shared.'],
347
+ ['PostDocumentByIdPublicAccess', 'Who may see a page is the site’s, and is set in Shared.'],
348
+ ['PutDocumentByIdPublicAccess', 'Who may see a page is the site’s, and is set in Shared.'],
349
+ ['DeleteDocumentByIdPublicAccess', 'Who may see a page is the site’s, and is set in Shared.'],
350
+ ['PutDocumentByIdNotifications', 'Notifications are the site’s, and are set in Shared.'],
351
+ ['PostPartialViewFolder', 'Folders are the site’s, and are changed in Shared.'],
352
+ ['DeletePartialViewFolderByPath', 'Folders are the site’s, and are changed in Shared.'],
353
+ ['PostScriptFolder', 'Folders are the site’s, and are changed in Shared.'],
354
+ ['DeleteScriptFolderByPath', 'Folders are the site’s, and are changed in Shared.'],
355
+ ['PostStylesheetFolder', 'Folders are the site’s, and are changed in Shared.'],
356
+ ['DeleteStylesheetFolderByPath', 'Folders are the site’s, and are changed in Shared.'],
357
+ [
358
+ 'PostTemplate',
359
+ 'A template is changed through its file in a workspace: the components, by path.',
360
+ ],
361
+ [
362
+ 'PutTemplateById',
363
+ 'A template is changed through its file in a workspace: the components, by path.',
364
+ ],
365
+ [
366
+ 'DeleteTemplateById',
367
+ 'A template is changed through its file in a workspace: the components, by path.',
368
+ ],
369
+ ['PostDocumentTypeByIdCopy', 'Copying a definition is done in Shared only, for now.'],
370
+ ['PutDocumentTypeByIdMove', 'Moving a definition in its tree is done in Shared only, for now.'],
371
+ ['PutDocumentTypeByIdImport', 'Importing a definition is done in Shared only, for now.'],
372
+ ['PostDocumentTypeImport', 'Importing a definition is done in Shared only, for now.'],
373
+ ['PostDocumentTypeFolder', 'Folders are the site’s, and are changed in Shared.'],
374
+ ['PutDocumentTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
375
+ ['DeleteDocumentTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
376
+ ['PostMediaTypeByIdCopy', 'Copying a definition is done in Shared only, for now.'],
377
+ ['PutMediaTypeByIdMove', 'Moving a definition in its tree is done in Shared only, for now.'],
378
+ ['PutMediaTypeByIdImport', 'Importing a definition is done in Shared only, for now.'],
379
+ ['PostMediaTypeImport', 'Importing a definition is done in Shared only, for now.'],
380
+ ['PostMediaTypeFolder', 'Folders are the site’s, and are changed in Shared.'],
381
+ ['PutMediaTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
382
+ ['DeleteMediaTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
383
+ ['PostMemberTypeByIdCopy', 'Copying a definition is done in Shared only, for now.'],
384
+ ['PutMemberTypeByIdMove', 'Moving a definition in its tree is done in Shared only, for now.'],
385
+ ['PutMemberTypeByIdImport', 'Importing a definition is done in Shared only, for now.'],
386
+ ['PostMemberTypeImport', 'Importing a definition is done in Shared only, for now.'],
387
+ ['PostMemberTypeFolder', 'Folders are the site’s, and are changed in Shared.'],
388
+ ['PutMemberTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
389
+ ['DeleteMemberTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
390
+ [
391
+ 'PostDocumentTypeByIdTemplate',
392
+ 'A template is made in Shared only, until a workspace holds its own (story 377).',
393
+ ],
394
+ ['PostDataTypeByIdCopy', 'Copying a definition is done in Shared only, for now.'],
395
+ ['PutDataTypeByIdMove', 'Moving a definition in its tree is done in Shared only, for now.'],
396
+ ['PostDataTypeFolder', 'Folders are the site’s, and are changed in Shared.'],
397
+ ['PutDataTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
398
+ ['DeleteDataTypeFolderById', 'Folders are the site’s, and are changed in Shared.'],
399
+ ])
@@ -394,6 +394,18 @@ export function registerFolderHandlers(
394
394
  })
395
395
  }
396
396
 
397
+ /** A delete an open workspace's changes stand in the way of (story 376), named for no one. */
398
+ const inWorkspace = (what: string) =>
399
+ problemResponse(
400
+ problemDetails({
401
+ title: `This ${what} is being changed in a workspace`,
402
+ status: 409,
403
+ detail:
404
+ 'It cannot be deleted while that work is open. An administrator can delete it anyway, and the workspace must then settle it when it is merged.',
405
+ operationStatus: 'InWorkspace',
406
+ }),
407
+ )
408
+
397
409
  export function registerContentTypeHandlers(
398
410
  router: ManagementApiRouter,
399
411
  port: ContentTypePort,
@@ -532,7 +544,9 @@ export function registerContentTypeHandlers(
532
544
  operationStatus: 'NotAllowed',
533
545
  }),
534
546
  )
535
- const removed = await port.remove(ctx.params.id as string)
547
+ const force = ctx.url.searchParams.get('force') === 'true' && ctx.principal?.isAdmin === true
548
+ const removed = await port.remove(ctx.params.id as string, { force, by: ctx.principal?.id })
549
+ if (removed === 'in-workspace') return inWorkspace(noun)
536
550
  if (!removed) return problemResponse(notFound(`The ${noun} could not be found`))
537
551
  ctx.notifications.push({
538
552
  message: `${title} deleted`,
@@ -119,7 +119,18 @@ export function registerDataTypeHandlers(router: ManagementApiRouter, port: Data
119
119
  })
120
120
 
121
121
  router.handle('DeleteDataTypeById', async (ctx) => {
122
- const removed = await port.remove(ctx.params.id as string)
122
+ const force = ctx.url.searchParams.get('force') === 'true' && ctx.principal?.isAdmin === true
123
+ const removed = await port.remove(ctx.params.id as string, { force, by: ctx.principal?.id })
124
+ if (removed === 'in-workspace')
125
+ return problemResponse(
126
+ problemDetails({
127
+ title: 'This data type is being changed in a workspace',
128
+ status: 409,
129
+ detail:
130
+ 'It cannot be deleted while that work is open. An administrator can delete it anyway, and the workspace must then settle it when it is merged.',
131
+ operationStatus: 'InWorkspace',
132
+ }),
133
+ )
123
134
  if (removed === 'in-use')
124
135
  return problemResponse(
125
136
  problemDetails({
@@ -132,12 +132,15 @@ export function registerDictionaryHandlers(
132
132
  const body = (await ctx.request.json()) as Record<string, unknown>
133
133
  const key = typeof body.id === 'string' ? body.id : crypto.randomUUID()
134
134
  const failed = statusResult(
135
- await dictionary.create({
136
- key,
137
- name: String(body.name ?? '').trim(),
138
- parentKey: refId(body.parent),
139
- translations: readTranslations(body.translations),
140
- }),
135
+ await dictionary.create(
136
+ {
137
+ key,
138
+ name: String(body.name ?? '').trim(),
139
+ parentKey: refId(body.parent),
140
+ translations: readTranslations(body.translations),
141
+ },
142
+ ctx.principal?.id,
143
+ ),
141
144
  )
142
145
  if (failed) return failed
143
146
  return created(`${ctx.url.origin}/umbraco/management/api/v1/dictionary/${key}`, key)
@@ -146,23 +149,31 @@ export function registerDictionaryHandlers(
146
149
  router.handle('PutDictionaryById', async (ctx) => {
147
150
  const body = (await ctx.request.json()) as Record<string, unknown>
148
151
  const failed = statusResult(
149
- await dictionary.update(ctx.params.id as string, {
150
- name: String(body.name ?? '').trim(),
151
- translations: readTranslations(body.translations),
152
- }),
152
+ await dictionary.update(
153
+ ctx.params.id as string,
154
+ {
155
+ name: String(body.name ?? '').trim(),
156
+ translations: readTranslations(body.translations),
157
+ },
158
+ ctx.principal?.id,
159
+ ),
153
160
  )
154
161
  return failed ?? new Response(null, { status: 200 })
155
162
  })
156
163
 
157
- router.handle('DeleteDictionaryById', async ({ params }) => {
158
- return statusResult(await dictionary.delete(params.id as string)) ?? new Response(null)
164
+ router.handle('DeleteDictionaryById', async (ctx) => {
165
+ return (
166
+ statusResult(await dictionary.delete(ctx.params.id as string, ctx.principal?.id)) ??
167
+ new Response(null)
168
+ )
159
169
  })
160
170
 
161
171
  router.handle('PutDictionaryByIdMove', async (ctx) => {
162
172
  const body = (await ctx.request.json()) as Record<string, unknown>
163
173
  return (
164
- statusResult(await dictionary.move(ctx.params.id as string, refId(body.target))) ??
165
- new Response(null)
174
+ statusResult(
175
+ await dictionary.move(ctx.params.id as string, refId(body.target), ctx.principal?.id),
176
+ ) ?? new Response(null)
166
177
  )
167
178
  })
168
179
 
@@ -96,7 +96,7 @@ export function registerDocumentBlueprintHandlers(
96
96
  })
97
97
 
98
98
  router.handle('DeleteDocumentBlueprintById', async (ctx) => {
99
- const removed = await port.remove(ctx.params.id as string)
99
+ const removed = await port.remove(ctx.params.id as string, ctx.principal)
100
100
  if (!removed) return problemResponse(notFound('The blueprint could not be found'))
101
101
  return new Response(null, { status: 200 })
102
102
  })
@@ -26,7 +26,7 @@ import { APP_PREVIEW_PROVIDER, type PreviewPort } from '../ports.ts'
26
26
  import type { DocumentPort, PortFailure, SaveDocument } from '../ports-content.ts'
27
27
  import type { ManagementApiRouter, RequestContext } from '../router.ts'
28
28
  import { created, paging } from './content-type.ts'
29
- import { itemFlags, variantFlags } from './flags.ts'
29
+ import { itemFlags, variantFlags, WORKSPACE_CHANGED } from './flags.ts'
30
30
  import {
31
31
  type TreeSource,
32
32
  visibleChildren,
@@ -67,13 +67,16 @@ export function toDocumentResponse(aggregate: DocumentAggregate) {
67
67
  },
68
68
  template: aggregate.componentKey ? { id: aggregate.componentKey } : null,
69
69
  flags: itemFlags(aggregate.variants),
70
- values: aggregate.values.map((value) => ({
71
- editorAlias: value.editorAlias ?? '',
72
- culture: value.culture,
73
- segment: value.segment,
74
- alias: value.alias,
75
- value: value.value,
76
- })),
70
+ // The editor edits the shared value; each environment's is edited beside it (story 387).
71
+ values: aggregate.values
72
+ .filter((value) => !value.environment)
73
+ .map((value) => ({
74
+ editorAlias: value.editorAlias ?? '',
75
+ culture: value.culture,
76
+ segment: value.segment,
77
+ alias: value.alias,
78
+ value: value.value,
79
+ })),
77
80
  variants: toVariantResponse(aggregate),
78
81
  }
79
82
  }
@@ -273,7 +276,10 @@ export function toDocumentTreeItemResponse(item: DocumentTreeItem, noAccess = fa
273
276
  state: v.state,
274
277
  flags: variantFlags(v),
275
278
  })),
276
- flags: itemFlags(item.variants),
279
+ flags: [
280
+ ...itemFlags(item.variants),
281
+ ...(item.workspaceChanged ? [{ alias: WORKSPACE_CHANGED }] : []),
282
+ ],
277
283
  }
278
284
  }
279
285
 
@@ -577,12 +583,14 @@ export function registerDocumentHandlers(
577
583
  return invalid('A patch needs at least one operation.')
578
584
  const current = {
579
585
  template: existing.componentKey ? { id: existing.componentKey } : null,
580
- values: existing.values.map(({ alias, culture, segment, value }) => ({
581
- alias,
582
- culture,
583
- segment,
584
- value,
585
- })),
586
+ values: existing.values
587
+ .filter((v) => !v.environment)
588
+ .map(({ alias, culture, segment, value }) => ({
589
+ alias,
590
+ culture,
591
+ segment,
592
+ value,
593
+ })),
586
594
  variants: existing.variants.map(({ culture, segment, name }) => ({ culture, segment, name })),
587
595
  }
588
596
  const patched = applyJsonPatch(current, operations as PatchOperation[])
@@ -42,13 +42,15 @@ export function toElementResponse(element: DocumentAggregate) {
42
42
  element.contentTypeIcon,
43
43
  element.contentTypeCollectionKey,
44
44
  ),
45
- values: element.values.map((v) => ({
46
- alias: v.alias,
47
- culture: v.culture,
48
- segment: v.segment,
49
- value: v.value,
50
- editorAlias: v.editorAlias ?? '',
51
- })),
45
+ values: element.values
46
+ .filter((v) => !v.environment)
47
+ .map((v) => ({
48
+ alias: v.alias,
49
+ culture: v.culture,
50
+ segment: v.segment,
51
+ value: v.value,
52
+ editorAlias: v.editorAlias ?? '',
53
+ })),
52
54
  variants: element.variants.map((v) => ({
53
55
  id: element.key,
54
56
  culture: v.culture,
@@ -43,7 +43,19 @@ const treeItem = (entry: FileEntry) => ({
43
43
  hasChildren: entry.hasChildren,
44
44
  })
45
45
 
46
- function failure(area: FileArea, status: FileStatus, folder = false): Response {
46
+ function failure(area: FileArea, status: FileStatus, folder = false, detail?: string): Response {
47
+ if (status === 'DoesNotCompile' || status === 'TooLarge')
48
+ return problemResponse(
49
+ problemDetails({
50
+ title:
51
+ status === 'DoesNotCompile'
52
+ ? "The component doesn't compile, so it wasn't saved"
53
+ : 'The file is too large to keep in a workspace',
54
+ ...(detail ? { detail } : {}),
55
+ status: 400,
56
+ operationStatus: status,
57
+ }),
58
+ )
47
59
  if (status === 'ReadOnly')
48
60
  return problemResponse(
49
61
  problemDetails({
@@ -92,7 +104,7 @@ export function registerFileSystemHandlers(
92
104
  },
93
105
  })
94
106
  const result = (ctx: RequestContext, outcome: FileResult, create: boolean, folder = false) => {
95
- if (!outcome.ok) return failure(area, outcome.status, folder)
107
+ if (!outcome.ok) return failure(area, outcome.status, folder, outcome.detail)
96
108
  return create ? created(ctx, outcome.path, folder) : new Response(null, { status: 200 })
97
109
  }
98
110
  const page = (ctx: RequestContext, entries: readonly FileEntry[] | undefined) => {
@@ -165,20 +177,29 @@ export function registerFileSystemHandlers(
165
177
  parentPathOf(b.parent),
166
178
  String(b.name ?? ''),
167
179
  typeof b.content === 'string' ? b.content : '',
180
+ ctx.principal?.id,
168
181
  )
169
182
  return result(ctx, outcome, true)
170
183
  })
171
184
  router.handle(`Put${area}ByPath`, async (ctx) => {
172
185
  const b = await body(ctx)
173
186
  const content = typeof b.content === 'string' ? b.content : ''
174
- return result(ctx, await port.update(ctx.params.path as string, content), false)
187
+ return result(
188
+ ctx,
189
+ await port.update(ctx.params.path as string, content, ctx.principal?.id),
190
+ false,
191
+ )
175
192
  })
176
193
  router.handle(`Put${area}ByPathRename`, async (ctx) => {
177
194
  const b = await body(ctx)
178
- return result(ctx, await port.rename(ctx.params.path as string, String(b.name ?? '')), true)
195
+ return result(
196
+ ctx,
197
+ await port.rename(ctx.params.path as string, String(b.name ?? ''), ctx.principal?.id),
198
+ true,
199
+ )
179
200
  })
180
201
  router.handle(`Delete${area}ByPath`, async (ctx) =>
181
- result(ctx, await port.delete(ctx.params.path as string), false),
202
+ result(ctx, await port.delete(ctx.params.path as string, ctx.principal?.id), false),
182
203
  )
183
204
 
184
205
  router.handle(`Post${area}Folder`, async (ctx) => {
@@ -15,6 +15,9 @@ export const variantFlags = (variant: {
15
15
  ? [{ alias: SCHEDULED_FOR_PUBLISH }]
16
16
  : []
17
17
 
18
+ /** A tree item a workspace changed, read in that workspace (story 384). */
19
+ export const WORKSPACE_CHANGED = 'Crombolo.Workspace.Changed'
20
+
18
21
  /** An item's flags: what any of its variants carries, once. */
19
22
  export const itemFlags = (variants: ReadonlyArray<Parameters<typeof variantFlags>[0]>): Flag[] => {
20
23
  const aliases = new Set(variants.flatMap((v) => variantFlags(v).map((f) => f.alias)))
@@ -71,7 +71,7 @@ export function registerLocalizationHandlers(
71
71
  operationStatus: 'DuplicateIsoCode',
72
72
  }),
73
73
  )
74
- await localization.saveLanguage(readLanguage(isoCode, body))
74
+ await localization.saveLanguage(readLanguage(isoCode, body), ctx.principal?.id)
75
75
  ctx.notifications.push({ message: 'Language created', category: 'Language', type: 'Success' })
76
76
  return new Response(null, {
77
77
  status: 201,
@@ -83,12 +83,15 @@ export function registerLocalizationHandlers(
83
83
  const existing = await localization.language(isoCode)
84
84
  if (!existing) return problemResponse(notFound('The language could not be found'))
85
85
  const body = (await ctx.request.json()) as Record<string, unknown>
86
- await localization.saveLanguage(readLanguage(existing.isoCode, body))
86
+ await localization.saveLanguage(readLanguage(existing.isoCode, body), ctx.principal?.id)
87
87
  ctx.notifications.push({ message: 'Language saved', category: 'Language', type: 'Success' })
88
88
  return new Response(null, { status: 200 })
89
89
  })
90
90
  router.handle('DeleteLanguageByIsoCode', async (ctx) => {
91
- const result = await localization.deleteLanguage(ctx.params.isoCode as string)
91
+ const result = await localization.deleteLanguage(
92
+ ctx.params.isoCode as string,
93
+ ctx.principal?.id,
94
+ )
92
95
  if (result === 'not-found') return problemResponse(notFound('The language could not be found'))
93
96
  if (result !== 'deleted')
94
97
  return problemResponse(
@@ -36,13 +36,15 @@ export function toMediaResponse(media: DocumentAggregate) {
36
36
  media.contentTypeIcon,
37
37
  media.contentTypeCollectionKey,
38
38
  ),
39
- values: media.values.map((v) => ({
40
- alias: v.alias,
41
- culture: v.culture,
42
- segment: v.segment,
43
- value: v.value,
44
- editorAlias: v.editorAlias ?? '',
45
- })),
39
+ values: media.values
40
+ .filter((v) => !v.environment)
41
+ .map((v) => ({
42
+ alias: v.alias,
43
+ culture: v.culture,
44
+ segment: v.segment,
45
+ value: v.value,
46
+ editorAlias: v.editorAlias ?? '',
47
+ })),
46
48
  variants: media.variants.map((v) => ({
47
49
  culture: v.culture,
48
50
  segment: v.segment,
@@ -8,6 +8,7 @@ import {
8
8
  notFound,
9
9
  paged,
10
10
  parseSkipTake,
11
+ placesRefusal,
11
12
  problemDetails,
12
13
  problemResponse,
13
14
  } from '@crombolo/core'
@@ -603,8 +604,16 @@ function registerGroups(router: ManagementApiRouter, groups: UserGroupPort): voi
603
604
  if (found === 'Forbidden') return status('Forbidden')
604
605
  return Response.json(found)
605
606
  })
607
+ /** A place under Content without Content (story 385): refused, saying why. */
608
+ const withoutContent = (group: UserGroupInput) => {
609
+ const reason = placesRefusal(group.sections)
610
+ return reason ? bad('The group needs Content', reason, 'PlacesNeedContent') : undefined
611
+ }
606
612
  router.handle('PostUserGroup', async (ctx) => {
607
- const result = await groups.create(me(ctx), readGroup(await body(ctx)))
613
+ const group = readGroup(await body(ctx))
614
+ const refused = withoutContent(group)
615
+ if (refused) return refused
616
+ const result = await groups.create(me(ctx), group)
608
617
  if (result.status !== 'Success' || !result.key) return status(result.status)
609
618
  // The toast the backoffice shows, as for every other type it saves.
610
619
  ctx.notifications.push({
@@ -615,7 +624,10 @@ function registerGroups(router: ManagementApiRouter, groups: UserGroupPort): voi
615
624
  return created(`${ctx.url.origin}${V1}/user-group/${result.key}`, result.key)
616
625
  })
617
626
  router.handle('PutUserGroupById', async (ctx) => {
618
- const result = await groups.update(me(ctx), ctx.params.id as string, readGroup(await body(ctx)))
627
+ const group = readGroup(await body(ctx))
628
+ const refused = withoutContent(group)
629
+ if (refused) return refused
630
+ const result = await groups.update(me(ctx), ctx.params.id as string, group)
619
631
  if (result === 'Success')
620
632
  ctx.notifications.push({
621
633
  message: 'User group saved',
@@ -188,7 +188,11 @@ export interface ContentTypePort extends TreePort {
188
188
  aggregate: ContentTypeAggregate,
189
189
  principal: Principal,
190
190
  ): Promise<{ ok: true } | PortFailure>
191
- remove(key: string): Promise<boolean>
191
+ /**
192
+ * 'in-workspace' when an open workspace has changed it (story 376): refused,
193
+ * unless `force`, which only an administrator may ask.
194
+ */
195
+ remove(key: string, options?: { force?: boolean; by?: string }): Promise<boolean | 'in-workspace'>
192
196
  /** The type as Umbraco's `.udt` XML, or undefined when it is not there. */
193
197
  exportUdt(key: string): Promise<string | undefined>
194
198
  /**
@@ -243,8 +247,11 @@ export interface DataTypePort extends TreePort {
243
247
  byKeys(keys: readonly string[]): Promise<DataTypeModel[]>
244
248
  /** A failure when the save would leave the schema files invalid (story 344). */
245
249
  save(model: DataTypeModel, principal: Principal): Promise<PortFailure | undefined>
246
- /** 'in-use' when a property type still uses it. */
247
- remove(key: string): Promise<boolean | 'in-use'>
250
+ /** 'in-use' when a property type still uses it; 'in-workspace' as for a type (story 376). */
251
+ remove(
252
+ key: string,
253
+ options?: { force?: boolean; by?: string },
254
+ ): Promise<boolean | 'in-use' | 'in-workspace'>
248
255
  filter(
249
256
  criteria: { name?: string; editorAlias?: string; editorUiAlias?: string },
250
257
  paging: SkipTake,
@@ -470,7 +477,8 @@ export interface BlueprintPort {
470
477
  init: { key: string; name: string; parentKey: string | null },
471
478
  principal: Principal,
472
479
  ): Promise<{ ok: true; key: string } | PortFailure>
473
- remove(key: string): Promise<boolean>
480
+ /** `principal`: who removed it, for the change it is recorded as (story 392). */
481
+ remove(key: string, principal?: Principal): Promise<boolean>
474
482
  move(key: string, targetKey: string | null): Promise<{ ok: true } | PortFailure>
475
483
  versions(key: string): Promise<DocumentVersionSummary[]>
476
484
  systemUserKey(): Promise<string | null>
@@ -29,22 +29,29 @@ export type FileStatus =
29
29
  | 'NotEmpty'
30
30
  /** Crombolo: the site keeps these files read-only in the back office (story 337). */
31
31
  | 'ReadOnly'
32
+ /** Crombolo: a component saved in a workspace must compile (story 377). */
33
+ | 'DoesNotCompile'
34
+ /** Crombolo: a workspace keeps files of up to a megabyte (story 377). */
35
+ | 'TooLarge'
32
36
 
33
37
  /** Why the back office may not change a template, stylesheet or script here (story 337). */
34
38
  export const CONTENT_FILES_READ_ONLY =
35
39
  "This site doesn't allow templates, stylesheets and scripts to be changed in the back office."
36
40
 
37
- export type FileResult = { ok: true; path: string } | { ok: false; status: FileStatus }
41
+ export type FileResult =
42
+ | { ok: true; path: string }
43
+ | { ok: false; status: FileStatus; detail?: string }
38
44
 
39
45
  export interface FileSystemPort {
40
46
  /** Folders then files, each by name; the root when `parentPath` is null. */
41
47
  children(parentPath: string | null): Promise<FileEntry[] | undefined>
42
48
  entry(path: string): Promise<FileEntry | undefined>
43
49
  read(path: string): Promise<FileContent | undefined>
44
- create(parentPath: string | null, name: string, content: string): Promise<FileResult>
45
- update(path: string, content: string): Promise<FileResult>
46
- rename(path: string, name: string): Promise<FileResult>
47
- delete(path: string): Promise<FileResult>
50
+ /** `by` is the person's key, for the change a direct edit is recorded as (story 381). */
51
+ create(parentPath: string | null, name: string, content: string, by?: string): Promise<FileResult>
52
+ update(path: string, content: string, by?: string): Promise<FileResult>
53
+ rename(path: string, name: string, by?: string): Promise<FileResult>
54
+ delete(path: string, by?: string): Promise<FileResult>
48
55
  createFolder(parentPath: string | null, name: string): Promise<FileResult>
49
56
  deleteFolder(path: string): Promise<FileResult>
50
57
  }
package/src/ports.ts CHANGED
@@ -61,8 +61,12 @@ export interface LocalizationPort {
61
61
  /** Languages live in the database (and `schema/languages.toml`); cultures are the fixed list. */
62
62
  allLanguages(): Promise<LanguageInput[]>
63
63
  language(isoCode: string): Promise<LanguageInput | undefined>
64
- saveLanguage(language: LanguageInput): Promise<void>
65
- deleteLanguage(isoCode: string): Promise<'deleted' | 'default' | 'in-use' | 'not-found'>
64
+ /** `by`: who made the write, for the change it is recorded as (story 392). */
65
+ saveLanguage(language: LanguageInput, by?: string): Promise<void>
66
+ deleteLanguage(
67
+ isoCode: string,
68
+ by?: string,
69
+ ): Promise<'deleted' | 'default' | 'in-use' | 'not-found'>
66
70
  cultures(): ResponseOf<'GetCulture'>['items']
67
71
  }
68
72
 
@@ -232,13 +236,15 @@ export interface DictionaryPort {
232
236
  ): Promise<Array<{ key: string; name: string; parentKey: string | null; hasChildren: boolean }>>
233
237
  /** The item and its ancestors, root first. */
234
238
  ancestry(key: string): Promise<DictionaryItemModel[]>
235
- create(item: DictionaryItemModel): Promise<DictionaryWriteStatus>
239
+ /** `by`: who made the write, for the change it is recorded as (story 392). */
240
+ create(item: DictionaryItemModel, by?: string): Promise<DictionaryWriteStatus>
236
241
  update(
237
242
  key: string,
238
243
  change: { name: string; translations: DictionaryItemModel['translations'] },
244
+ by?: string,
239
245
  ): Promise<DictionaryWriteStatus>
240
- move(key: string, parentKey: string | null): Promise<DictionaryWriteStatus>
241
- delete(key: string): Promise<DictionaryWriteStatus>
246
+ move(key: string, parentKey: string | null, by?: string): Promise<DictionaryWriteStatus>
247
+ delete(key: string, by?: string): Promise<DictionaryWriteStatus>
242
248
  /** The item, with its descendants when asked, as a `.udt` file. */
243
249
  export(
244
250
  key: string,
package/src/router.ts CHANGED
@@ -132,8 +132,25 @@ const PICKER_OPERATIONS = new Set([
132
132
  'GetTreeElementSiblings',
133
133
  ])
134
134
 
135
+ /**
136
+ * Where a request's work happens, when not in Shared (story 375): its handler
137
+ * runs inside `run`, and what it changes is announced by the operations alone.
138
+ */
139
+ export interface RequestScope {
140
+ run<T>(fn: () => Promise<T>): Promise<T>
141
+ }
142
+
135
143
  export interface RouterOptions {
136
144
  operations?: readonly OperationInfo[]
145
+ /**
146
+ * The scope a request asks for, decided once it is authorised: a refusal to
147
+ * answer with, a scope to run it in, or undefined for Shared.
148
+ */
149
+ scope?(
150
+ request: Request,
151
+ principal: Principal | undefined,
152
+ operation: OperationInfo,
153
+ ): Promise<RequestScope | Response | undefined>
137
154
  /** Resolves the caller's identity. Omitted means every request is anonymous. */
138
155
  authenticate?: Authenticator
139
156
  /** Told about every request that reached an operation with no handler. */
@@ -191,6 +208,7 @@ export class ManagementApiRouter {
191
208
  readonly #clientAddress: (request: Request) => ClientAddress
192
209
  readonly #onError: RouterOptions['onError']
193
210
  readonly #onContentChange: RouterOptions['onContentChange']
211
+ readonly #scope: RouterOptions['scope']
194
212
 
195
213
  constructor(options: RouterOptions = {}) {
196
214
  const operations = options.operations ?? listOperations(loadSpec())
@@ -205,6 +223,7 @@ export class ManagementApiRouter {
205
223
  this.#onError = options.onError
206
224
  this.#ignoresStartNodes = options.ignoresStartNodes
207
225
  this.#onContentChange = options.onContentChange
226
+ this.#scope = options.scope
208
227
  for (const operation of operations) {
209
228
  const segments = operation.path.split('/').filter((s) => s.length > 0)
210
229
  const paramNames = segments.map((s) =>
@@ -318,6 +337,8 @@ export class ManagementApiRouter {
318
337
  if (principal && !(await authorize(operation, params, request, principal, this.#nodes)))
319
338
  return new Response(null, { status: 403, headers: { 'cache-control': 'no-store' } })
320
339
 
340
+ const scope = await this.#scope?.(request, principal, operation)
341
+ if (scope instanceof Response) return scope
321
342
  const handler = this.#handlers.get(operation.operationId)
322
343
  if (!handler) this.#onNotImplemented?.(operation, request)
323
344
  // A document write announces itself from its operation (story 170).
@@ -335,25 +356,29 @@ export class ManagementApiRouter {
335
356
  .json()
336
357
  .catch(() => undefined)
337
358
  : undefined
338
- const response = handler
339
- ? await this.#run(handler, {
340
- request,
341
- url,
342
- params,
343
- operation,
344
- notifications,
345
- principal,
346
- nodes: this.#nodes,
347
- client: this.#clientAddress(request),
348
- })
349
- : problemResponse(notImplemented(operation.operationId))
359
+ const context: RequestContext = {
360
+ request,
361
+ url,
362
+ params,
363
+ operation,
364
+ notifications,
365
+ principal,
366
+ nodes: this.#nodes,
367
+ client: this.#clientAddress(request),
368
+ }
369
+ const response = !handler
370
+ ? problemResponse(notImplemented(operation.operationId))
371
+ : scope
372
+ ? await scope.run(() => this.#run(handler, context))
373
+ : await this.#run(handler, context)
350
374
  if (plan && audit && response.status >= 200 && response.status < 300)
351
375
  await this.#recordAudit(plan, audit, params, request, response, principal)
352
- if (handler && announces && this.#onServerEvent) {
376
+ // A workspace's change is nobody else's to hear of until its merge.
377
+ if (handler && announces && !scope && this.#onServerEvent) {
353
378
  const event = serverEventFor(operation, params, response)
354
379
  if (event) this.#onServerEvent(event)
355
380
  }
356
- if (handler && announces && this.#onContentChange) {
381
+ if (handler && announces && !scope && this.#onContentChange) {
357
382
  const change = contentChangeFor(operation.operationId, params, response, changeBody)
358
383
  if (change) this.#onContentChange(change, principal)
359
384
  }
package/src/routes.ts CHANGED
@@ -57,6 +57,7 @@ export interface ManagementApiOptions {
57
57
  clientAddress?: RouterOptions['clientAddress']
58
58
  onError?: RouterOptions['onError']
59
59
  onContentChange?: RouterOptions['onContentChange']
60
+ scope?: RouterOptions['scope']
60
61
  }
61
62
 
62
63
  export function createManagementApiRouter(options: ManagementApiOptions = {}): ManagementApiRouter {
@@ -70,6 +71,7 @@ export function createManagementApiRouter(options: ManagementApiOptions = {}): M
70
71
  clientAddress: options.clientAddress,
71
72
  onError: options.onError,
72
73
  onContentChange: options.onContentChange,
74
+ scope: options.scope,
73
75
  ignoresStartNodes: async (dataTypeId) => {
74
76
  const dataType = await options.deps?.dataTypes?.byKey(dataTypeId).catch(() => undefined)
75
77
  const setting = dataType?.values.find((v) => v.alias === 'ignoreUserStartNodes')?.value
@@ -32,8 +32,13 @@ export const WEBHOOK_EVENTS: readonly WebhookEventInfo[] = [
32
32
  },
33
33
  { alias: 'Umbraco.MediaSave', eventName: 'Media Saved', eventType: 'Media' },
34
34
  { alias: 'Umbraco.MediaDelete', eventName: 'Media Deleted', eventType: 'Media' },
35
+ // Story 388: a publish closed its change, which a host may apply elsewhere at once.
36
+ { alias: 'Crombolo.ChangePublished', eventName: 'Change Published', eventType: 'Content' },
35
37
  ]
36
38
 
39
+ /** Raised when a publish finishes a person's change (story 388), naming it. */
40
+ export const CHANGE_PUBLISHED = 'Crombolo.ChangePublished'
41
+
37
42
  export const WEBHOOK_EVENT_ALIASES: ReadonlySet<string> = new Set(
38
43
  WEBHOOK_EVENTS.map((event) => event.alias),
39
44
  )