@crombolo/backoffice-host 0.34.0 → 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.34.0",
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.34.0",
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.34.0",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -36,6 +36,10 @@ export const installBundle = (name, version, applyContent = true, acceptServerCo
36
36
  export const uninstallBundle = (name) =>
37
37
  json('/uninstall', { method: 'POST', body: JSON.stringify({ name }) })
38
38
 
39
+ /** Where a created bundle's package downloads from, with `?withMedia=true` to carry its media files. */
40
+ export const createdDownloadUrl = (id, query = '') =>
41
+ `${base()}/created/${encodeURIComponent(id)}/download${query}`
42
+
39
43
  /** The npm package a created bundle downloads as. */
40
44
  export const readCreatedPackage = (id) => json(`/created/${encodeURIComponent(id)}/package`)
41
45
 
@@ -14,7 +14,8 @@ import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit
14
14
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
15
15
  import { umbConfirmModal } from '@umbraco-cms/backoffice/modal'
16
16
  import { UmbPackageRepository } from '@umbraco-cms/backoffice/package'
17
- import { readCreatedPackage, saveCreatedPackage } from './bundles-client.js'
17
+ import { createdDownloadUrl, readCreatedPackage, saveCreatedPackage } from './bundles-client.js'
18
+ import { downloadFile } from './download.js'
18
19
 
19
20
  const TAKE = 10
20
21
 
@@ -30,6 +31,8 @@ export default class CromboloBundlesCreatedOverviewElement extends UmbLitElement
30
31
  _packages: { state: true },
31
32
  _editing: { state: true },
32
33
  _draft: { state: true },
34
+ _downloading: { state: true },
35
+ _withMedia: { state: true },
33
36
  _problem: { state: true },
34
37
  }
35
38
 
@@ -117,6 +120,39 @@ export default class CromboloBundlesCreatedOverviewElement extends UmbLitElement
117
120
  `
118
121
  }
119
122
 
123
+ #toggleDownload(item) {
124
+ this._downloading = this._downloading === item.unique ? '' : item.unique
125
+ this._withMedia = false
126
+ }
127
+
128
+ /** The package, with its media files only when ticked: off by default (story 195). */
129
+ async #download(item) {
130
+ const query = this._withMedia ? '?withMedia=true' : ''
131
+ const pkg = this._packages[item.unique]
132
+ await downloadFile(
133
+ createdDownloadUrl(item.unique, query),
134
+ pkg ? `${pkg.name}-${pkg.version}.tgz` : 'bundle.tgz',
135
+ )
136
+ this._downloading = ''
137
+ }
138
+
139
+ #renderDownload(item) {
140
+ if (this._downloading !== item.unique) return nothing
141
+ return html`
142
+ <div class="package-editor">
143
+ <uui-checkbox
144
+ label="Include media files"
145
+ .checked=${this._withMedia}
146
+ @change=${(event) => (this._withMedia = event.target.checked)}></uui-checkbox>
147
+ <p>
148
+ Without them, installing the bundle brings its media items without their files.
149
+ </p>
150
+ <uui-button look="primary" label="Download" @click=${() => this.#download(item)}></uui-button>
151
+ <uui-button label="Cancel" @click=${() => (this._downloading = '')}></uui-button>
152
+ </div>
153
+ `
154
+ }
155
+
120
156
  #detail(item) {
121
157
  const pkg = this._packages[item.unique]
122
158
  return pkg ? `${pkg.name}@${pkg.version}` : ''
@@ -196,6 +232,10 @@ export default class CromboloBundlesCreatedOverviewElement extends UmbLitElement
196
232
  look="secondary"
197
233
  label="Name and version"
198
234
  @click=${() => this.#edit(item)}></uui-button>
235
+ <uui-button
236
+ look="secondary"
237
+ label="Download"
238
+ @click=${() => this.#toggleDownload(item)}></uui-button>
199
239
  <uui-button
200
240
  look="secondary"
201
241
  color="danger"
@@ -207,6 +247,7 @@ export default class CromboloBundlesCreatedOverviewElement extends UmbLitElement
207
247
  )}
208
248
  </uui-table>
209
249
  ${this._items.map((item) => this.#renderEditor(item))}
250
+ ${this._items.map((item) => this.#renderDownload(item))}
210
251
  </uui-box>
211
252
  `
212
253
  }
@@ -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.34.0",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,15 @@
1
+ /** Opens the Permissions dialog for a media folder or item (story 196). */
2
+ import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'
3
+ import { umbOpenModal } from '@umbraco-cms/backoffice/modal'
4
+ import { MEDIA_ACCESS_MODAL } from './media-access.js'
5
+
6
+ export class CromboloMediaAccessAction extends UmbEntityActionBase {
7
+ async execute() {
8
+ await umbOpenModal(this, MEDIA_ACCESS_MODAL, {
9
+ modal: { type: 'sidebar', size: 'medium' },
10
+ data: { unique: this.args.unique },
11
+ }).catch(() => undefined)
12
+ }
13
+ }
14
+
15
+ export { CromboloMediaAccessAction as api }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The media workspace's note of who can see an item, with a "Protected" badge
3
+ * when it is closed to visitors (story 196). Registered by `media-access.js`.
4
+ */
5
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
6
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
7
+ import { UMB_MEDIA_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/media'
8
+ import { readMediaAccess, summarise, usedByText } from './media-access.js'
9
+
10
+ export default class CromboloMediaAccessInfoElement extends UmbLitElement {
11
+ static properties = {
12
+ _state: { state: true },
13
+ }
14
+
15
+ #unique
16
+
17
+ constructor() {
18
+ super()
19
+ this._state = undefined
20
+ this.consumeContext(UMB_MEDIA_WORKSPACE_CONTEXT, (context) => {
21
+ this.observe(context?.unique, (unique) => {
22
+ if (!unique || unique === this.#unique) return
23
+ this.#unique = unique
24
+ readMediaAccess(unique).then(
25
+ (state) => {
26
+ this._state = state
27
+ },
28
+ () => {
29
+ this._state = undefined
30
+ },
31
+ )
32
+ })
33
+ })
34
+ }
35
+
36
+ render() {
37
+ if (!this._state) return nothing
38
+ return html`<umb-workspace-info-app-layout headline="Public Access">
39
+ <div class="body">
40
+ ${this._state.protected ? html`<uui-tag color="warning" look="primary">Protected</uui-tag>` : nothing}
41
+ <span>${summarise(this._state)}</span>
42
+ </div>
43
+ ${
44
+ this._state.usedBy?.length
45
+ ? html`<div class="body"><uui-tag look="secondary">In use</uui-tag><span>${usedByText(this._state.usedBy)}</span></div>`
46
+ : nothing
47
+ }
48
+ </umb-workspace-info-app-layout>`
49
+ }
50
+
51
+ static styles = css`
52
+ .body {
53
+ display: flex;
54
+ gap: var(--uui-size-space-3, 9px);
55
+ align-items: center;
56
+ padding: var(--uui-size-space-4, 12px) var(--uui-size-space-5, 18px);
57
+ }
58
+ `
59
+ }
60
+
61
+ customElements.define('crombolo-media-access-info', CromboloMediaAccessInfoElement)
@@ -0,0 +1,287 @@
1
+ /**
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
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
8
+ import '@umbraco-cms/backoffice/member'
9
+ import {
10
+ bytesOf,
11
+ describeAccess,
12
+ formFor,
13
+ inheritedForm,
14
+ megabytesOf,
15
+ PUBLIC_NOTE,
16
+ READ_MODES,
17
+ readMediaAccess,
18
+ requestFor,
19
+ saveMediaAccess,
20
+ usedByText,
21
+ WRITE_MODES,
22
+ } from './media-access.js'
23
+
24
+ export default class CromboloMediaAccessModalElement extends UmbModalBaseElement {
25
+ static properties = {
26
+ _state: { state: true },
27
+ _form: { state: true },
28
+ _changed: { state: true },
29
+ _busy: { state: true },
30
+ _message: { state: true },
31
+ }
32
+
33
+ constructor() {
34
+ super()
35
+ this._state = undefined
36
+ this._form = undefined
37
+ this._changed = false
38
+ this._busy = false
39
+ this._message = ''
40
+ }
41
+
42
+ connectedCallback() {
43
+ super.connectedCallback()
44
+ this.#load()
45
+ }
46
+
47
+ async #load() {
48
+ try {
49
+ this.#show(await readMediaAccess(this.data?.unique))
50
+ } catch (error) {
51
+ this._message = error.message
52
+ }
53
+ }
54
+
55
+ #show(state) {
56
+ this._state = state
57
+ this._form = formFor(state)
58
+ this._changed = false
59
+ }
60
+
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
65
+ }
66
+
67
+ #setInherit(on) {
68
+ if (on) {
69
+ this._form = inheritedForm(this._state)
70
+ this._changed = true
71
+ } else this.#change({})
72
+ }
73
+
74
+ #setMode(action, mode) {
75
+ this.#change({ [action]: mode, ...(action === 'read' ? { allMembers: false } : {}) })
76
+ }
77
+
78
+ #tick(name, action, on) {
79
+ this.#change({
80
+ groups: this._form.groups.map((g) => (g.name === name ? { ...g, [action]: on } : g)),
81
+ ...(action === 'read' ? { allMembers: false } : {}),
82
+ })
83
+ }
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
+
99
+ async #save() {
100
+ if (!this._changed) return this._submitModal()
101
+ this._busy = true
102
+ this._message = ''
103
+ try {
104
+ this.#show(await saveMediaAccess(this.data?.unique, requestFor(this._form, this._state.item)))
105
+ this._submitModal()
106
+ } catch (error) {
107
+ this._message = error.message
108
+ } finally {
109
+ this._busy = false
110
+ }
111
+ }
112
+
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>`
129
+ }
130
+
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}
140
+ ${
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>`
158
+ : nothing
159
+ }
160
+ </section>`
161
+ }
162
+
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>
179
+ ${
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>`
193
+ : nothing
194
+ }`
195
+ }
196
+
197
+ render() {
198
+ const headline = this._state ? `Permissions for ${this._state.name}` : 'Permissions'
199
+ return html`<umb-body-layout headline=${headline}>
200
+ ${
201
+ this._state && this._form
202
+ ? html`<p class="summary">${describeAccess(this._form, this._state)}</p>
203
+ <p class="fine">Editors who can open this in Media can always see it.</p>
204
+ ${
205
+ this._state.usedBy?.length
206
+ ? html`<p class="warning">${usedByText(this._state.usedBy)}</p>`
207
+ : nothing
208
+ }
209
+ ${this.#renderRule()}`
210
+ : this._message
211
+ ? nothing
212
+ : html`<uui-loader></uui-loader>`
213
+ }
214
+ ${this._message ? html`<p class="problem" role="alert">${this._message}</p>` : nothing}
215
+ <uui-button slot="actions" label="Cancel" @click=${() => this._rejectModal()}
216
+ >Cancel</uui-button
217
+ >
218
+ <uui-button
219
+ slot="actions"
220
+ look="primary"
221
+ color="positive"
222
+ label="Save"
223
+ ?disabled=${this._busy || !this._form}
224
+ @click=${() => this.#save()}
225
+ >Save</uui-button
226
+ >
227
+ </umb-body-layout>`
228
+ }
229
+
230
+ static styles = css`
231
+ uui-box {
232
+ margin-bottom: var(--uui-size-space-5, 18px);
233
+ }
234
+ table {
235
+ border-collapse: collapse;
236
+ margin: var(--uui-size-space-3, 9px) 0;
237
+ }
238
+ th,
239
+ td {
240
+ padding: var(--uui-size-space-2, 6px) var(--uui-size-space-4, 12px);
241
+ text-align: left;
242
+ }
243
+ .types {
244
+ display: grid;
245
+ grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
246
+ gap: var(--uui-size-space-2, 6px);
247
+ margin-bottom: var(--uui-size-space-4, 12px);
248
+ }
249
+ .size input {
250
+ margin-left: var(--uui-size-space-3, 9px);
251
+ width: 8rem;
252
+ }
253
+ .inherit,
254
+ .custom label,
255
+ .public {
256
+ display: block;
257
+ margin: var(--uui-size-space-2, 6px) 0;
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
+ }
271
+ .label {
272
+ font-weight: bold;
273
+ margin-bottom: 0;
274
+ }
275
+ .fine {
276
+ color: var(--uui-color-text-alt, #555);
277
+ }
278
+ .warning {
279
+ color: var(--uui-color-warning-standalone, #8a5a00);
280
+ }
281
+ .problem {
282
+ color: var(--uui-color-danger, #b00);
283
+ }
284
+ `
285
+ }
286
+
287
+ customElements.define('crombolo-media-access-modal', CromboloMediaAccessModalElement)
@@ -0,0 +1,335 @@
1
+ /**
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
+ * server keeps them at <backoffice>/crombolo/api/media-access/{key}, and
5
+ * refuses what the user may not do whatever this shows. docs/rendering.md, "Protected media".
6
+ */
7
+
8
+ export const MEDIA_ACCESS_MODAL = 'Crombolo.Modal.MediaAccess'
9
+
10
+ const base = () =>
11
+ `${(document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')}/crombolo/api/media-access`
12
+
13
+ /** The permissions of a folder or item, as the dialog shows them. */
14
+ export const readMediaAccess = async (key) => {
15
+ const response = await fetch(`${base()}/${encodeURIComponent(key)}`, {
16
+ credentials: 'include',
17
+ headers: { accept: 'application/json' },
18
+ })
19
+ if (!response.ok) throw new Error(problemFor(response.status))
20
+ return response.json()
21
+ }
22
+
23
+ /** Sets them; answers the new state, or throws what went wrong. */
24
+ export const saveMediaAccess = async (key, body) => {
25
+ const response = await fetch(`${base()}/${encodeURIComponent(key)}`, {
26
+ method: 'PUT',
27
+ credentials: 'include',
28
+ headers: { accept: 'application/json', 'content-type': 'application/json' },
29
+ body: JSON.stringify(body),
30
+ })
31
+ const answer = await response.json().catch(() => ({}))
32
+ if (!response.ok) throw new Error(answer.reason ?? problemFor(response.status))
33
+ return answer
34
+ }
35
+
36
+ export const problemFor = (status) =>
37
+ status === 403
38
+ ? 'You do not have permission to change who can see this.'
39
+ : status === 404
40
+ ? 'This media item could not be found.'
41
+ : 'The permissions could not be loaded. Try again.'
42
+
43
+ export const PUBLIC_NOTE =
44
+ 'Anyone who has the link can open these files, without signing in, and can pass the link on.'
45
+
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) : '')
48
+
49
+ /**
50
+ * The groups a rule shows: every member group on the site, ticked as the rule
51
+ * says, and any the rule names that no longer exists.
52
+ */
53
+ export function groupRows(rule, memberGroups) {
54
+ const named = new Map((rule?.groups ?? []).map((g) => [g.name.toLowerCase(), g]))
55
+ const rows = memberGroups.map((name) => {
56
+ const set = named.get(name.toLowerCase())
57
+ return { name, read: set?.read ?? false, write: set?.write ?? false }
58
+ })
59
+ for (const g of rule?.groups ?? [])
60
+ if (!memberGroups.some((name) => name.toLowerCase() === g.name.toLowerCase())) rows.push(g)
61
+ return rows
62
+ }
63
+
64
+ /** Megabytes as the dialog shows a size limit; empty for none. */
65
+ export const megabytesOf = (bytes) =>
66
+ bytes ? String(Math.round((bytes / (1024 * 1024)) * 100) / 100) : ''
67
+
68
+ /** A size limit typed in megabytes, as bytes; null when empty or not a size. */
69
+ export const bytesOf = (megabytes) => {
70
+ const value = Number(String(megabytes ?? '').trim())
71
+ return String(megabytes ?? '').trim() !== '' && Number.isFinite(value) && value > 0
72
+ ? Math.round(value * 1024 * 1024)
73
+ : null
74
+ }
75
+
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)
204
+ return {
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
+ },
218
+ }
219
+ }
220
+
221
+ /** Says which site features use a folder, in a sentence. */
222
+ export const usedByText = (bundles) =>
223
+ bundles?.length ? `Used by ${bundles.join(', ')} to store members' files.` : ''
224
+
225
+ const MEDIA_WRITE = /\/management\/api\/v1\/media\/([0-9a-f-]{36})(\/move|\/move-to-recycle-bin)?$/i
226
+
227
+ /**
228
+ * The warning to show before a request renames, moves or deletes a folder a
229
+ * site feature uses by its name and place (story 198); undefined for anything
230
+ * else. `used` is what `<backoffice>/crombolo/api/media-access/used` lists.
231
+ */
232
+ export function bundleWarningFor(method, url, body, used) {
233
+ const path = new URL(url, 'http://local').pathname
234
+ const match = MEDIA_WRITE.exec(path)
235
+ if (!match) return undefined
236
+ const folder = used.find((entry) => entry.key.toLowerCase() === match[1].toLowerCase())
237
+ if (!folder || folder.bundles.length === 0) return undefined
238
+ const verb = method.toUpperCase()
239
+ let doing
240
+ if (verb === 'DELETE' || match[2] === '/move-to-recycle-bin') doing = 'delete'
241
+ else if (match[2] === '/move') doing = 'move'
242
+ else if (verb === 'PUT') {
243
+ const names = (body?.variants ?? []).map((v) =>
244
+ String(v?.name ?? '')
245
+ .trim()
246
+ .toLowerCase(),
247
+ )
248
+ if (names.length === 0 || names.every((name) => name === folder.name.trim().toLowerCase()))
249
+ return undefined
250
+ doing = 'rename'
251
+ } else return undefined
252
+ const who = folder.bundles.join(' and ')
253
+ return {
254
+ headline: `${doing[0].toUpperCase()}${doing.slice(1)} ${folder.name}?`,
255
+ content: `${who} finds this folder by its name and place to store members' files. If you ${doing} it, members can no longer add files through ${who}, and the site will not start again until ${who} is set up for the new folder.`,
256
+ confirmLabel: `${doing[0].toUpperCase()}${doing.slice(1)} anyway`,
257
+ }
258
+ }
259
+
260
+ /** The folders site features use, for the warning above; none when they cannot be read. */
261
+ export const readUsedFolders = async () => {
262
+ const response = await fetch(`${base()}/used`, {
263
+ credentials: 'include',
264
+ headers: { accept: 'application/json' },
265
+ }).catch(() => undefined)
266
+ return response?.ok ? response.json() : []
267
+ }
268
+
269
+ /**
270
+ * Asks before a rename, move or delete of a folder a site feature uses. A
271
+ * request the user cancels is aborted, as a closed dialog is.
272
+ */
273
+ export async function confirmFolderChange(host, request, confirm) {
274
+ if (request.method === 'GET') return request
275
+ if (!MEDIA_WRITE.test(new URL(request.url, 'http://local').pathname)) return request
276
+ const body =
277
+ request.method === 'PUT'
278
+ ? await request
279
+ .clone()
280
+ .json()
281
+ .catch(() => undefined)
282
+ : undefined
283
+ const warning = bundleWarningFor(request.method, request.url, body, await readUsedFolders())
284
+ if (!warning) return request
285
+ try {
286
+ await confirm(host, { color: 'danger', ...warning })
287
+ return request
288
+ } catch {
289
+ return new Request(request, { signal: AbortSignal.abort() })
290
+ }
291
+ }
292
+
293
+ export const MEDIA_ACCESS_ACTION = {
294
+ type: 'entityAction',
295
+ kind: 'default',
296
+ alias: 'Crombolo.EntityAction.Media.Permissions',
297
+ name: 'Crombolo Media Permissions',
298
+ forEntityTypes: ['media'],
299
+ weight: 150,
300
+ api: () => import('./media-access-action.js'),
301
+ meta: { icon: 'icon-lock', label: 'Permissions' },
302
+ conditions: [
303
+ { alias: 'Umb.Condition.EntityIsNotTrashed' },
304
+ { alias: 'Umb.Condition.UserPermission.Fallback', allOf: ['Crombolo.Media.Update'] },
305
+ ],
306
+ }
307
+
308
+ export const MEDIA_ACCESS_DIALOG = {
309
+ type: 'modal',
310
+ alias: MEDIA_ACCESS_MODAL,
311
+ name: 'Crombolo Media Permissions Dialog',
312
+ element: () => import('./media-access-modal.js'),
313
+ }
314
+
315
+ export const MEDIA_ACCESS_INFO = {
316
+ type: 'workspaceInfoApp',
317
+ alias: 'Crombolo.WorkspaceInfoApp.Media.Access',
318
+ name: 'Crombolo Media Access Info',
319
+ element: () => import('./media-access-info.js'),
320
+ weight: 90,
321
+ conditions: [{ alias: 'Umb.Condition.WorkspaceAlias', match: 'Umb.Workspace.Media' }],
322
+ }
323
+
324
+ export const onInit = async (host, extensionRegistry) => {
325
+ extensionRegistry.register(MEDIA_ACCESS_ACTION)
326
+ extensionRegistry.register(MEDIA_ACCESS_DIALOG)
327
+ extensionRegistry.register(MEDIA_ACCESS_INFO)
328
+ const [{ umbHttpClient }, { umbConfirmModal }] = await Promise.all([
329
+ import('@umbraco-cms/backoffice/http-client'),
330
+ import('@umbraco-cms/backoffice/modal'),
331
+ ])
332
+ umbHttpClient.interceptors.request.use((request) =>
333
+ confirmFolderChange(host, request, umbConfirmModal),
334
+ )
335
+ }
@@ -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.34.0",
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.34.0",
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.34.0",
5
+ "version": "0.36.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -99,6 +99,12 @@
99
99
  "name": "Crombolo Media Permissions",
100
100
  "js": "/crombolo-plugin/media-permissions.js"
101
101
  },
102
+ {
103
+ "type": "backofficeEntryPoint",
104
+ "alias": "Crombolo.EntryPoint.MediaAccess",
105
+ "name": "Crombolo Media Access",
106
+ "js": "/crombolo-plugin/media-access.js"
107
+ },
102
108
  {
103
109
  "type": "backofficeEntryPoint",
104
110
  "alias": "Crombolo.EntryPoint.EditConflicts",