@crombolo/backoffice-host 0.33.1 → 0.35.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/README.md +14 -0
- package/package.json +3 -3
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/bundles-carries.js +7 -2
- package/plugin/bundles-client.js +9 -2
- package/plugin/bundles-created-overview.js +42 -1
- package/plugin/bundles-marketplace.js +89 -5
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/media-access-action.js +15 -0
- package/plugin/media-access-info.js +61 -0
- package/plugin/media-access-modal.js +339 -0
- package/plugin/media-access.js +242 -0
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/umbraco-package.json +7 -1
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @crombolo/backoffice-host
|
|
2
|
+
|
|
3
|
+
**Internal to crombolo.** This package is published because
|
|
4
|
+
[`@crombolo/crombolo`](https://www.npmjs.com/package/@crombolo/crombolo)
|
|
5
|
+
depends on it, and its exports can change in any release, a patch included.
|
|
6
|
+
|
|
7
|
+
Import from `@crombolo/crombolo` instead:
|
|
8
|
+
|
|
9
|
+
- `@crombolo/crombolo` for a site: its config, its boot and its views.
|
|
10
|
+
- `@crombolo/crombolo/bundle` for a server bundle's author.
|
|
11
|
+
- `@crombolo/crombolo/host` for whoever runs sites.
|
|
12
|
+
|
|
13
|
+
Those three entry points carry the compatibility promise in
|
|
14
|
+
[`docs/api.md`](https://github.com/kineco-au/crombolo-cms/blob/main/docs/api.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/backoffice-host",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
|
|
3
|
+
"version": "0.35.2",
|
|
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",
|
|
7
7
|
"homepage": "https://github.com/kineco-au/crombolo-cms#readme",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@crombolo/core": "0.
|
|
34
|
+
"@crombolo/core": "0.35.2",
|
|
35
35
|
"@crombolo/backoffice-dist": "18.2.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -7,10 +7,15 @@ import { html } from '@umbraco-cms/backoffice/external/lit'
|
|
|
7
7
|
export const CARRIES_LABELS = {
|
|
8
8
|
extensions: 'Screens',
|
|
9
9
|
content: 'Content',
|
|
10
|
-
server: '
|
|
10
|
+
server: 'Runs code on the server',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** Server code is a different kind of thing to add, so it looks like one (story 194). */
|
|
13
14
|
export const carriesTags = (carries) =>
|
|
14
15
|
Object.entries(CARRIES_LABELS)
|
|
15
16
|
.filter(([key]) => carries?.[key])
|
|
16
|
-
.map(([, label]) =>
|
|
17
|
+
.map(([key, label]) =>
|
|
18
|
+
key === 'server'
|
|
19
|
+
? html`<uui-tag look="primary" color="warning">${label}</uui-tag>`
|
|
20
|
+
: html`<uui-tag look="secondary">${label}</uui-tag>`,
|
|
21
|
+
)
|
package/plugin/bundles-client.js
CHANGED
|
@@ -27,12 +27,19 @@ export const searchMarketplace = (query) =>
|
|
|
27
27
|
|
|
28
28
|
export const listInstalled = () => json('/installed')
|
|
29
29
|
|
|
30
|
-
export const installBundle = (name, version, applyContent = true) =>
|
|
31
|
-
json('/install', {
|
|
30
|
+
export const installBundle = (name, version, applyContent = true, acceptServerCode = false) =>
|
|
31
|
+
json('/install', {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
body: JSON.stringify({ name, version, applyContent, acceptServerCode }),
|
|
34
|
+
})
|
|
32
35
|
|
|
33
36
|
export const uninstallBundle = (name) =>
|
|
34
37
|
json('/uninstall', { method: 'POST', body: JSON.stringify({ name }) })
|
|
35
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
|
+
|
|
36
43
|
/** The npm package a created bundle downloads as. */
|
|
37
44
|
export const readCreatedPackage = (id) => json(`/created/${encodeURIComponent(id)}/package`)
|
|
38
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
|
}
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* What it shows instead is the npm registry, searched for the keyword a crombolo
|
|
10
10
|
* bundle publishes, and filtered to the ones whose manifest is a valid bundle.
|
|
11
11
|
* Installing runs `bun add` on the server, then adds the content the bundle
|
|
12
|
-
* carries unless the site or the person installing declines it.
|
|
12
|
+
* carries unless the site or the person installing declines it. A bundle that
|
|
13
|
+
* runs code on the server installs only after an explicit yes in its card,
|
|
14
|
+
* which the server insists on too (story 194).
|
|
13
15
|
*/
|
|
14
16
|
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
15
17
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
@@ -29,6 +31,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
29
31
|
_declined: { state: true },
|
|
30
32
|
_installs: { state: true },
|
|
31
33
|
_elsewhere: { state: true },
|
|
34
|
+
_consenting: { state: true },
|
|
35
|
+
_trusted: { state: true },
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
constructor() {
|
|
@@ -45,6 +49,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
45
49
|
this._declined = new Set()
|
|
46
50
|
this._installs = true
|
|
47
51
|
this._elsewhere = null
|
|
52
|
+
this._consenting = ''
|
|
53
|
+
this._trusted = false
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
connectedCallback() {
|
|
@@ -81,11 +87,40 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
81
87
|
this.#load()
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
/** Asks first when the bundle runs code on the server; installs otherwise. */
|
|
91
|
+
#requestInstall(item) {
|
|
92
|
+
if (item.carries?.server) this.#askConsent(item)
|
|
93
|
+
else this.#install(item, false)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#askConsent(item) {
|
|
97
|
+
this._consenting = item.name
|
|
98
|
+
this._trusted = false
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#cancelConsent() {
|
|
102
|
+
this._consenting = ''
|
|
103
|
+
this._trusted = false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async #install(item, acceptServerCode) {
|
|
85
107
|
this._busy = item.name
|
|
86
108
|
this._notice = ''
|
|
87
109
|
try {
|
|
88
|
-
const outcome = await installBundle(
|
|
110
|
+
const outcome = await installBundle(
|
|
111
|
+
item.name,
|
|
112
|
+
item.version,
|
|
113
|
+
!this._declined.has(item.name),
|
|
114
|
+
acceptServerCode,
|
|
115
|
+
)
|
|
116
|
+
// The version that would install may have gained server code since the
|
|
117
|
+
// list was read: the server says so, and the card asks.
|
|
118
|
+
if (outcome.needsServerConsent && !acceptServerCode) {
|
|
119
|
+
this._notice = outcome.message ?? ''
|
|
120
|
+
this.#askConsent({ ...item, carries: { ...item.carries, server: true } })
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
this._consenting = ''
|
|
89
124
|
// The dependency line is what there is to commit, so it is shown rather
|
|
90
125
|
// than described: the install lives in this node's node_modules until it
|
|
91
126
|
// is in the site's repository.
|
|
@@ -120,6 +155,43 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
120
155
|
`
|
|
121
156
|
}
|
|
122
157
|
|
|
158
|
+
/** The explicit yes a bundle that runs code on the server needs, in its own card. */
|
|
159
|
+
#consent(item) {
|
|
160
|
+
return html`
|
|
161
|
+
<div class="consent" role="group" aria-label="Install code that runs on the server">
|
|
162
|
+
<p>
|
|
163
|
+
<strong>This bundle runs code on the server.</strong> Once your site's developers turn
|
|
164
|
+
it on, its code can read and change the site's data, files and settings.
|
|
165
|
+
</p>
|
|
166
|
+
<p class="meta">
|
|
167
|
+
<span>Published by ${item.publisher ?? 'an unnamed publisher'}</span>
|
|
168
|
+
<a href=${item.links.npm} target="_blank" rel="noopener">npm</a>
|
|
169
|
+
${
|
|
170
|
+
item.links.repository
|
|
171
|
+
? html`<a href=${item.links.repository} target="_blank" rel="noopener">source</a>`
|
|
172
|
+
: nothing
|
|
173
|
+
}
|
|
174
|
+
</p>
|
|
175
|
+
<uui-checkbox
|
|
176
|
+
label="I trust this publisher with the site's server"
|
|
177
|
+
.checked=${this._trusted}
|
|
178
|
+
@change=${(event) => {
|
|
179
|
+
this._trusted = event.target.checked
|
|
180
|
+
}}></uui-checkbox>
|
|
181
|
+
<div class="actions">
|
|
182
|
+
<uui-button
|
|
183
|
+
look="primary"
|
|
184
|
+
color="warning"
|
|
185
|
+
label="Install server code"
|
|
186
|
+
?disabled=${!this._trusted}
|
|
187
|
+
.state=${this._busy === item.name ? 'waiting' : undefined}
|
|
188
|
+
@click=${() => this.#install(item, true)}></uui-button>
|
|
189
|
+
<uui-button look="secondary" label="Cancel" @click=${this.#cancelConsent}></uui-button>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
`
|
|
193
|
+
}
|
|
194
|
+
|
|
123
195
|
#empty() {
|
|
124
196
|
return html`
|
|
125
197
|
<uui-box headline="No bundles published yet">
|
|
@@ -184,12 +256,14 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
184
256
|
? this._elsewhere
|
|
185
257
|
? html`<p class="meta">${this.#elsewhereLink() || this._elsewhere.message}</p>`
|
|
186
258
|
: html`<p class="meta">Add it to the site with <code>bun add ${item.name}</code>, then deploy.</p>`
|
|
187
|
-
:
|
|
259
|
+
: this._consenting === item.name
|
|
260
|
+
? this.#consent(item)
|
|
261
|
+
: html`
|
|
188
262
|
<uui-button
|
|
189
263
|
look="primary"
|
|
190
264
|
label="Install"
|
|
191
265
|
.state=${this._busy === item.name ? 'waiting' : undefined}
|
|
192
|
-
@click=${() => this.#
|
|
266
|
+
@click=${() => this.#requestInstall(item)}></uui-button>
|
|
193
267
|
`
|
|
194
268
|
}
|
|
195
269
|
</uui-box>
|
|
@@ -253,6 +327,16 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
253
327
|
display: block;
|
|
254
328
|
margin-bottom: var(--uui-size-space-4, 12px);
|
|
255
329
|
}
|
|
330
|
+
.consent {
|
|
331
|
+
padding: var(--uui-size-space-4, 12px);
|
|
332
|
+
border-left: 3px solid var(--uui-color-warning, #f0ac00);
|
|
333
|
+
background: var(--uui-color-surface-alt, #f3f3f5);
|
|
334
|
+
}
|
|
335
|
+
.consent .actions {
|
|
336
|
+
display: flex;
|
|
337
|
+
gap: var(--uui-size-space-3, 9px);
|
|
338
|
+
margin-top: var(--uui-size-space-4, 12px);
|
|
339
|
+
}
|
|
256
340
|
`
|
|
257
341
|
}
|
|
258
342
|
|
|
@@ -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="Who can see it">
|
|
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,339 @@
|
|
|
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`.
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
7
|
+
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
|
|
8
|
+
import {
|
|
9
|
+
bytesOf,
|
|
10
|
+
FILE_READ_CHOICES,
|
|
11
|
+
FILE_WRITE_CHOICES,
|
|
12
|
+
groupRows,
|
|
13
|
+
megabytesOf,
|
|
14
|
+
NEW_READ_CHOICES,
|
|
15
|
+
NEW_WRITE_CHOICES,
|
|
16
|
+
PUBLIC_WARNING,
|
|
17
|
+
readMediaAccess,
|
|
18
|
+
requestFor,
|
|
19
|
+
saveMediaAccess,
|
|
20
|
+
summarise,
|
|
21
|
+
usedByText,
|
|
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
|
+
_busy: { state: true },
|
|
29
|
+
_message: { state: true },
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
super()
|
|
34
|
+
this._state = undefined
|
|
35
|
+
this._form = undefined
|
|
36
|
+
this._busy = false
|
|
37
|
+
this._message = ''
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
super.connectedCallback()
|
|
42
|
+
this.#load()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async #load() {
|
|
46
|
+
try {
|
|
47
|
+
this.#show(await readMediaAccess(this.data?.unique))
|
|
48
|
+
} catch (error) {
|
|
49
|
+
this._message = error.message
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#show(state) {
|
|
54
|
+
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
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
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#tickType(id, on) {
|
|
80
|
+
const types = this._form.own.memberTypes ?? []
|
|
81
|
+
this.#change({ memberTypes: on ? [...types, id] : types.filter((t) => t !== id) })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#change(patch) {
|
|
85
|
+
this._form = { ...this._form, own: { ...this._form.own, ...patch } }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#tick(name, which, on) {
|
|
89
|
+
this.#change({
|
|
90
|
+
groups: this._form.own.groups.map((g) => (g.name === name ? { ...g, [which]: on } : g)),
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async #save() {
|
|
95
|
+
this._busy = true
|
|
96
|
+
this._message = ''
|
|
97
|
+
try {
|
|
98
|
+
this.#show(await saveMediaAccess(this.data?.unique, requestFor(this._form)))
|
|
99
|
+
this._submitModal()
|
|
100
|
+
} catch (error) {
|
|
101
|
+
this._message = error.message
|
|
102
|
+
} finally {
|
|
103
|
+
this._busy = false
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
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>`
|
|
122
|
+
}
|
|
123
|
+
|
|
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
|
+
}
|
|
183
|
+
${
|
|
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
|
+
>`
|
|
193
|
+
: nothing
|
|
194
|
+
}
|
|
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
|
+
}`
|
|
238
|
+
}
|
|
239
|
+
|
|
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">
|
|
248
|
+
${
|
|
249
|
+
creator
|
|
250
|
+
? html`<p>Added by ${creator.name ?? 'a member who is no longer here'}.</p>`
|
|
251
|
+
: 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>`
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
render() {
|
|
263
|
+
const headline = this._state ? `Permissions for ${this._state.name}` : 'Permissions'
|
|
264
|
+
return html`<umb-body-layout headline=${headline}>
|
|
265
|
+
${
|
|
266
|
+
this._state && this._form
|
|
267
|
+
? html`<p class="summary">${summarise(this._state)}</p>
|
|
268
|
+
<p class="fine">Editors who can open this in Media can always see it.</p>
|
|
269
|
+
${
|
|
270
|
+
this._state.usedBy?.length
|
|
271
|
+
? html`<p class="warning">${usedByText(this._state.usedBy)}</p>`
|
|
272
|
+
: nothing
|
|
273
|
+
}
|
|
274
|
+
${this.#renderRule()} ${this.#renderFile()}`
|
|
275
|
+
: this._message
|
|
276
|
+
? nothing
|
|
277
|
+
: html`<uui-loader></uui-loader>`
|
|
278
|
+
}
|
|
279
|
+
${this._message ? html`<p class="problem" role="alert">${this._message}</p>` : nothing}
|
|
280
|
+
<uui-button slot="actions" label="Cancel" @click=${() => this._rejectModal()}
|
|
281
|
+
>Cancel</uui-button
|
|
282
|
+
>
|
|
283
|
+
<uui-button
|
|
284
|
+
slot="actions"
|
|
285
|
+
look="primary"
|
|
286
|
+
color="positive"
|
|
287
|
+
label="Save"
|
|
288
|
+
?disabled=${this._busy || !this._form}
|
|
289
|
+
@click=${() => this.#save()}
|
|
290
|
+
>Save</uui-button
|
|
291
|
+
>
|
|
292
|
+
</umb-body-layout>`
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static styles = css`
|
|
296
|
+
uui-box {
|
|
297
|
+
margin-bottom: var(--uui-size-space-5, 18px);
|
|
298
|
+
}
|
|
299
|
+
table {
|
|
300
|
+
border-collapse: collapse;
|
|
301
|
+
margin: var(--uui-size-space-3, 9px) 0;
|
|
302
|
+
}
|
|
303
|
+
th,
|
|
304
|
+
td {
|
|
305
|
+
padding: var(--uui-size-space-2, 6px) var(--uui-size-space-4, 12px);
|
|
306
|
+
text-align: left;
|
|
307
|
+
}
|
|
308
|
+
.types {
|
|
309
|
+
display: grid;
|
|
310
|
+
grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
|
|
311
|
+
gap: var(--uui-size-space-2, 6px);
|
|
312
|
+
margin-bottom: var(--uui-size-space-4, 12px);
|
|
313
|
+
}
|
|
314
|
+
.size input {
|
|
315
|
+
margin-left: var(--uui-size-space-3, 9px);
|
|
316
|
+
width: 8rem;
|
|
317
|
+
}
|
|
318
|
+
.choices label,
|
|
319
|
+
.public {
|
|
320
|
+
display: block;
|
|
321
|
+
margin: var(--uui-size-space-2, 6px) 0;
|
|
322
|
+
}
|
|
323
|
+
.label {
|
|
324
|
+
font-weight: bold;
|
|
325
|
+
margin-bottom: 0;
|
|
326
|
+
}
|
|
327
|
+
.fine {
|
|
328
|
+
color: var(--uui-color-text-alt, #555);
|
|
329
|
+
}
|
|
330
|
+
.warning {
|
|
331
|
+
color: var(--uui-color-warning-standalone, #8a5a00);
|
|
332
|
+
}
|
|
333
|
+
.problem {
|
|
334
|
+
color: var(--uui-color-danger, #b00);
|
|
335
|
+
}
|
|
336
|
+
`
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
customElements.define('crombolo-media-access-modal', CromboloMediaAccessModalElement)
|
|
@@ -0,0 +1,242 @@
|
|
|
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
|
|
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.
|
|
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 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 =
|
|
73
|
+
'Anyone who has the link can open these files, without signing in, and can pass the link on.'
|
|
74
|
+
|
|
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
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The groups a rule shows: every member group on the site, ticked as the rule
|
|
84
|
+
* says, and any the rule names that no longer exists.
|
|
85
|
+
*/
|
|
86
|
+
export function groupRows(rule, memberGroups) {
|
|
87
|
+
const named = new Map((rule?.groups ?? []).map((g) => [g.name.toLowerCase(), g]))
|
|
88
|
+
const rows = memberGroups.map((name) => {
|
|
89
|
+
const set = named.get(name.toLowerCase())
|
|
90
|
+
return { name, read: set?.read ?? false, write: set?.write ?? false }
|
|
91
|
+
})
|
|
92
|
+
for (const g of rule?.groups ?? [])
|
|
93
|
+
if (!memberGroups.some((name) => name.toLowerCase() === g.name.toLowerCase())) rows.push(g)
|
|
94
|
+
return rows
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Megabytes as the dialog shows a size limit; empty for none. */
|
|
98
|
+
export const megabytesOf = (bytes) =>
|
|
99
|
+
bytes ? String(Math.round((bytes / (1024 * 1024)) * 100) / 100) : ''
|
|
100
|
+
|
|
101
|
+
/** A size limit typed in megabytes, as bytes; null when empty or not a size. */
|
|
102
|
+
export const bytesOf = (megabytes) => {
|
|
103
|
+
const value = Number(String(megabytes ?? '').trim())
|
|
104
|
+
return String(megabytes ?? '').trim() !== '' && Number.isFinite(value) && value > 0
|
|
105
|
+
? Math.round(value * 1024 * 1024)
|
|
106
|
+
: null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What the dialog sends: the rule (null to follow the folder above) and a file's own setting. */
|
|
110
|
+
export function requestFor(form) {
|
|
111
|
+
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
|
+
: {}),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Says which site features use a folder, in a sentence. */
|
|
129
|
+
export const usedByText = (bundles) =>
|
|
130
|
+
bundles?.length ? `Used by ${bundles.join(', ')} to store members' files.` : ''
|
|
131
|
+
|
|
132
|
+
const MEDIA_WRITE = /\/management\/api\/v1\/media\/([0-9a-f-]{36})(\/move|\/move-to-recycle-bin)?$/i
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The warning to show before a request renames, moves or deletes a folder a
|
|
136
|
+
* site feature uses by its name and place (story 198); undefined for anything
|
|
137
|
+
* else. `used` is what `<backoffice>/crombolo/api/media-access/used` lists.
|
|
138
|
+
*/
|
|
139
|
+
export function bundleWarningFor(method, url, body, used) {
|
|
140
|
+
const path = new URL(url, 'http://local').pathname
|
|
141
|
+
const match = MEDIA_WRITE.exec(path)
|
|
142
|
+
if (!match) return undefined
|
|
143
|
+
const folder = used.find((entry) => entry.key.toLowerCase() === match[1].toLowerCase())
|
|
144
|
+
if (!folder || folder.bundles.length === 0) return undefined
|
|
145
|
+
const verb = method.toUpperCase()
|
|
146
|
+
let doing
|
|
147
|
+
if (verb === 'DELETE' || match[2] === '/move-to-recycle-bin') doing = 'delete'
|
|
148
|
+
else if (match[2] === '/move') doing = 'move'
|
|
149
|
+
else if (verb === 'PUT') {
|
|
150
|
+
const names = (body?.variants ?? []).map((v) =>
|
|
151
|
+
String(v?.name ?? '')
|
|
152
|
+
.trim()
|
|
153
|
+
.toLowerCase(),
|
|
154
|
+
)
|
|
155
|
+
if (names.length === 0 || names.every((name) => name === folder.name.trim().toLowerCase()))
|
|
156
|
+
return undefined
|
|
157
|
+
doing = 'rename'
|
|
158
|
+
} else return undefined
|
|
159
|
+
const who = folder.bundles.join(' and ')
|
|
160
|
+
return {
|
|
161
|
+
headline: `${doing[0].toUpperCase()}${doing.slice(1)} ${folder.name}?`,
|
|
162
|
+
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.`,
|
|
163
|
+
confirmLabel: `${doing[0].toUpperCase()}${doing.slice(1)} anyway`,
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The folders site features use, for the warning above; none when they cannot be read. */
|
|
168
|
+
export const readUsedFolders = async () => {
|
|
169
|
+
const response = await fetch(`${base()}/used`, {
|
|
170
|
+
credentials: 'include',
|
|
171
|
+
headers: { accept: 'application/json' },
|
|
172
|
+
}).catch(() => undefined)
|
|
173
|
+
return response?.ok ? response.json() : []
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Asks before a rename, move or delete of a folder a site feature uses. A
|
|
178
|
+
* request the user cancels is aborted, as a closed dialog is.
|
|
179
|
+
*/
|
|
180
|
+
export async function confirmFolderChange(host, request, confirm) {
|
|
181
|
+
if (request.method === 'GET') return request
|
|
182
|
+
if (!MEDIA_WRITE.test(new URL(request.url, 'http://local').pathname)) return request
|
|
183
|
+
const body =
|
|
184
|
+
request.method === 'PUT'
|
|
185
|
+
? await request
|
|
186
|
+
.clone()
|
|
187
|
+
.json()
|
|
188
|
+
.catch(() => undefined)
|
|
189
|
+
: undefined
|
|
190
|
+
const warning = bundleWarningFor(request.method, request.url, body, await readUsedFolders())
|
|
191
|
+
if (!warning) return request
|
|
192
|
+
try {
|
|
193
|
+
await confirm(host, { color: 'danger', ...warning })
|
|
194
|
+
return request
|
|
195
|
+
} catch {
|
|
196
|
+
return new Request(request, { signal: AbortSignal.abort() })
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const MEDIA_ACCESS_ACTION = {
|
|
201
|
+
type: 'entityAction',
|
|
202
|
+
kind: 'default',
|
|
203
|
+
alias: 'Crombolo.EntityAction.Media.Permissions',
|
|
204
|
+
name: 'Crombolo Media Permissions',
|
|
205
|
+
forEntityTypes: ['media'],
|
|
206
|
+
weight: 150,
|
|
207
|
+
api: () => import('./media-access-action.js'),
|
|
208
|
+
meta: { icon: 'icon-lock', label: 'Permissions' },
|
|
209
|
+
conditions: [
|
|
210
|
+
{ alias: 'Umb.Condition.EntityIsNotTrashed' },
|
|
211
|
+
{ alias: 'Umb.Condition.UserPermission.Fallback', allOf: ['Crombolo.Media.Update'] },
|
|
212
|
+
],
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const MEDIA_ACCESS_DIALOG = {
|
|
216
|
+
type: 'modal',
|
|
217
|
+
alias: MEDIA_ACCESS_MODAL,
|
|
218
|
+
name: 'Crombolo Media Permissions Dialog',
|
|
219
|
+
element: () => import('./media-access-modal.js'),
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export const MEDIA_ACCESS_INFO = {
|
|
223
|
+
type: 'workspaceInfoApp',
|
|
224
|
+
alias: 'Crombolo.WorkspaceInfoApp.Media.Access',
|
|
225
|
+
name: 'Crombolo Media Access Info',
|
|
226
|
+
element: () => import('./media-access-info.js'),
|
|
227
|
+
weight: 90,
|
|
228
|
+
conditions: [{ alias: 'Umb.Condition.WorkspaceAlias', match: 'Umb.Workspace.Media' }],
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export const onInit = async (host, extensionRegistry) => {
|
|
232
|
+
extensionRegistry.register(MEDIA_ACCESS_ACTION)
|
|
233
|
+
extensionRegistry.register(MEDIA_ACCESS_DIALOG)
|
|
234
|
+
extensionRegistry.register(MEDIA_ACCESS_INFO)
|
|
235
|
+
const [{ umbHttpClient }, { umbConfirmModal }] = await Promise.all([
|
|
236
|
+
import('@umbraco-cms/backoffice/http-client'),
|
|
237
|
+
import('@umbraco-cms/backoffice/modal'),
|
|
238
|
+
])
|
|
239
|
+
umbHttpClient.interceptors.request.use((request) =>
|
|
240
|
+
confirmFolderChange(host, request, umbConfirmModal),
|
|
241
|
+
)
|
|
242
|
+
}
|
|
@@ -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.
|
|
5
|
+
"version": "0.35.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",
|