@crombolo/backoffice-host 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.
@@ -0,0 +1,750 @@
1
+ /**
2
+ * The user group editor (story 338): Access, Permissions, Exceptions, Data
3
+ * Transfer and People, in place of Umbraco's checkbox grids. It reads and writes
4
+ * the group through the workspace's own context, so Save, routing, the tree and
5
+ * the read-only rules for non-administrators stay the workspace's.
6
+ */
7
+ import { UmbDocumentItemRepository } from '@umbraco-cms/backoffice/document'
8
+ import { UmbDocumentTypeDetailRepository } from '@umbraco-cms/backoffice/document-type'
9
+ import { UmbElementItemRepository } from '@umbraco-cms/backoffice/element'
10
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
11
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
12
+ import { UmbTextStyles } from '@umbraco-cms/backoffice/style'
13
+ import { UMB_USER_GROUP_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/user-group'
14
+ import {
15
+ ACCESS_OFF,
16
+ AREAS,
17
+ exceptionSentence,
18
+ exceptionSummary,
19
+ KIND_AREA,
20
+ KIND_LABEL,
21
+ kindVerbs,
22
+ LEVELS,
23
+ levelOf,
24
+ libraryFollowsPages,
25
+ SENSITIVE_ANSWERS,
26
+ SYSTEM_GROUPS,
27
+ shownLevel,
28
+ systemGroupNote,
29
+ TABS,
30
+ TRANSFER,
31
+ VERB_WORDS,
32
+ withLevel,
33
+ withVerb,
34
+ } from './group-editor-words.js'
35
+
36
+ const DOCUMENT = 'DocumentPermissionPresentationModel'
37
+ const ELEMENT = 'ElementPermissionPresentationModel'
38
+ const FIELD = 'DocumentPropertyValuePermissionPresentationModel'
39
+ const WRITE_FIELD = 'Umb.Document.PropertyValue.Write'
40
+
41
+ const idOf = (ref) => ref?.id ?? ref?.unique
42
+
43
+ /** Which of a group's granular entries are exceptions the editor lists. */
44
+ function kindOfEntry(entry) {
45
+ if (entry.$type === DOCUMENT && entry.document) return 'pages'
46
+ if (entry.$type === ELEMENT && entry.element) return 'library'
47
+ if (
48
+ (entry.$type === FIELD || entry.userPermissionType === 'document-property-value') &&
49
+ entry.propertyType
50
+ )
51
+ return 'field'
52
+ return undefined
53
+ }
54
+
55
+ export default class CromboloGroupEditorElement extends UmbLitElement {
56
+ static properties = {
57
+ _tab: { state: true },
58
+ _group: { state: true },
59
+ _readOnly: { state: true },
60
+ _canManageMembers: { state: true },
61
+ _names: { state: true },
62
+ _adding: { state: true },
63
+ _open: { state: true },
64
+ }
65
+
66
+ #context
67
+ #documents = new UmbDocumentItemRepository(this)
68
+ #elements = new UmbElementItemRepository(this)
69
+ #documentTypes = new UmbDocumentTypeDetailRepository(this)
70
+
71
+ constructor() {
72
+ super()
73
+ this._tab = 'access'
74
+ this._group = {}
75
+ this._readOnly = true
76
+ this._canManageMembers = false
77
+ this._names = {}
78
+ this._adding = undefined
79
+ this._open = {}
80
+ this.consumeContext(UMB_USER_GROUP_WORKSPACE_CONTEXT, (context) => {
81
+ this.#context = context
82
+ for (const key of [
83
+ 'name',
84
+ 'alias',
85
+ 'sections',
86
+ 'languages',
87
+ 'hasAccessToAllLanguages',
88
+ 'documentStartNode',
89
+ 'documentRootAccess',
90
+ 'mediaStartNode',
91
+ 'mediaRootAccess',
92
+ 'elementStartNode',
93
+ 'elementRootAccess',
94
+ 'fallbackPermissions',
95
+ 'permissions',
96
+ 'owners',
97
+ ])
98
+ this.observe(
99
+ context?.[key],
100
+ (value) => {
101
+ this._group = { ...this._group, [key]: value }
102
+ if (key === 'permissions') this.#nameExceptions(value ?? [])
103
+ },
104
+ `_observe_${key}`,
105
+ )
106
+ this.observe(
107
+ context?.readOnly,
108
+ (value) => (this._readOnly = value ?? true),
109
+ '_observeReadOnly',
110
+ )
111
+ this.observe(
112
+ context?.canManageMembers,
113
+ (value) => (this._canManageMembers = value ?? false),
114
+ '_observeCanManageMembers',
115
+ )
116
+ })
117
+ }
118
+
119
+ // ---- reading and writing the group
120
+
121
+ get #verbs() {
122
+ return this._group.fallbackPermissions ?? []
123
+ }
124
+ #setVerbs(verbs) {
125
+ this.#context?.setFallbackPermissions(verbs)
126
+ }
127
+ #set(key, value) {
128
+ this.#context?.updateProperty(key, value)
129
+ }
130
+ get #alias() {
131
+ return this._group.alias ?? ''
132
+ }
133
+ get #isAdminGroup() {
134
+ return this.#alias.toLowerCase() === 'admin'
135
+ }
136
+ /** Story 338: a built-in group's access and permissions are shown, never changed. */
137
+ get #permissionsLocked() {
138
+ return this._readOnly || SYSTEM_GROUPS.has(this.#alias)
139
+ }
140
+ #renderSystemNote() {
141
+ return SYSTEM_GROUPS.has(this.#alias)
142
+ ? html`<div class="notice" role="status"><uui-icon name="icon-lock"></uui-icon>${systemGroupNote(this.#alias)}</div>`
143
+ : nothing
144
+ }
145
+
146
+ #hasArea(section) {
147
+ return (this._group.sections ?? []).includes(section)
148
+ }
149
+
150
+ async #nameExceptions(entries) {
151
+ const pages = entries.filter((e) => kindOfEntry(e) === 'pages').map((e) => idOf(e.document))
152
+ const items = entries.filter((e) => kindOfEntry(e) === 'library').map((e) => idOf(e.element))
153
+ const types = [
154
+ ...new Set(
155
+ entries.filter((e) => kindOfEntry(e) === 'field').map((e) => idOf(e.documentType)),
156
+ ),
157
+ ]
158
+ const names = { ...this._names }
159
+ if (pages.length) {
160
+ const { data } = await this.#documents.requestItems(pages)
161
+ for (const item of data ?? [])
162
+ names[item.unique] = item.variants?.[0]?.name ?? item.name ?? item.unique
163
+ }
164
+ if (items.length) {
165
+ const { data } = await this.#elements.requestItems(items)
166
+ for (const item of data ?? [])
167
+ names[item.unique] = item.variants?.[0]?.name ?? item.name ?? item.unique
168
+ }
169
+ for (const type of types) {
170
+ if (names[type]) continue
171
+ const { data } = await this.#documentTypes.requestByUnique(type)
172
+ if (!data) continue
173
+ names[type] = data.name
174
+ for (const property of data.properties ?? []) names[property.unique] = property.name
175
+ }
176
+ this._names = names
177
+ }
178
+
179
+ // ---- Access
180
+
181
+ #toggleArea(section, on) {
182
+ const sections = this._group.sections ?? []
183
+ this.#set(
184
+ 'sections',
185
+ on ? [...new Set([...sections, section])] : sections.filter((s) => s !== section),
186
+ )
187
+ }
188
+
189
+ #renderSwitch(on, label, toggle) {
190
+ return html`<button
191
+ type="button"
192
+ role="switch"
193
+ class="switch ${on ? 'on' : ''}"
194
+ aria-checked=${on ? 'true' : 'false'}
195
+ aria-label=${`${label}: ${on ? 'on' : 'off'}`}
196
+ ?disabled=${this.#permissionsLocked}
197
+ @click=${() => toggle(!on)}><span></span></button>`
198
+ }
199
+
200
+ #renderWhere(label, root, node, rootKey, nodeKey, picker) {
201
+ return html`<div class="row">
202
+ <span class="row-label">${label}</span>
203
+ <div class="row-value">
204
+ <uui-toggle
205
+ label="Everywhere"
206
+ ?checked=${root}
207
+ ?disabled=${this.#permissionsLocked}
208
+ @change=${(e) => {
209
+ this.#set(rootKey, e.target.checked)
210
+ this.#set(nodeKey, null)
211
+ }}></uui-toggle>
212
+ ${root ? nothing : picker(node ? [node.unique ?? node.id] : [])}
213
+ </div>
214
+ </div>`
215
+ }
216
+
217
+ #pick(nodeKey) {
218
+ return (e) => {
219
+ const unique = e.target.selection?.[0]
220
+ this.#set(nodeKey, unique ? { unique } : null)
221
+ }
222
+ }
223
+
224
+ #renderAreaSettings(section) {
225
+ const g = this._group
226
+ if (section === 'Umb.Section.Content')
227
+ return html`
228
+ ${this.#renderWhere('Pages', g.documentRootAccess, g.documentStartNode, 'documentRootAccess', 'documentStartNode', (selection) => html`<umb-input-document max="1" ?readonly=${this.#permissionsLocked} .selection=${selection} @change=${this.#pick('documentStartNode')}></umb-input-document>`)}
229
+ <div class="row">
230
+ <span class="row-label">Languages</span>
231
+ <div class="row-value">
232
+ <uui-toggle
233
+ label="All languages"
234
+ ?checked=${g.hasAccessToAllLanguages}
235
+ ?disabled=${this.#permissionsLocked}
236
+ @change=${(e) => this.#set('hasAccessToAllLanguages', e.target.checked)}></uui-toggle>
237
+ ${
238
+ g.hasAccessToAllLanguages
239
+ ? nothing
240
+ : html`<umb-input-language
241
+ ?readonly=${this.#permissionsLocked}
242
+ .selection=${g.languages ?? []}
243
+ @change=${(e) => this.#set('languages', e.target.selection)}></umb-input-language>`
244
+ }
245
+ </div>
246
+ </div>
247
+ `
248
+ if (section === 'Umb.Section.Library')
249
+ return this.#renderWhere(
250
+ 'Folders',
251
+ g.elementRootAccess,
252
+ g.elementStartNode,
253
+ 'elementRootAccess',
254
+ 'elementStartNode',
255
+ (selection) =>
256
+ html`<umb-input-element max="1" ?folderOnly=${true} ?readonly=${this.#permissionsLocked} .selection=${selection} @change=${this.#pick('elementStartNode')}></umb-input-element>`,
257
+ )
258
+ if (section === 'Umb.Section.Media')
259
+ return this.#renderWhere(
260
+ 'Folders',
261
+ g.mediaRootAccess,
262
+ g.mediaStartNode,
263
+ 'mediaRootAccess',
264
+ 'mediaStartNode',
265
+ (selection) =>
266
+ html`<umb-input-media max="1" folder-filter="foldersOnly" ?readonly=${this.#permissionsLocked} .selection=${selection} @change=${this.#pick('mediaStartNode')}></umb-input-media>`,
267
+ )
268
+ return nothing
269
+ }
270
+
271
+ #renderAccess() {
272
+ return html`
273
+ ${this.#renderSystemNote()}
274
+ ${AREAS.map((area) => {
275
+ const on = this.#hasArea(area.section)
276
+ const settings = on ? this.#renderAreaSettings(area.section) : nothing
277
+ return html`<uui-box class="area ${on ? '' : 'off'}">
278
+ <div class="area-head">
279
+ ${this.#renderSwitch(on, area.label, (value) => this.#toggleArea(area.section, value))}
280
+ <div class="area-text">
281
+ <h2>${area.label}</h2>
282
+ <p>${area.line}</p>
283
+ </div>
284
+ <span class="state">${on ? 'On' : 'Off'}</span>
285
+ </div>
286
+ ${settings === nothing ? nothing : html`<div class="area-body">${settings}</div>`}
287
+ </uui-box>`
288
+ })}
289
+ `
290
+ }
291
+
292
+ // ---- Permissions
293
+
294
+ #renderLevels(kind, current, choose, disabled = false) {
295
+ return html`<div class="levels" role="radiogroup" aria-label=${KIND_LABEL[kind]}>
296
+ ${LEVELS[kind].map(
297
+ (level) => html`<label class="level ${current === level.id ? 'chosen' : ''}">
298
+ <input
299
+ type="radio"
300
+ name=${`level-${kind}`}
301
+ .checked=${current === level.id}
302
+ ?disabled=${disabled || this.#permissionsLocked}
303
+ @change=${() => choose(level.id)} />
304
+ <span class="level-text"><strong>${level.label}</strong><span>${level.line}</span></span>
305
+ </label>`,
306
+ )}
307
+ ${current === 'custom' ? html`<span class="custom">Custom</span>` : nothing}
308
+ </div>`
309
+ }
310
+
311
+ #renderCustomise(kind, current) {
312
+ // An administrator can do everything, so their verbs are nothing to customise.
313
+ if (this.#isAdminGroup) return nothing
314
+ const open = this._open[kind] || current === 'custom'
315
+ const verbs = this.#verbs
316
+ return html`<details ?open=${open} @toggle=${(e) => (this._open = { ...this._open, [kind]: e.target.open })}>
317
+ <summary>Customise</summary>
318
+ <div class="verbs">
319
+ ${kindVerbs(kind).map(
320
+ (verb) => html`<label class="verb">
321
+ <input
322
+ type="checkbox"
323
+ .checked=${verbs.includes(verb)}
324
+ ?disabled=${this.#permissionsLocked}
325
+ @change=${(e) => this.#setVerbs(withVerb(verbs, verb, e.target.checked))} />
326
+ ${VERB_WORDS[verb] ?? verb}
327
+ </label>`,
328
+ )}
329
+ </div>
330
+ </details>`
331
+ }
332
+
333
+ #renderKind(kind, extra = nothing) {
334
+ const area = KIND_AREA[kind]
335
+ const label = KIND_LABEL[kind]
336
+ if (!this.#hasArea(area))
337
+ return html`<section class="kind off" aria-disabled="true">
338
+ <div class="kind-head">
339
+ <h2>${label}</h2>
340
+ <span class="pill">Access is off</span>
341
+ <span class="note">${ACCESS_OFF(label)}
342
+ <button type="button" class="link" @click=${() => (this._tab = 'access')}>Go to Access</button></span>
343
+ </div>
344
+ ${this.#renderLevels(kind, 'none', () => {}, true)}
345
+ </section>`
346
+ const current = shownLevel(kind, this.#verbs, this.#alias)
347
+ return html`<section class="kind">
348
+ <div class="kind-head"><h2>${label}</h2></div>
349
+ ${this.#renderLevels(kind, current, (id) => this.#setVerbs(withLevel(this.#verbs, kind, id)))}
350
+ ${extra} ${this.#renderCustomise(kind, current)}
351
+ </section>`
352
+ }
353
+
354
+ #renderLibrary() {
355
+ if (!this.#hasArea(KIND_AREA.library)) return this.#renderKind('library')
356
+ const follows = this.#isAdminGroup || libraryFollowsPages(this.#verbs)
357
+ if (!follows || this._open.libraryOwn)
358
+ return this.#renderKind('library', this.#renderFollow(false))
359
+ return html`<section class="kind">
360
+ <div class="kind-head"><h2>Library</h2></div>
361
+ ${this.#renderFollow(true)}
362
+ </section>`
363
+ }
364
+
365
+ #renderFollow(follows) {
366
+ return html`<div class="follow">
367
+ <label class="level ${follows ? 'chosen' : ''}"><input
368
+ type="radio"
369
+ name="library-follows"
370
+ .checked=${follows}
371
+ ?disabled=${this.#permissionsLocked}
372
+ @change=${() => {
373
+ this._open = { ...this._open, libraryOwn: false }
374
+ const pages = levelOf('pages', this.#verbs)
375
+ if (pages !== 'custom') this.#setVerbs(withLevel(this.#verbs, 'library', pages))
376
+ }} /><strong>Same as pages</strong></label>
377
+ <label class="level ${follows ? '' : 'chosen'}"><input
378
+ type="radio"
379
+ name="library-follows"
380
+ .checked=${!follows}
381
+ ?disabled=${this.#permissionsLocked}
382
+ @change=${() => (this._open = { ...this._open, libraryOwn: true })} /><strong>Choose separately</strong></label>
383
+ </div>`
384
+ }
385
+
386
+ #renderPermissions() {
387
+ const sensitive = html`<label class="verb">
388
+ <input
389
+ type="checkbox"
390
+ .checked=${this.#isAdminGroup || this.#verbs.includes(SENSITIVE_ANSWERS)}
391
+ ?disabled=${this.#permissionsLocked}
392
+ @change=${(e) => this.#setVerbs(withVerb(this.#verbs, SENSITIVE_ANSWERS, e.target.checked))} />
393
+ Can see answers marked sensitive
394
+ </label>`
395
+ return html`
396
+ ${this.#renderSystemNote()}
397
+ ${this.#renderKind('pages')} ${this.#renderLibrary()} ${this.#renderKind('media')}
398
+ ${this.#renderKind('forms', sensitive)}
399
+ `
400
+ }
401
+
402
+ // ---- Exceptions
403
+
404
+ get #exceptions() {
405
+ return (this._group.permissions ?? [])
406
+ .map((entry, index) => ({ entry, index, kind: kindOfEntry(entry) }))
407
+ .filter((e) => e.kind)
408
+ }
409
+
410
+ #describe({ entry, kind }) {
411
+ if (kind === 'field')
412
+ return exceptionSentence(
413
+ {
414
+ kind,
415
+ typeName: this._names[idOf(entry.documentType)] ?? 'A page type',
416
+ fieldName: this._names[idOf(entry.propertyType)] ?? 'a field',
417
+ verbs: entry.verbs,
418
+ },
419
+ this.#verbs,
420
+ )
421
+ const id = idOf(kind === 'library' ? entry.element : entry.document)
422
+ return exceptionSentence(
423
+ { kind, name: this._names[id] ?? '…', verbs: entry.verbs },
424
+ this.#verbs,
425
+ )
426
+ }
427
+
428
+ #remove(index) {
429
+ this.#context?.setPermissions((this._group.permissions ?? []).filter((_, i) => i !== index))
430
+ }
431
+
432
+ #renderExceptions() {
433
+ const list = this.#exceptions
434
+ return html`
435
+ ${this.#renderSystemNote()}
436
+ <div class="intro-row">
437
+ ${
438
+ this._readOnly
439
+ ? nothing
440
+ : html`<uui-button look="primary" label="Add an exception" ?disabled=${this.#permissionsLocked} @click=${() => (this._adding = { kind: 'pages', level: 'see' })}></uui-button>`
441
+ }
442
+ </div>
443
+ ${this._adding ? this.#renderAdding() : nothing}
444
+ ${
445
+ list.length === 0
446
+ ? html`<p class="empty">No exceptions: the permissions apply everywhere this group has access.</p>`
447
+ : html`<uui-box>
448
+ ${list.map((item) => {
449
+ const said = this.#describe(item)
450
+ return html`<div class="exception">
451
+ <div class="exception-text">
452
+ <strong>${said.where}</strong> <span class="muted">${said.whereNote}</span>
453
+ <div>${said.what}</div>
454
+ </div>
455
+ ${
456
+ this.#permissionsLocked
457
+ ? nothing
458
+ : html`<uui-button look="secondary" color="danger" label="Remove" @click=${() => this.#remove(item.index)}></uui-button>`
459
+ }
460
+ </div>`
461
+ })}
462
+ </uui-box>`
463
+ }
464
+ <p class="note">An exception on a page covers that page and everything below it, and the nearest one wins. An exception on a field applies on every page of that type.</p>
465
+ `
466
+ }
467
+
468
+ async #chooseType(unique) {
469
+ const { data } = await this.#documentTypes.requestByUnique(unique)
470
+ this._adding = {
471
+ ...this._adding,
472
+ typeId: unique,
473
+ typeName: data?.name,
474
+ fields: (data?.properties ?? []).map((p) => ({ id: p.unique, name: p.name })),
475
+ fieldId: undefined,
476
+ }
477
+ }
478
+
479
+ #addException() {
480
+ const a = this._adding
481
+ const entries = [...(this._group.permissions ?? [])]
482
+ if (a.kind === 'field') {
483
+ if (!a.typeId || !a.fieldId) return
484
+ entries.push({
485
+ $type: FIELD,
486
+ userPermissionType: 'document-property-value',
487
+ documentType: { id: a.typeId, unique: a.typeId },
488
+ propertyType: { id: a.fieldId, unique: a.fieldId },
489
+ verbs: a.level === 'edit' ? [WRITE_FIELD] : [],
490
+ })
491
+ } else {
492
+ if (!a.placeId) return
493
+ const verbs = LEVELS[a.kind].find((l) => l.id === a.level)?.verbs ?? []
494
+ entries.push(
495
+ a.kind === 'library'
496
+ ? { $type: ELEMENT, element: { id: a.placeId }, verbs }
497
+ : { $type: DOCUMENT, document: { id: a.placeId }, verbs },
498
+ )
499
+ }
500
+ this.#context?.setPermissions(entries)
501
+ this._adding = undefined
502
+ }
503
+
504
+ #renderAdding() {
505
+ const a = this._adding
506
+ const set = (patch) => (this._adding = { ...a, ...patch })
507
+ const field = a.kind === 'field'
508
+ const placeName = field
509
+ ? `${a.typeName ?? 'the page type'} › ${a.fields?.find((f) => f.id === a.fieldId)?.name ?? 'the field'}`
510
+ : (a.placeName ?? 'the chosen place')
511
+ return html`<uui-box headline="Add an exception" class="adding">
512
+ <fieldset>
513
+ <legend>1. What is it for?</legend>
514
+ <div class="stack">
515
+ ${[
516
+ ['pages', 'A page and everything below it'],
517
+ ['library', 'A Library folder and everything in it'],
518
+ ['field', 'One field on a page type'],
519
+ ].map(
520
+ ([kind, label]) => html`<label class="level ${a.kind === kind ? 'chosen' : ''}"><input
521
+ type="radio"
522
+ name="exception-kind"
523
+ .checked=${a.kind === kind}
524
+ @change=${() => (this._adding = { kind, level: kind === 'field' ? 'see' : 'see' })} /><strong>${label}</strong></label>`,
525
+ )}
526
+ </div>
527
+ </fieldset>
528
+ <div class="step">
529
+ <span class="step-label">2. ${field ? 'Which field?' : 'Which one?'}</span>
530
+ ${
531
+ field
532
+ ? html`<umb-input-document-type
533
+ max="1"
534
+ .selection=${a.typeId ? [a.typeId] : []}
535
+ @change=${(e) => e.target.selection?.[0] && this.#chooseType(e.target.selection[0])}></umb-input-document-type>
536
+ ${
537
+ a.fields
538
+ ? html`<uui-select
539
+ label="Field"
540
+ .options=${[{ name: 'Choose a field', value: '', selected: !a.fieldId }, ...a.fields.map((f) => ({ name: f.name, value: f.id, selected: f.id === a.fieldId }))]}
541
+ @change=${(e) => set({ fieldId: e.target.value || undefined })}></uui-select>`
542
+ : nothing
543
+ }`
544
+ : a.kind === 'library'
545
+ ? html`<umb-input-element max="1" ?folderOnly=${true} @change=${async (e) => {
546
+ const id = e.target.selection?.[0]
547
+ const { data } = id ? await this.#elements.requestItems([id]) : { data: [] }
548
+ set({ placeId: id, placeName: data?.[0]?.name ?? data?.[0]?.variants?.[0]?.name })
549
+ }}></umb-input-element>`
550
+ : html`<umb-input-document max="1" @change=${async (e) => {
551
+ const id = e.target.selection?.[0]
552
+ const { data } = id ? await this.#documents.requestItems([id]) : { data: [] }
553
+ set({ placeId: id, placeName: data?.[0]?.variants?.[0]?.name ?? data?.[0]?.name })
554
+ }}></umb-input-document>`
555
+ }
556
+ </div>
557
+ <fieldset>
558
+ <legend>3. What can they do there?</legend>
559
+ ${
560
+ field
561
+ ? html`<div class="levels">
562
+ ${[
563
+ ['see', "See it, can't change it"],
564
+ ['edit', 'Change it'],
565
+ ].map(
566
+ ([
567
+ id,
568
+ label,
569
+ ]) => html`<label class="level ${a.level === id ? 'chosen' : ''}"><input
570
+ type="radio"
571
+ name="exception-level"
572
+ .checked=${a.level === id}
573
+ @change=${() => set({ level: id })} /><strong>${label}</strong></label>`,
574
+ )}
575
+ </div>`
576
+ : this.#renderLevels(a.kind, a.level, (id) => set({ level: id }))
577
+ }
578
+ </fieldset>
579
+ <p class="summary">${exceptionSummary(this._group.name ?? 'This group', a.kind, placeName, a.level)}</p>
580
+ <div class="actions">
581
+ <uui-button look="secondary" label="Cancel" @click=${() => (this._adding = undefined)}></uui-button>
582
+ <uui-button
583
+ look="primary"
584
+ label="Add exception"
585
+ ?disabled=${field ? !(a.typeId && a.fieldId) : !a.placeId}
586
+ @click=${() => this.#addException()}></uui-button>
587
+ </div>
588
+ </uui-box>`
589
+ }
590
+
591
+ // ---- Data Transfer
592
+
593
+ #renderTransfer() {
594
+ const verbs = this.#verbs
595
+ const groups = [...new Set(TRANSFER.map((entry) => entry.group))]
596
+ return html`
597
+ ${this.#renderSystemNote()}
598
+ ${groups.map(
599
+ (group) => html`<uui-box headline=${group}>
600
+ ${TRANSFER.filter((entry) => entry.group === group).map((entry) => {
601
+ const blocked = entry.under && !verbs.includes(entry.under)
602
+ return html`<label class="transfer ${entry.under ? 'under' : ''} ${entry.warning ? 'warning' : ''}">
603
+ <input
604
+ type="checkbox"
605
+ .checked=${verbs.includes(entry.verb)}
606
+ ?disabled=${this.#permissionsLocked || blocked}
607
+ @change=${(e) => this.#setVerbs(withVerb(verbs, entry.verb, e.target.checked))} />
608
+ <span><strong>${entry.label}</strong><span class="muted">${entry.line}</span></span>
609
+ </label>`
610
+ })}
611
+ </uui-box>`,
612
+ )}
613
+ `
614
+ }
615
+
616
+ // ---- People
617
+
618
+ #renderPeople() {
619
+ const alias = (this._group.alias ?? '').toLowerCase()
620
+ const unownable =
621
+ alias === 'admin' || this.#verbs.some((verb) => verb.startsWith('Crombolo.Remote.'))
622
+ const owners = this._group.owners ?? []
623
+ return html`<div class="people">
624
+ <umb-user-group-workspace-users ?readonly=${!this._canManageMembers}></umb-user-group-workspace-users>
625
+ <uui-box headline="Owners">
626
+ ${
627
+ unownable && owners.length === 0
628
+ ? html`<p class="muted">${
629
+ alias === 'admin'
630
+ ? 'The administrators group never has owners: only an administrator can make someone an administrator.'
631
+ : "This group can't have owners, because it can move sites or install code. Only an administrator can add people to it."
632
+ }</p>`
633
+ : html`<p class="muted">Owners can manage group members</p>
634
+ <umb-user-group-input
635
+ ?readonly=${this._readOnly}
636
+ .selection=${owners.map((owner) => owner.unique)}
637
+ @change=${(e) =>
638
+ this.#set(
639
+ 'owners',
640
+ e.target.selection.map((unique) => ({ unique })),
641
+ )}></umb-user-group-input>`
642
+ }
643
+ </uui-box>
644
+ </div>`
645
+ }
646
+
647
+ // ---- the page
648
+
649
+ #notice() {
650
+ if (!this._readOnly) return nothing
651
+ return html`<div class="notice" role="status">
652
+ <uui-icon name="icon-lock"></uui-icon>
653
+ ${
654
+ this._canManageMembers
655
+ ? "Only an administrator can change what this group allows. You can choose who's in it."
656
+ : 'Only an administrator can change this group.'
657
+ }
658
+ </div>`
659
+ }
660
+
661
+ render() {
662
+ const tabs = TABS.filter((tab) => !tab.adminOnly || !this._readOnly)
663
+ const count = this.#exceptions.length
664
+ const body = {
665
+ access: () => this.#renderAccess(),
666
+ permissions: () => this.#renderPermissions(),
667
+ exceptions: () => this.#renderExceptions(),
668
+ transfer: () => this.#renderTransfer(),
669
+ people: () => this.#renderPeople(),
670
+ }[this._tab]
671
+ return html`
672
+ <uui-tab-group>
673
+ ${tabs.map(
674
+ (tab) => html`<uui-tab
675
+ label=${tab.label}
676
+ ?active=${this._tab === tab.id}
677
+ @click=${() => (this._tab = tab.id)}>${tab.label}${
678
+ tab.id === 'exceptions' && count > 0
679
+ ? html` <span class="count">${count}</span>`
680
+ : nothing
681
+ }</uui-tab>`,
682
+ )}
683
+ </uui-tab-group>
684
+ <div class="body">${this.#notice()} ${body()}</div>
685
+ `
686
+ }
687
+
688
+ static styles = [
689
+ UmbTextStyles,
690
+ css`
691
+ :host { display: block; }
692
+ uui-tab-group { padding: 0 var(--uui-size-layout-1); border-bottom: 1px solid var(--uui-color-border); background: var(--uui-color-surface); }
693
+ .count { background: var(--uui-color-selected); color: var(--uui-color-selected-contrast); border-radius: 999px; padding: 0 8px; font-size: 12px; }
694
+ .body { padding: var(--uui-size-layout-1); display: flex; flex-direction: column; gap: var(--uui-size-space-4); max-width: 960px; }
695
+ .intro, .note, .muted, .empty { color: var(--uui-color-text-alt); margin: 0; }
696
+ .intro-row { display: flex; gap: var(--uui-size-space-4); align-items: flex-start; flex-wrap: wrap; }
697
+ .intro-row .intro { flex: 1 1 400px; }
698
+ .notice { display: flex; gap: var(--uui-size-space-3); align-items: center; padding: var(--uui-size-space-4) var(--uui-size-space-5); border: 1px solid var(--uui-color-border); border-radius: var(--uui-border-radius); background: var(--uui-color-surface-alt); }
699
+ .area-head { display: flex; align-items: center; gap: var(--uui-size-space-4); }
700
+ .area-text { flex: 1; min-width: 0; }
701
+ .area-text h2, .kind-head h2 { margin: 0; font-size: var(--uui-type-default-size); }
702
+ .area-text p { margin: 2px 0 0; color: var(--uui-color-text-alt); font-size: 13px; }
703
+ .area.off h2 { color: var(--uui-color-text-alt); }
704
+ .state { font-size: 13px; color: var(--uui-color-text-alt); }
705
+ .area-body { border-top: 1px solid var(--uui-color-divider); margin-top: var(--uui-size-space-4); padding: var(--uui-size-space-2) 0 0 64px; }
706
+ .row { display: flex; gap: var(--uui-size-space-4); padding: var(--uui-size-space-3) 0; align-items: flex-start; flex-wrap: wrap; }
707
+ .row + .row { border-top: 1px solid var(--uui-color-divider); }
708
+ .row-label { width: 110px; font-weight: 600; padding-top: 4px; }
709
+ .row-value { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: var(--uui-size-space-3); }
710
+ .switch { width: 48px; height: 28px; border-radius: 999px; border: 0; background: var(--uui-color-border-emphasis); position: relative; flex: none; padding: 0; cursor: pointer; }
711
+ .switch span { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 999px; background: #fff; transition: left 120ms; }
712
+ .switch.on { background: var(--uui-color-selected); }
713
+ .switch.on span { left: 23px; }
714
+ .switch:disabled { cursor: default; opacity: 0.6; }
715
+ .kind { background: var(--uui-color-surface); border: 1px solid var(--uui-color-border); border-radius: var(--uui-border-radius); padding: var(--uui-size-space-5); display: flex; flex-direction: column; gap: var(--uui-size-space-4); }
716
+ .kind.off { background: var(--uui-color-surface-alt); border-style: dashed; }
717
+ .kind.off .levels { opacity: 0.45; }
718
+ .kind-head { display: flex; align-items: center; gap: var(--uui-size-space-3); flex-wrap: wrap; }
719
+ .pill { font-size: 13px; background: var(--uui-color-divider); border-radius: 999px; padding: 2px 12px; }
720
+ .link { background: none; border: 0; padding: 0; color: var(--uui-color-interactive); text-decoration: underline; cursor: pointer; font: inherit; }
721
+ .levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--uui-size-space-2); align-items: stretch; }
722
+ .level { display: flex; gap: var(--uui-size-space-2); align-items: flex-start; border: 1px solid var(--uui-color-border); border-radius: var(--uui-border-radius); padding: var(--uui-size-space-3); min-height: 44px; box-sizing: border-box; cursor: pointer; }
723
+ .level.chosen { border-color: var(--uui-color-selected); background: var(--uui-color-surface-emphasis); }
724
+ .level-text { display: flex; flex-direction: column; gap: 2px; }
725
+ .level-text span { color: var(--uui-color-text-alt); font-size: 12px; }
726
+ .custom { align-self: center; font-weight: 600; }
727
+ .follow, .stack { display: flex; gap: var(--uui-size-space-2); flex-wrap: wrap; }
728
+ .stack { flex-direction: column; }
729
+ details summary { cursor: pointer; color: var(--uui-color-interactive); min-height: 32px; display: flex; align-items: center; }
730
+ .verbs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--uui-size-space-2) var(--uui-size-space-5); padding: var(--uui-size-space-3) 0; }
731
+ .verb { display: flex; gap: var(--uui-size-space-2); align-items: center; min-height: 32px; }
732
+ .exception { display: flex; gap: var(--uui-size-space-4); align-items: center; padding: var(--uui-size-space-3) 0; flex-wrap: wrap; }
733
+ .exception + .exception { border-top: 1px solid var(--uui-color-divider); }
734
+ .exception-text { flex: 1 1 300px; }
735
+ .adding fieldset { border: 0; padding: 0; margin: 0 0 var(--uui-size-space-4); }
736
+ .adding legend, .step-label { font-size: 13px; color: var(--uui-color-text-alt); margin-bottom: var(--uui-size-space-2); display: block; }
737
+ .step { margin-bottom: var(--uui-size-space-4); display: flex; flex-direction: column; gap: var(--uui-size-space-2); }
738
+ .summary { background: var(--uui-color-surface-alt); border-radius: var(--uui-border-radius); padding: var(--uui-size-space-3) var(--uui-size-space-4); margin: 0 0 var(--uui-size-space-4); }
739
+ .actions { display: flex; gap: var(--uui-size-space-3); justify-content: flex-end; }
740
+ .transfer { display: flex; gap: var(--uui-size-space-3); align-items: flex-start; padding: var(--uui-size-space-3) 0; }
741
+ .transfer > span { display: flex; flex-direction: column; gap: 2px; }
742
+ .transfer + .transfer { border-top: 1px solid var(--uui-color-divider); }
743
+ .transfer.under { padding-left: 32px; }
744
+ .transfer.warning { border: 1px solid var(--uui-color-warning); background: var(--uui-color-warning-standalone, #fff6e5); border-radius: var(--uui-border-radius); padding: var(--uui-size-space-3); }
745
+ .people { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--uui-size-space-4); align-items: start; }
746
+ `,
747
+ ]
748
+ }
749
+
750
+ customElements.define('crombolo-group-editor', CromboloGroupEditorElement)