@crombolo/backoffice-host 0.35.2 → 0.36.2

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/backoffice-host",
3
- "version": "0.35.2",
3
+ "version": "0.36.2",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@crombolo/core": "0.35.2",
34
+ "@crombolo/core": "0.36.2",
35
35
  "@crombolo/backoffice-dist": "18.2.0"
36
36
  }
37
37
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo App Preview",
4
4
  "id": "Crombolo.AppPreview",
5
- "version": "0.35.2",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,13 @@
1
+ /** The select reserves an empty value for its disabled placeholder. */
2
+ export const NO_FORM_VALUE = '@none'
3
+
4
+ /** Choices for the form picker, including a saved form that has since gone. */
5
+ export function formPickerOptions(forms, value) {
6
+ const options = [
7
+ { name: 'No form', value: NO_FORM_VALUE, selected: !value },
8
+ ...forms.map((form) => ({ name: form.name, value: form.key, selected: form.key === value })),
9
+ ]
10
+ if (value && !forms.some((form) => form.key === value))
11
+ options.push({ name: 'Unavailable form', value, selected: true })
12
+ return options
13
+ }
@@ -5,28 +5,18 @@
5
5
  * than from a tree of nodes: there is nothing in the database to browse. The
6
6
  * stored value is the form's key, which is what a render resolves back to the
7
7
  * definition.
8
- *
9
- * Shows the alias beside the name because a form is referred to by alias
10
- * everywhere else — in a view, in a workflow's settings, in a diff.
11
8
  */
12
- import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
9
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
13
10
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
14
-
15
- const forms = async () => {
16
- const href = document.querySelector('base')?.getAttribute('href') ?? '/umbraco/'
17
- const response = await fetch(`${href.replace(/\/$/, '')}/crombolo/api/forms`, {
18
- credentials: 'include',
19
- headers: { accept: 'application/json' },
20
- })
21
- if (!response.ok) throw new Error(`forms responded ${response.status}`)
22
- return (await response.json()).items ?? []
23
- }
11
+ import { formPickerOptions, NO_FORM_VALUE } from './form-picker-options.js'
12
+ import { listForms, readForm } from './forms-client.js'
24
13
 
25
14
  export default class CromboloFormPickerElement extends UmbLitElement {
26
15
  static properties = {
27
16
  value: { type: String },
28
17
  _items: { state: true },
29
18
  _failed: { state: true },
19
+ _detail: { state: true },
30
20
  }
31
21
 
32
22
  constructor() {
@@ -34,12 +24,14 @@ export default class CromboloFormPickerElement extends UmbLitElement {
34
24
  this.value = ''
35
25
  this._items = undefined
36
26
  this._failed = false
27
+ this._detail = undefined
37
28
  }
38
29
 
39
30
  connectedCallback() {
40
31
  super.connectedCallback()
41
- forms().then(
32
+ listForms().then(
42
33
  (items) => {
34
+ this._failed = false
43
35
  this._items = items
44
36
  },
45
37
  () => {
@@ -48,6 +40,22 @@ export default class CromboloFormPickerElement extends UmbLitElement {
48
40
  )
49
41
  }
50
42
 
43
+ updated(changed) {
44
+ if (changed.has('value') || changed.has('_items')) this.#loadFields()
45
+ }
46
+
47
+ async #loadFields() {
48
+ const key = this.value
49
+ this._detail = undefined
50
+ if (!this._items?.some((form) => form.key === key)) return
51
+ try {
52
+ const detail = await readForm(key)
53
+ if (this.value === key) this._detail = { key, definition: detail.definition }
54
+ } catch {
55
+ if (this.value === key) this._detail = { key, failed: true }
56
+ }
57
+ }
58
+
51
59
  /**
52
60
  * A plain `change` on the host, which is what `umb-property` listens for.
53
61
  *
@@ -57,14 +65,14 @@ export default class CromboloFormPickerElement extends UmbLitElement {
57
65
  */
58
66
  #pick(event) {
59
67
  event.stopPropagation()
60
- this.value = event.target.value || undefined
68
+ this.value = event.target.value === NO_FORM_VALUE ? undefined : event.target.value || undefined
61
69
  this.dispatchEvent(new Event('change'))
62
70
  }
63
71
 
64
72
  render() {
65
73
  if (this._failed) return html`<uui-box><p>The list of forms could not be loaded.</p></uui-box>`
66
74
  if (this._items === undefined) return html`<uui-loader></uui-loader>`
67
- if (this._items.length === 0)
75
+ if (this._items.length === 0 && !this.value)
68
76
  return html`
69
77
  <p class="empty">
70
78
  This site has no forms yet. Add one in the Forms section.
@@ -72,34 +80,62 @@ export default class CromboloFormPickerElement extends UmbLitElement {
72
80
  `
73
81
  return html`
74
82
  <uui-select
75
- .value=${this.value ?? ''}
83
+ .options=${formPickerOptions(this._items, this.value)}
76
84
  @change=${this.#pick}
77
85
  label="Form"
78
- placeholder="Choose a form"
79
- >
80
- <option value="">(none)</option>
81
- ${repeat(
82
- this._items,
83
- (form) => form.key,
84
- (form) => html`
85
- <option value=${form.key} ?selected=${form.key === this.value}>
86
- ${form.name} (${form.alias})
87
- </option>
88
- `,
89
- )}
90
- </uui-select>
86
+ ></uui-select>
91
87
  ${this.value ? html`<p class="detail">${this.#describe()}</p>` : nothing}
88
+ ${
89
+ this._items.some((form) => form.key === this.value)
90
+ ? html`<details>
91
+ <summary>View form fields</summary>
92
+ ${this.#fields()}
93
+ </details>`
94
+ : nothing
95
+ }
92
96
  `
93
97
  }
94
98
 
95
99
  #describe() {
96
100
  const form = this._items?.find((item) => item.key === this.value)
97
- if (!form) return 'This form is no longer in schema/forms/.'
101
+ if (!form) return 'The selected form is no longer available.'
98
102
  const fields = `${form.fieldCount} field${form.fieldCount === 1 ? '' : 's'}`
99
103
  const pages = `${form.pageCount} page${form.pageCount === 1 ? '' : 's'}`
100
104
  return `${fields} over ${pages}${form.storeEntries ? '' : '; entries are not stored'}`
101
105
  }
102
106
 
107
+ #fields() {
108
+ const detail = this._detail?.key === this.value ? this._detail : undefined
109
+ if (!detail) return html`<p role="status">Loading form fields…</p>`
110
+ if (detail.failed)
111
+ return html`<p role="alert">The form fields could not be loaded.</p>
112
+ <uui-button label="Try again" look="secondary" @click=${() => this.#loadFields()}></uui-button>`
113
+ return detail.definition.pages.map(
114
+ (page, index) => html`<section aria-label=${page.caption || `Page ${index + 1}`}>
115
+ <h4>${page.caption || `Page ${index + 1}`}</h4>
116
+ ${page.groups.map(
117
+ (group) => html`<div>
118
+ ${group.caption ? html`<h5>${group.caption}</h5>` : nothing}
119
+ <ul class="fields">
120
+ ${group.fields.map(
121
+ (field) => html`<li>
122
+ <span>${field.caption || field.alias}</span>
123
+ ${field.mandatory ? html`<small class="required">Required</small>` : nothing}
124
+ ${field.helpText ? html`<p>${field.helpText}</p>` : nothing}
125
+ ${
126
+ field.values?.length
127
+ ? html`<ul>${field.values.map((choice) => html`<li>${choice}</li>`)}</ul>`
128
+ : nothing
129
+ }
130
+ </li>`,
131
+ )}
132
+ </ul>
133
+ </div>`,
134
+ )}
135
+ </section>`,
136
+ )
137
+ }
138
+
103
139
  static styles = css`
104
140
  :host {
105
141
  display: block;
@@ -110,6 +146,23 @@ export default class CromboloFormPickerElement extends UmbLitElement {
110
146
  font-size: var(--uui-type-small-size, 0.8rem);
111
147
  margin: var(--uui-size-space-2, 6px) 0 0;
112
148
  }
149
+ details {
150
+ margin-top: var(--uui-size-space-4, 12px);
151
+ }
152
+ summary {
153
+ cursor: pointer;
154
+ }
155
+ .fields > li {
156
+ margin-bottom: var(--uui-size-space-3, 9px);
157
+ }
158
+ .fields p {
159
+ margin: 0;
160
+ color: var(--uui-color-text-alt);
161
+ }
162
+ .required {
163
+ margin-left: var(--uui-size-space-2, 6px);
164
+ color: var(--uui-color-text-alt);
165
+ }
113
166
  `
114
167
  }
115
168
 
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Localizations",
4
4
  "id": "Crombolo.Localizations",
5
- "version": "0.35.2",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -35,7 +35,7 @@ export default class CromboloMediaAccessInfoElement extends UmbLitElement {
35
35
 
36
36
  render() {
37
37
  if (!this._state) return nothing
38
- return html`<umb-workspace-info-app-layout headline="Who can see it">
38
+ return html`<umb-workspace-info-app-layout headline="Public Access">
39
39
  <div class="body">
40
40
  ${this._state.protected ? html`<uui-tag color="warning" look="primary">Protected</uui-tag>` : nothing}
41
41
  <span>${summarise(this._state)}</span>
@@ -1,30 +1,31 @@
1
1
  /**
2
- * The Permissions dialog for a media folder or item (story 196): who may see
3
- * and change it, by member group, and for a folder what files added to it
4
- * later get. Registered by `media-access.js`.
2
+ * The Permissions dialog for a media folder or item (story 205): whether it
3
+ * inherits the folder above's Public Access, or who may read and change it, by
4
+ * group or individual member. Registered by `media-access.js`.
5
5
  */
6
6
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
7
  import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
8
+ import '@umbraco-cms/backoffice/member'
8
9
  import {
9
10
  bytesOf,
10
- FILE_READ_CHOICES,
11
- FILE_WRITE_CHOICES,
12
- groupRows,
11
+ describeAccess,
12
+ formFor,
13
+ inheritedForm,
13
14
  megabytesOf,
14
- NEW_READ_CHOICES,
15
- NEW_WRITE_CHOICES,
16
- PUBLIC_WARNING,
15
+ PUBLIC_NOTE,
16
+ READ_MODES,
17
17
  readMediaAccess,
18
18
  requestFor,
19
19
  saveMediaAccess,
20
- summarise,
21
20
  usedByText,
21
+ WRITE_MODES,
22
22
  } from './media-access.js'
23
23
 
24
24
  export default class CromboloMediaAccessModalElement extends UmbModalBaseElement {
25
25
  static properties = {
26
26
  _state: { state: true },
27
27
  _form: { state: true },
28
+ _changed: { state: true },
28
29
  _busy: { state: true },
29
30
  _message: { state: true },
30
31
  }
@@ -33,6 +34,7 @@ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement
33
34
  super()
34
35
  this._state = undefined
35
36
  this._form = undefined
37
+ this._changed = false
36
38
  this._busy = false
37
39
  this._message = ''
38
40
  }
@@ -52,50 +54,54 @@ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement
52
54
 
53
55
  #show(state) {
54
56
  this._state = state
55
- this._form = {
56
- hasFile: state.hasFile,
57
- own: state.own
58
- ? { ...state.own, groups: groupRows(state.own, state.memberGroups) }
59
- : undefined,
60
- item: { readPolicy: state.item.readPolicy, writePolicy: state.item.writePolicy },
61
- }
57
+ this._form = formFor(state)
58
+ this._changed = false
62
59
  }
63
60
 
64
- #setOwn() {
65
- const from = this._state.inherited
66
- this._form = {
67
- ...this._form,
68
- own: {
69
- publicRead: from?.publicRead ?? false,
70
- groups: groupRows(from, this._state.memberGroups),
71
- newRead: from?.newRead ?? null,
72
- newWrite: from?.newWrite ?? null,
73
- memberTypes: [...(from?.memberTypes ?? [])],
74
- memberMaxBytes: from?.memberMaxBytes ?? null,
75
- },
76
- }
61
+ /** Any edit gives the item settings of its own, starting from those it inherited. */
62
+ #change(patch) {
63
+ this._form = { ...this._form, inherit: false, ...patch }
64
+ this._changed = true
77
65
  }
78
66
 
79
- #tickType(id, on) {
80
- const types = this._form.own.memberTypes ?? []
81
- this.#change({ memberTypes: on ? [...types, id] : types.filter((t) => t !== id) })
67
+ #setInherit(on) {
68
+ if (on) {
69
+ this._form = inheritedForm(this._state)
70
+ this._changed = true
71
+ } else this.#change({})
82
72
  }
83
73
 
84
- #change(patch) {
85
- this._form = { ...this._form, own: { ...this._form.own, ...patch } }
74
+ #setMode(action, mode) {
75
+ this.#change({ [action]: mode, ...(action === 'read' ? { allMembers: false } : {}) })
86
76
  }
87
77
 
88
- #tick(name, which, on) {
78
+ #tick(name, action, on) {
89
79
  this.#change({
90
- groups: this._form.own.groups.map((g) => (g.name === name ? { ...g, [which]: on } : g)),
80
+ groups: this._form.groups.map((g) => (g.name === name ? { ...g, [action]: on } : g)),
81
+ ...(action === 'read' ? { allMembers: false } : {}),
91
82
  })
92
83
  }
93
84
 
85
+ #setMembers(action, keys) {
86
+ const selected = new Set(keys)
87
+ const members = this._form.members.map((m) => ({ ...m, [action]: selected.has(m.key) }))
88
+ for (const key of keys)
89
+ if (!members.some((m) => m.key === key))
90
+ members.push({ key, read: action === 'read', write: action === 'write' })
91
+ this.#change({ members, ...(action === 'read' ? { allMembers: false } : {}) })
92
+ }
93
+
94
+ #tickType(id, on) {
95
+ const types = this._form.memberTypes
96
+ this.#change({ memberTypes: on ? [...types, id] : types.filter((t) => t !== id) })
97
+ }
98
+
94
99
  async #save() {
100
+ if (!this._changed) return this._submitModal()
95
101
  this._busy = true
96
102
  this._message = ''
97
103
  try {
98
- this.#show(await saveMediaAccess(this.data?.unique, requestFor(this._form)))
104
+ this.#show(await saveMediaAccess(this.data?.unique, requestFor(this._form, this._state.item)))
99
105
  this._submitModal()
100
106
  } catch (error) {
101
107
  this._message = error.message
@@ -104,159 +110,88 @@ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement
104
110
  }
105
111
  }
106
112
 
107
- #choices(label, choices, value, onPick) {
108
- return html`<div class="choices" role="radiogroup" aria-label=${label}>
109
- <p class="label">${label}</p>
110
- ${choices.map(
111
- (choice) => html`<label>
112
- <input
113
- type="radio"
114
- .checked=${value === choice.value}
115
- @change=${() => onPick(choice.value)}
116
- />
117
- ${choice.label}
118
- </label>`,
119
- )}
120
- ${value === 'public' ? html`<p class="warning">${PUBLIC_WARNING}</p>` : nothing}
121
- </div>`
113
+ #toggle(label, modes, value, onPick) {
114
+ const locked = this._form.inherit
115
+ return html`<p class="label" id=${`${label}-label`}>${label}</p>
116
+ <uui-button-group role="radiogroup" aria-labelledby=${`${label}-label`}>
117
+ ${modes.map(
118
+ (mode) => html`<uui-button
119
+ role="radio"
120
+ aria-checked=${value === mode.value ? 'true' : 'false'}
121
+ label=${mode.label}
122
+ look=${value === mode.value ? 'primary' : 'outline'}
123
+ ?disabled=${locked}
124
+ @click=${() => onPick(mode.value)}
125
+ >${mode.label}</uui-button
126
+ >`,
127
+ )}
128
+ </uui-button-group>`
122
129
  }
123
130
 
124
- #renderRule() {
125
- const own = this._form.own
126
- if (!own) {
127
- const from = this._state.inherited
128
- return html`<uui-box headline="Who can see and change it">
129
- <p>
130
- ${
131
- from
132
- ? html`Follows the permissions set on <strong>${from.from.name}</strong>.`
133
- : 'Nothing above it sets permissions, so anyone with the link can see it.'
134
- }
135
- </p>
136
- <uui-button look="secondary" label="Set its own" @click=${() => this.#setOwn()}
137
- >Set its own</uui-button
138
- >
139
- </uui-box>`
140
- }
141
- return html`<uui-box headline="Who can see and change it">
142
- <label class="public">
143
- <input
144
- type="checkbox"
145
- .checked=${own.publicRead}
146
- @change=${(e) => this.#change({ publicRead: e.target.checked })}
147
- />
148
- Anyone with the link can see it
149
- </label>
150
- ${own.publicRead ? html`<p class="warning">${PUBLIC_WARNING}</p>` : nothing}
151
- ${
152
- own.groups.length === 0
153
- ? html`<p class="fine">This site has no member groups yet.</p>`
154
- : html`<table>
155
- <thead>
156
- <tr><th>Member group</th><th>Can see</th><th>Can change</th></tr>
157
- </thead>
158
- <tbody>
159
- ${own.groups.map(
160
- (g) => html`<tr>
161
- <td>${g.name}</td>
162
- <td>
163
- <input
164
- type="checkbox"
165
- aria-label=${`${g.name} can see`}
166
- .checked=${g.read}
167
- @change=${(e) => this.#tick(g.name, 'read', e.target.checked)}
168
- />
169
- </td>
170
- <td>
171
- <input
172
- type="checkbox"
173
- aria-label=${`${g.name} can change`}
174
- .checked=${g.write}
175
- @change=${(e) => this.#tick(g.name, 'write', e.target.checked)}
176
- />
177
- </td>
178
- </tr>`,
179
- )}
180
- </tbody>
181
- </table>`
182
- }
131
+ #access(action) {
132
+ const form = this._form
133
+ const mode = form[action]
134
+ const label = action === 'read' ? 'Read' : 'Write'
135
+ const members = form.members.filter((m) => m[action]).map((m) => m.key)
136
+ return html`<section class="access" aria-label=${label}>
137
+ ${this.#toggle(label, action === 'read' ? READ_MODES : WRITE_MODES, mode, (v) => this.#setMode(action, v))}
138
+ ${mode === 'public' ? html`<p class="fine">${PUBLIC_NOTE}</p>` : nothing}
139
+ ${mode === 'private' ? html`<p class="fine">Only back-office users with the required permissions.</p>` : nothing}
183
140
  ${
184
- this._state.inherited
185
- ? html`<uui-button
186
- look="secondary"
187
- label="Follow the folder above instead"
188
- @click=${() => {
189
- this._form = { ...this._form, own: undefined }
190
- }}
191
- >Follow the folder above instead</uui-button
192
- >`
141
+ mode === 'custom'
142
+ ? html`<div class="custom">
143
+ ${action === 'read' && form.allMembers ? html`<p>All signed-in members currently have read access. Choose groups or members to replace that setting.</p>` : nothing}
144
+ <h4>Member groups</h4>
145
+ ${
146
+ form.groups.length
147
+ ? form.groups.map(
148
+ (g) =>
149
+ html`<label><input type="checkbox" .checked=${g[action]} ?disabled=${form.inherit}
150
+ @change=${(e) => this.#tick(g.name, action, e.target.checked)} />${g.name}</label>`,
151
+ )
152
+ : html`<p>No member groups are available.</p>`
153
+ }
154
+ <h4>Members</h4>
155
+ <umb-input-member .selection=${members} ?readonly=${form.inherit}
156
+ @change=${(e) => this.#setMembers(action, e.target.selection ?? [])}></umb-input-member>
157
+ </div>`
193
158
  : nothing
194
159
  }
195
- </uui-box>
196
- ${
197
- this._form.hasFile
198
- ? nothing
199
- : html`<uui-box headline="Files added here later">
200
- ${this.#choices('Who can see them', NEW_READ_CHOICES, own.newRead, (v) =>
201
- this.#change({ newRead: v }),
202
- )}
203
- ${this.#choices('Who can change them', NEW_WRITE_CHOICES, own.newWrite, (v) =>
204
- this.#change({ newWrite: v }),
205
- )}
206
- <p class="fine">Files already here keep what they have.</p>
207
- </uui-box>
208
- <uui-box headline="File types members may upload here">
209
- <p class="fine">
210
- Members can add files only through a feature of this site that offers it. Nothing
211
- is accepted unless it is ticked here.
212
- </p>
213
- <div class="types">
214
- ${this._state.memberFileTypes.map(
215
- (type) => html`<label>
216
- <input
217
- type="checkbox"
218
- .checked=${(own.memberTypes ?? []).includes(type.id)}
219
- @change=${(e) => this.#tickType(type.id, e.target.checked)}
220
- />
221
- ${type.label}
222
- </label>`,
223
- )}
224
- </div>
225
- <label class="size">
226
- Largest file, in MB
227
- <input
228
- type="number"
229
- min="0"
230
- step="0.5"
231
- placeholder="No limit of its own"
232
- .value=${megabytesOf(own.memberMaxBytes)}
233
- @change=${(e) => this.#change({ memberMaxBytes: bytesOf(e.target.value) })}
234
- />
235
- </label>
236
- </uui-box>`
237
- }`
160
+ </section>`
238
161
  }
239
162
 
240
- #renderFile() {
241
- if (!this._form.hasFile) return nothing
242
- const item = this._form.item
243
- const setItem = (patch) => {
244
- this._form = { ...this._form, item: { ...item, ...patch } }
245
- }
246
- const creator = this._state.item.creator
247
- return html`<uui-box headline="This file">
163
+ #renderRule() {
164
+ const form = this._form
165
+ return html`<uui-box headline="Public Access">
166
+ ${
167
+ this._state.hasParent
168
+ ? html`<label class="inherit"><input type="checkbox" .checked=${form.inherit}
169
+ @change=${(e) => this.#setInherit(e.target.checked)} />Inherit parent permissions</label>`
170
+ : nothing
171
+ }
172
+ ${this.#access('read')}${this.#access('write')}
173
+ ${
174
+ form.newRead === 'creator' || form.newWrite === 'creator'
175
+ ? html`<p class="fine">Files members add here can only be seen or changed by the member who added them, as set before.</p>`
176
+ : nothing
177
+ }
178
+ </uui-box>
248
179
  ${
249
- creator
250
- ? html`<p>Added by ${creator.name ?? 'a member who is no longer here'}.</p>`
180
+ !this._state.hasFile
181
+ ? html`<uui-box headline="Member uploads">
182
+ ${form.inherit ? html`<p class="fine">Inherited from the folder above. Changing these gives this folder permissions of its own.</p>` : nothing}
183
+ <h4>File types members may upload here</h4>
184
+ ${(this._state.memberFileTypes ?? []).map(
185
+ (type) => html`<label class="public"><input type="checkbox"
186
+ .checked=${form.memberTypes.includes(type.id)}
187
+ @change=${(e) => this.#tickType(type.id, e.target.checked)} />${type.label}</label>`,
188
+ )}
189
+ <label>Largest file, in MB<input type="number" min="0" step="0.5"
190
+ .value=${megabytesOf(form.memberMaxBytes)}
191
+ @change=${(e) => this.#change({ memberMaxBytes: bytesOf(e.target.value) })} /></label>
192
+ </uui-box>`
251
193
  : nothing
252
- }
253
- ${this.#choices('Who can see it', FILE_READ_CHOICES, item.readPolicy, (v) =>
254
- setItem({ readPolicy: v }),
255
- )}
256
- ${this.#choices('Who can change it', FILE_WRITE_CHOICES, item.writePolicy, (v) =>
257
- setItem({ writePolicy: v }),
258
- )}
259
- </uui-box>`
194
+ }`
260
195
  }
261
196
 
262
197
  render() {
@@ -264,14 +199,14 @@ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement
264
199
  return html`<umb-body-layout headline=${headline}>
265
200
  ${
266
201
  this._state && this._form
267
- ? html`<p class="summary">${summarise(this._state)}</p>
202
+ ? html`<p class="summary">${describeAccess(this._form, this._state)}</p>
268
203
  <p class="fine">Editors who can open this in Media can always see it.</p>
269
204
  ${
270
205
  this._state.usedBy?.length
271
206
  ? html`<p class="warning">${usedByText(this._state.usedBy)}</p>`
272
207
  : nothing
273
208
  }
274
- ${this.#renderRule()} ${this.#renderFile()}`
209
+ ${this.#renderRule()}`
275
210
  : this._message
276
211
  ? nothing
277
212
  : html`<uui-loader></uui-loader>`
@@ -315,11 +250,24 @@ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement
315
250
  margin-left: var(--uui-size-space-3, 9px);
316
251
  width: 8rem;
317
252
  }
318
- .choices label,
253
+ .inherit,
254
+ .custom label,
319
255
  .public {
320
256
  display: block;
321
257
  margin: var(--uui-size-space-2, 6px) 0;
322
258
  }
259
+ .inherit {
260
+ font-weight: bold;
261
+ margin-bottom: var(--uui-size-space-4, 12px);
262
+ }
263
+ uui-button-group {
264
+ margin: var(--uui-size-space-2, 6px) 0;
265
+ }
266
+ .access + .access {
267
+ margin-top: var(--uui-size-space-5, 18px);
268
+ border-top: 1px solid var(--uui-color-border, #ddd);
269
+ padding-top: var(--uui-size-space-3, 9px);
270
+ }
323
271
  .label {
324
272
  font-weight: bold;
325
273
  margin-bottom: 0;
@@ -1,8 +1,8 @@
1
1
  /**
2
- * "Permissions" on media folders and items (story 196): which member groups
3
- * may see and change them, and what files added to a folder later get. The
2
+ * "Permissions" on media folders and items (story 204): who may read and
3
+ * change them, and what files added to a folder later get. The
4
4
  * server keeps them at <backoffice>/crombolo/api/media-access/{key}, and
5
- * refuses what the user may not do whatever this shows. docs/media.md.
5
+ * refuses what the user may not do whatever this shows. docs/rendering.md, "Protected media".
6
6
  */
7
7
 
8
8
  export const MEDIA_ACCESS_MODAL = 'Crombolo.Modal.MediaAccess'
@@ -40,44 +40,11 @@ export const problemFor = (status) =>
40
40
  ? 'This media item could not be found.'
41
41
  : 'The permissions could not be loaded. Try again.'
42
42
 
43
- export const NEW_READ_CHOICES = [
44
- { value: null, label: 'As this folder says' },
45
- { value: 'public', label: 'Anyone with the link' },
46
- { value: 'groups', label: 'Members of the groups that can see this folder' },
47
- { value: 'creator', label: 'Only the member who added it' },
48
- ]
49
-
50
- export const NEW_WRITE_CHOICES = [
51
- { value: null, label: 'As this folder says' },
52
- { value: 'groups', label: 'Members of the groups that can change this folder' },
53
- { value: 'creator', label: 'Only the member who added it' },
54
- { value: 'none', label: 'No member' },
55
- ]
56
-
57
- export const FILE_READ_CHOICES = [
58
- { value: 'inherit', label: 'As its folder says' },
59
- { value: 'public', label: 'Anyone with the link' },
60
- { value: 'groups', label: 'Members of the groups that can see it' },
61
- { value: 'creator', label: 'Only the member who added it' },
62
- { value: 'none', label: 'No member' },
63
- ]
64
-
65
- export const FILE_WRITE_CHOICES = [
66
- { value: 'inherit', label: 'As its folder says' },
67
- { value: 'groups', label: 'Members of the groups that can change it' },
68
- { value: 'creator', label: 'Only the member who added it' },
69
- { value: 'none', label: 'No member' },
70
- ]
71
-
72
- export const PUBLIC_WARNING =
43
+ export const PUBLIC_NOTE =
73
44
  'Anyone who has the link can open these files, without signing in, and can pass the link on.'
74
45
 
75
- /** One line saying who can see a folder or file. */
76
- export function summarise(state) {
77
- if (!state) return ''
78
- if (!state.protected) return 'Anyone with the link can see this.'
79
- return 'Only the members chosen here, and editors who can open it in Media, can see this.'
80
- }
46
+ /** One line saying who can see and change a folder or file, as saved. */
47
+ export const summarise = (state) => (state ? describeAccess(formFor(state), state) : '')
81
48
 
82
49
  /**
83
50
  * The groups a rule shows: every member group on the site, ticked as the rule
@@ -106,22 +73,148 @@ export const bytesOf = (megabytes) => {
106
73
  : null
107
74
  }
108
75
 
109
- /** What the dialog sends: the rule (null to follow the folder above) and a file's own setting. */
110
- export function requestFor(form) {
76
+ /** Read audiences; the default, Enabled, lets anyone with the link see a file. */
77
+ export const READ_MODES = [
78
+ { value: 'public', label: 'Enabled' },
79
+ { value: 'private', label: 'Disabled' },
80
+ { value: 'custom', label: 'Custom' },
81
+ ]
82
+ /** Write audiences: members are never allowed to change files publicly. */
83
+ export const WRITE_MODES = [
84
+ { value: 'private', label: 'No Public Access' },
85
+ { value: 'custom', label: 'Custom' },
86
+ ]
87
+
88
+ /** An existing setting shown without broadening its audience. */
89
+ export function accessMode(policy, action, rule) {
90
+ if (policy === 'none' || (action === 'write' && ['public', 'members'].includes(policy)))
91
+ return 'private'
92
+ if (policy === 'public') return 'public'
93
+ if (policy !== 'inherit') return 'custom'
94
+ if (action === 'read' && (!rule || rule.publicRead)) return 'public'
95
+ const flag = action === 'read' ? 'read' : 'write'
96
+ return [...(rule?.groups ?? []), ...(rule?.members ?? [])].some((grant) => grant[flag])
97
+ ? 'custom'
98
+ : 'private'
99
+ }
100
+
101
+ /** Whether a folder or item follows the folder above it, with no settings of its own. */
102
+ export const inheritsParent = (state) =>
103
+ Boolean(state.hasParent) &&
104
+ !state.own &&
105
+ state.item.readPolicy === 'inherit' &&
106
+ state.item.writePolicy === 'inherit'
107
+
108
+ /**
109
+ * The dialog's form: the audiences a rule and an item's own policies come to.
110
+ * A file that may only be seen by the member who added it lists that member.
111
+ */
112
+ export function viewOf(rule, item, state) {
113
+ const members = (rule?.members ?? []).map((m) => ({ ...m }))
114
+ const creator = item.creator?.key
115
+ for (const action of ['read', 'write']) {
116
+ if (item[`${action}Policy`] !== 'creator' || !creator) continue
117
+ const existing = members.find((m) => m.key === creator)
118
+ if (existing) existing[action] = true
119
+ else members.push({ key: creator, read: action === 'read', write: action === 'write' })
120
+ }
121
+ const kept = (value) => (value === 'creator' ? value : null)
122
+ return {
123
+ read: accessMode(item.readPolicy, 'read', rule),
124
+ write: accessMode(item.writePolicy, 'write', rule),
125
+ allMembers: item.readPolicy === 'members',
126
+ groups: groupRows(rule, state.memberGroups ?? []),
127
+ members,
128
+ newRead: kept(state.own?.newRead),
129
+ newWrite: kept(state.own?.newWrite),
130
+ memberTypes: [...(rule?.memberTypes ?? [])],
131
+ memberMaxBytes: rule?.memberMaxBytes ?? null,
132
+ }
133
+ }
134
+
135
+ const INHERITED_ITEM = { readPolicy: 'inherit', writePolicy: 'inherit' }
136
+
137
+ /** The form for a folder or item as saved: following the folder above, or its own settings. */
138
+ export function formFor(state) {
139
+ const inherit = inheritsParent(state)
140
+ return {
141
+ inherit,
142
+ ...(inherit
143
+ ? viewOf(state.inherited, INHERITED_ITEM, state)
144
+ : viewOf(state.own ?? state.inherited, state.item, state)),
145
+ }
146
+ }
147
+
148
+ /** The form when "Inherit parent permissions" is ticked again: the folder above's settings. */
149
+ export const inheritedForm = (state) => ({
150
+ inherit: true,
151
+ ...viewOf(state.inherited, INHERITED_ITEM, state),
152
+ })
153
+
154
+ const listed = (names) =>
155
+ names.length <= 1 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`
156
+
157
+ const chosen = (form, action) => {
158
+ const groups = form.groups.filter((g) => g[action]).map((g) => g.name)
159
+ const count = form.members.filter((m) => m[action]).length
160
+ return listed([...groups, ...(count ? [`${count} chosen member${count === 1 ? '' : 's'}`] : [])])
161
+ }
162
+
163
+ /** Where a form's settings come from and who they let in, in a sentence or two. */
164
+ export function describeAccess(form, state) {
165
+ const source = form.inherit
166
+ ? state.inherited?.from
167
+ ? `Inherited from ${state.inherited.from.name}.`
168
+ : 'Default permissions.'
169
+ : state.hasParent
170
+ ? 'Set for this item.'
171
+ : ''
172
+ const readers = chosen(form, 'read')
173
+ const writers = chosen(form, 'write')
174
+ const read =
175
+ form.read === 'public'
176
+ ? 'Anyone with the link can see this.'
177
+ : form.read === 'private'
178
+ ? 'Only back-office users can see this.'
179
+ : form.allMembers
180
+ ? 'All signed-in members can see this.'
181
+ : readers
182
+ ? `Only ${readers} can see this.`
183
+ : 'Nobody has been chosen to see this yet.'
184
+ const write =
185
+ form.write === 'custom' && writers ? `${writers} can change it.` : 'No members can change it.'
186
+ return [source, read, write].filter(Boolean).join(' ')
187
+ }
188
+
189
+ /**
190
+ * What the dialog sends: no settings of its own when it inherits, else a rule
191
+ * holding both audiences. An all-members read nobody changed is kept as it was.
192
+ */
193
+ export function requestFor(form, original = INHERITED_ITEM) {
194
+ if (form.inherit) return { rule: null, item: { ...INHERITED_ITEM } }
195
+ const grants = (list) =>
196
+ list
197
+ .map((g) => ({
198
+ ...g,
199
+ read: form.read === 'custom' && g.read,
200
+ write: form.write === 'custom' && g.write,
201
+ }))
202
+ .filter((g) => g.read || g.write)
203
+ const members = grants(form.members)
111
204
  return {
112
- rule: form.own
113
- ? {
114
- publicRead: form.own.publicRead,
115
- groups: form.own.groups.filter((g) => g.read || g.write),
116
- newRead: form.own.newRead ?? null,
117
- newWrite: form.own.newWrite ?? null,
118
- memberTypes: form.own.memberTypes ?? [],
119
- memberMaxBytes: form.own.memberMaxBytes ?? null,
120
- }
121
- : null,
122
- ...(form.hasFile
123
- ? { item: { readPolicy: form.item.readPolicy, writePolicy: form.item.writePolicy } }
124
- : {}),
205
+ rule: {
206
+ publicRead: form.read === 'public',
207
+ groups: grants(form.groups),
208
+ ...(members.length ? { members } : {}),
209
+ newRead: form.newRead ?? null,
210
+ newWrite: form.newWrite ?? null,
211
+ memberTypes: form.memberTypes ?? [],
212
+ memberMaxBytes: form.memberMaxBytes ?? null,
213
+ },
214
+ item: {
215
+ readPolicy: form.allMembers && original.readPolicy === 'members' ? 'members' : 'inherit',
216
+ writePolicy: 'inherit',
217
+ },
125
218
  }
126
219
  }
127
220
 
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.35.2",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Sign-in Dialog",
4
4
  "id": "Crombolo.SignInDialog",
5
- "version": "0.35.2",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo",
4
4
  "id": "Crombolo.Core",
5
- "version": "0.35.2",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {