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