@crombolo/core 0.20.0 → 0.21.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/permissions.ts +57 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/core",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Domain model, entity keys and shared contracts for crombolo. No I/O.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -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.