@crombolo/core 0.20.0 → 0.22.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 +1 -1
- package/src/content-types.ts +122 -3
- package/src/permissions.ts +57 -0
package/package.json
CHANGED
package/src/content-types.ts
CHANGED
|
@@ -113,8 +113,15 @@ export const SYSTEM_MEDIA_TYPE_KEYS: Readonly<Record<'Folder' | 'Image' | 'File'
|
|
|
113
113
|
File: '4c52d8ab-54e6-40cd-999c-7a5f24903e4d',
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/** "Caching" for media (story 057): a composition this CMS ships, never created as an item. */
|
|
117
|
+
export const MEDIA_CACHE_FIELDS_TYPE_KEY = '2d7c5e91-4a38-4f06-b1e2-8c9a0f3d6b57'
|
|
118
|
+
export const MEDIA_CACHE_KEEP_FOR_PROPERTY_KEY = '6e1d9b47-3a2c-4f85-8b06-d4c7a2e5f193'
|
|
119
|
+
|
|
116
120
|
export function isSystemMediaType(key: string): boolean {
|
|
117
|
-
|
|
121
|
+
const lower = key.toLowerCase()
|
|
122
|
+
return (
|
|
123
|
+
Object.values(SYSTEM_MEDIA_TYPE_KEYS).includes(lower) || lower === MEDIA_CACHE_FIELDS_TYPE_KEY
|
|
124
|
+
)
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
/**
|
|
@@ -131,8 +138,13 @@ export function isSystemMemberType(key: string): boolean {
|
|
|
131
138
|
* Content types this CMS ships: always present, not deletable, alias fixed. A
|
|
132
139
|
* site may add fields to one, but not remove or change the ones it ships with.
|
|
133
140
|
*/
|
|
134
|
-
export const SYSTEM_CONTENT_TYPE_KEYS: Readonly<
|
|
141
|
+
export const SYSTEM_CONTENT_TYPE_KEYS: Readonly<
|
|
142
|
+
Record<'SeoFields' | 'CacheFields' | 'Menu' | 'MenuItem', string>
|
|
143
|
+
> = {
|
|
135
144
|
SeoFields: '5e0f1c2a-7b3d-4c8e-9a61-0d2b4f6e8a13',
|
|
145
|
+
CacheFields: '7a1e4c93-2b6d-4f58-a0c7-5d3e9b1f8a24',
|
|
146
|
+
Menu: '3c9e2f71-5a4d-4b86-9e13-7f0a2d6c8b45',
|
|
147
|
+
MenuItem: '8b4d1a26-6e3f-4c90-a7d5-2e9c0f4b7a18',
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
export function isSystemContentType(kind: 'document' | 'media' | 'member', key: string): boolean {
|
|
@@ -201,9 +213,41 @@ export const SEO_FIELDS_PROPERTIES: readonly SystemPropertyModel[] = [
|
|
|
201
213
|
},
|
|
202
214
|
]
|
|
203
215
|
|
|
216
|
+
/** Where an editor chooses how long copies of a page or media item may be kept (story 057). */
|
|
217
|
+
export const CACHE_KEEP_FOR_ALIAS = 'cacheKeepFor'
|
|
218
|
+
|
|
219
|
+
/** The "Keep copies for" data type: a dropdown of `KEEP_COPIES_FOR` labels. */
|
|
220
|
+
export const KEEP_COPIES_FOR_DATA_TYPE_KEY = '4f2b8d61-9c0e-4a73-b5d8-1e6a3c7f9b02'
|
|
221
|
+
|
|
222
|
+
/** Each choice, as it is stored and shown, and its lifetime in seconds; none chosen is the site's. */
|
|
223
|
+
export const KEEP_COPIES_FOR: ReadonlyArray<{ label: string; seconds: number }> = [
|
|
224
|
+
{ label: "Don't keep copies", seconds: 0 },
|
|
225
|
+
{ label: '1 minute', seconds: 60 },
|
|
226
|
+
{ label: '5 minutes', seconds: 300 },
|
|
227
|
+
{ label: '1 hour', seconds: 3600 },
|
|
228
|
+
{ label: '1 day', seconds: 86400 },
|
|
229
|
+
]
|
|
230
|
+
|
|
231
|
+
/** The "Caching" composition's one field, the same for pages and media. */
|
|
232
|
+
export const CACHE_FIELDS_PROPERTIES: readonly SystemPropertyModel[] = [
|
|
233
|
+
{
|
|
234
|
+
key: '9b3e6f12-5d8a-4c07-8e41-2f7a0c9d6b13',
|
|
235
|
+
alias: CACHE_KEEP_FOR_ALIAS,
|
|
236
|
+
name: 'Keep copies for',
|
|
237
|
+
description:
|
|
238
|
+
"How long browsers and any service in front of the site may reuse a copy before asking again. Leave empty for the site's usual setting.",
|
|
239
|
+
dataTypeKey: KEEP_COPIES_FOR_DATA_TYPE_KEY,
|
|
240
|
+
},
|
|
241
|
+
]
|
|
242
|
+
|
|
204
243
|
/** The fields a system content type ships with, by the type's key. */
|
|
205
244
|
export function systemContentTypeProperties(key: string): readonly SystemPropertyModel[] {
|
|
206
|
-
|
|
245
|
+
const lower = key.toLowerCase()
|
|
246
|
+
if (lower === SYSTEM_CONTENT_TYPE_KEYS.SeoFields) return SEO_FIELDS_PROPERTIES
|
|
247
|
+
if (lower === SYSTEM_CONTENT_TYPE_KEYS.CacheFields) return CACHE_FIELDS_PROPERTIES
|
|
248
|
+
if (lower === SYSTEM_CONTENT_TYPE_KEYS.Menu) return MENU_PROPERTIES
|
|
249
|
+
if (lower === SYSTEM_CONTENT_TYPE_KEYS.MenuItem) return MENU_ITEM_PROPERTIES
|
|
250
|
+
return []
|
|
207
251
|
}
|
|
208
252
|
|
|
209
253
|
/**
|
|
@@ -272,3 +316,78 @@ export interface Page<T> {
|
|
|
272
316
|
total: number
|
|
273
317
|
items: T[]
|
|
274
318
|
}
|
|
319
|
+
|
|
320
|
+
/** A menu's "Alias", which templates name it by: `menu('header')` (story 141). */
|
|
321
|
+
export const MENU_ALIAS_PROPERTY = 'alias'
|
|
322
|
+
|
|
323
|
+
/** The "Menu items" data type: a block list of menu items, nested in each item too. */
|
|
324
|
+
export const MENU_ITEMS_DATA_TYPE_KEY = '5d2a8f47-1c6b-4e93-b0f4-8a3e7c2d9f61'
|
|
325
|
+
|
|
326
|
+
/** The "Menu link" data type: one page, media item or address. */
|
|
327
|
+
export const MENU_LINK_DATA_TYPE_KEY = '1f7c3b95-8d2e-4a64-9c0b-6e5d4a2f8c37'
|
|
328
|
+
|
|
329
|
+
/** The Menu element type's own fields. */
|
|
330
|
+
export const MENU_PROPERTIES: readonly SystemPropertyModel[] = [
|
|
331
|
+
{
|
|
332
|
+
key: '0a6f4d38-2c9b-4e71-8f5a-3d1b7e9c4a62',
|
|
333
|
+
alias: MENU_ALIAS_PROPERTY,
|
|
334
|
+
name: 'Alias',
|
|
335
|
+
description:
|
|
336
|
+
"What templates call this menu, such as header. Left empty, it is made from the menu's name when saved; renaming the menu later does not change it.",
|
|
337
|
+
dataTypeKey: '0cc0eba1-9960-42c9-bf9b-60e150b429ae',
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
key: '6e2b9c41-7f3a-4d58-b1c6-9a0e5d8f2b73',
|
|
341
|
+
alias: 'items',
|
|
342
|
+
name: 'Items',
|
|
343
|
+
description: 'Drag to reorder. Each item can hold items of its own.',
|
|
344
|
+
dataTypeKey: MENU_ITEMS_DATA_TYPE_KEY,
|
|
345
|
+
},
|
|
346
|
+
]
|
|
347
|
+
|
|
348
|
+
/** The Menu item element type's fields. */
|
|
349
|
+
export const MENU_ITEM_PROPERTIES: readonly SystemPropertyModel[] = [
|
|
350
|
+
{
|
|
351
|
+
key: '4c8a1e57-3b6d-4f92-a0e8-7d2c5b9f1a84',
|
|
352
|
+
alias: 'link',
|
|
353
|
+
name: 'Link',
|
|
354
|
+
description:
|
|
355
|
+
'A page, a media item or an address. Leave it empty for a heading that only holds the items below it.',
|
|
356
|
+
dataTypeKey: MENU_LINK_DATA_TYPE_KEY,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
key: '9d3f6b28-1a7e-4c05-b8d2-5e4a0c7f3b95',
|
|
360
|
+
alias: 'label',
|
|
361
|
+
name: 'Label',
|
|
362
|
+
description: "Shown instead of the page's name. Needed when there is no link.",
|
|
363
|
+
dataTypeKey: '0cc0eba1-9960-42c9-bf9b-60e150b429ae',
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
key: '2b7e0c64-8f1d-4a39-9c5e-6a3d8b1f4e06',
|
|
367
|
+
alias: 'children',
|
|
368
|
+
name: 'Items below',
|
|
369
|
+
description: 'Shown under this item, as a submenu.',
|
|
370
|
+
dataTypeKey: MENU_ITEMS_DATA_TYPE_KEY,
|
|
371
|
+
},
|
|
372
|
+
]
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* An alias made from a name as Umbraco's `ToSafeAlias` makes one: letters and
|
|
376
|
+
* digits only, words joined in camelCase, starting with a lowercase letter.
|
|
377
|
+
* "Main navigation" becomes `mainNavigation`. Pure.
|
|
378
|
+
*/
|
|
379
|
+
export function safeAlias(name: string): string {
|
|
380
|
+
const words = name
|
|
381
|
+
.normalize('NFKD')
|
|
382
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
383
|
+
.split(/[^A-Za-z0-9]+/)
|
|
384
|
+
.filter(Boolean)
|
|
385
|
+
const joined = words
|
|
386
|
+
.map((word, i) =>
|
|
387
|
+
i === 0
|
|
388
|
+
? word.charAt(0).toLowerCase() + word.slice(1)
|
|
389
|
+
: word.charAt(0).toUpperCase() + word.slice(1),
|
|
390
|
+
)
|
|
391
|
+
.join('')
|
|
392
|
+
return joined.replace(/^[0-9]+/, '')
|
|
393
|
+
}
|
package/src/permissions.ts
CHANGED
|
@@ -67,6 +67,40 @@ export const RemotePermissions = {
|
|
|
67
67
|
} as const
|
|
68
68
|
export type RemoteVerb = (typeof RemotePermissions)[keyof typeof RemotePermissions]
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Media (story 088). Umbraco has no media verbs: a group with the Media section
|
|
72
|
+
* may change everything in it. These are group-wide, held in the groups'
|
|
73
|
+
* fallback permissions, since media has no per-node permissions; start nodes
|
|
74
|
+
* still scope media by place.
|
|
75
|
+
*/
|
|
76
|
+
export const MediaPermissions = {
|
|
77
|
+
Read: 'Crombolo.Media.Read',
|
|
78
|
+
Update: 'Crombolo.Media.Update',
|
|
79
|
+
} as const
|
|
80
|
+
export type MediaVerb = (typeof MediaPermissions)[keyof typeof MediaPermissions]
|
|
81
|
+
|
|
82
|
+
/** Umbraco's element verbs, which the Library section's operations require. */
|
|
83
|
+
export const ElementPermissions = {
|
|
84
|
+
Read: 'Umb.Element.Read',
|
|
85
|
+
Create: 'Umb.Element.Create',
|
|
86
|
+
Update: 'Umb.Element.Update',
|
|
87
|
+
Delete: 'Umb.Element.Delete',
|
|
88
|
+
Move: 'Umb.Element.Move',
|
|
89
|
+
Duplicate: 'Umb.Element.Duplicate',
|
|
90
|
+
Publish: 'Umb.Element.Publish',
|
|
91
|
+
Unpublish: 'Umb.Element.Unpublish',
|
|
92
|
+
Rollback: 'Umb.Element.Rollback',
|
|
93
|
+
} as const
|
|
94
|
+
|
|
95
|
+
/** Umbraco's element folder verbs. */
|
|
96
|
+
export const ElementContainerPermissions = {
|
|
97
|
+
Read: 'Umb.ElementContainer.Read',
|
|
98
|
+
Create: 'Umb.ElementContainer.Create',
|
|
99
|
+
Update: 'Umb.ElementContainer.Update',
|
|
100
|
+
Delete: 'Umb.ElementContainer.Delete',
|
|
101
|
+
Move: 'Umb.ElementContainer.Move',
|
|
102
|
+
} as const
|
|
103
|
+
|
|
70
104
|
/** The discriminator on a granular permission row. */
|
|
71
105
|
export type PermissionContext = 'Document' | 'Element' | 'DocumentTypeProperty'
|
|
72
106
|
|
|
@@ -151,6 +185,8 @@ export interface GroupGrant {
|
|
|
151
185
|
alias: string
|
|
152
186
|
defaults: readonly string[]
|
|
153
187
|
granular: ReadonlyMap<string, readonly string[]>
|
|
188
|
+
/** Property types the group sets explicitly, by property type key: their value verbs. */
|
|
189
|
+
properties?: ReadonlyMap<string, readonly string[]>
|
|
154
190
|
}
|
|
155
191
|
|
|
156
192
|
/**
|
|
@@ -187,6 +223,27 @@ export function permissionsForPath(
|
|
|
187
223
|
return verbs
|
|
188
224
|
}
|
|
189
225
|
|
|
226
|
+
/** The verbs a user's groups hold everywhere: their defaults, for what has no per-node permissions. */
|
|
227
|
+
export function fallbackPermissions(groups: readonly GroupGrant[]): Set<string> {
|
|
228
|
+
return new Set(groups.flatMap((group) => group.defaults))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The value verbs a user holds on a property type, as Umbraco's client reads
|
|
233
|
+
* them: a group that sets the property explicitly replaces its defaults with
|
|
234
|
+
* that setting; the result is the union over groups.
|
|
235
|
+
*/
|
|
236
|
+
export function propertyValuePermissions(
|
|
237
|
+
groups: readonly GroupGrant[],
|
|
238
|
+
propertyTypeKey: string,
|
|
239
|
+
): Set<string> {
|
|
240
|
+
const verbs = new Set<string>()
|
|
241
|
+
const key = propertyTypeKey.toLowerCase()
|
|
242
|
+
for (const group of groups)
|
|
243
|
+
for (const verb of group.properties?.get(key) ?? group.defaults) verbs.add(verb)
|
|
244
|
+
return verbs
|
|
245
|
+
}
|
|
246
|
+
|
|
190
247
|
/**
|
|
191
248
|
* An administrator bypasses the permission tables entirely, matching Umbraco:
|
|
192
249
|
* membership of the admin group is the check, not an exhaustive grant list.
|