@crombolo/backoffice-host 0.65.1 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/backoffice-host",
3
- "version": "0.65.1",
3
+ "version": "0.66.0",
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",
@@ -19,7 +19,9 @@
19
19
  "type": "module",
20
20
  "exports": {
21
21
  ".": "./src/index.ts",
22
+ "./activity-words": "./plugin/bundles-activity-words.js",
22
23
  "./branding": "./src/branding.ts",
24
+ "./media-access-rules": "./plugin/media-access-rules.js",
23
25
  "./registry": "./src/registry.ts"
24
26
  },
25
27
  "files": [
@@ -32,7 +34,7 @@
32
34
  "access": "public"
33
35
  },
34
36
  "dependencies": {
35
- "@crombolo/core": "0.65.1",
36
- "@crombolo/backoffice-dist": "0.65.1"
37
+ "@crombolo/core": "0.66.0",
38
+ "@crombolo/backoffice-dist": "0.66.0"
37
39
  }
38
40
  }
@@ -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.65.1",
5
+ "version": "0.66.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Another person's command-line tokens (story 351), as a view on their user
3
+ * screen: an administrator sees them and revokes any. Shown only while the
4
+ * site takes tokens; the endpoint refuses anyone but an administrator.
5
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import { UMB_USER_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/user'
9
+ import { TOKENS_API } from './cli-tokens.js'
10
+ import { HEADLINE, NONE, OTHERS_INTRO, revokeQuestion, tokenLine } from './cli-tokens-words.js'
11
+
12
+ export default class CromboloCliTokensUserElement extends UmbLitElement {
13
+ static properties = { _state: { state: true }, _error: { state: true } }
14
+
15
+ #user = undefined
16
+
17
+ constructor() {
18
+ super()
19
+ this._state = undefined
20
+ this._error = ''
21
+ this.consumeContext(UMB_USER_WORKSPACE_CONTEXT, (context) => {
22
+ if (!context) return
23
+ this.observe(context.unique, (unique) => {
24
+ this.#user = unique ?? undefined
25
+ if (this.#user) this.#load()
26
+ })
27
+ })
28
+ }
29
+
30
+ async #load() {
31
+ try {
32
+ const response = await fetch(`${TOKENS_API}?user=${encodeURIComponent(this.#user)}`, {
33
+ credentials: 'include',
34
+ })
35
+ const body = await response.json().catch(() => ({}))
36
+ this._state = response.ok ? body : { enabled: true, items: [] }
37
+ this._error = response.ok ? '' : (body.message ?? 'Could not load the tokens.')
38
+ } catch {
39
+ this._error = 'Could not load the tokens.'
40
+ }
41
+ }
42
+
43
+ async #revoke(token) {
44
+ if (!confirm(revokeQuestion(token.name))) return
45
+ const response = await fetch(`${TOKENS_API}/${token.key}`, {
46
+ method: 'DELETE',
47
+ credentials: 'include',
48
+ })
49
+ if (!response.ok) this._error = 'That token could not be revoked.'
50
+ await this.#load()
51
+ }
52
+
53
+ render() {
54
+ if (!this._state) return nothing
55
+ if (!this._state.enabled)
56
+ return html`<uui-box headline=${HEADLINE}><p>This site does not take command-line tokens.</p></uui-box>`
57
+ const items = this._state.items ?? []
58
+ return html`<uui-box headline=${HEADLINE}>
59
+ <p class="muted">${OTHERS_INTRO}</p>
60
+ ${this._error ? html`<p class="error">${this._error}</p>` : nothing}
61
+ ${
62
+ items.length === 0
63
+ ? html`<p>${NONE}</p>`
64
+ : html`<ul>
65
+ ${items.map(
66
+ (token) => html`<li>
67
+ <div>
68
+ <strong>${token.name}</strong>
69
+ <small>${tokenLine(token)}</small>
70
+ </div>
71
+ <uui-button look="secondary" color="danger" label="Revoke" @click=${() => this.#revoke(token)}></uui-button>
72
+ </li>`,
73
+ )}
74
+ </ul>`
75
+ }
76
+ </uui-box>`
77
+ }
78
+
79
+ static styles = css`
80
+ :host {
81
+ display: block;
82
+ padding: var(--uui-size-layout-1);
83
+ }
84
+ ul {
85
+ list-style: none;
86
+ margin: 0;
87
+ padding: 0;
88
+ }
89
+ li {
90
+ display: flex;
91
+ justify-content: space-between;
92
+ align-items: center;
93
+ gap: var(--uui-size-space-4);
94
+ padding: var(--uui-size-space-3) 0;
95
+ border-bottom: 1px solid var(--uui-color-divider);
96
+ }
97
+ li div {
98
+ display: flex;
99
+ flex-direction: column;
100
+ }
101
+ small,
102
+ .muted {
103
+ color: var(--uui-color-text-alt);
104
+ }
105
+ .error {
106
+ color: var(--uui-color-danger);
107
+ }
108
+ `
109
+ }
110
+
111
+ customElements.define('crombolo-cli-tokens-user', CromboloCliTokensUserElement)
@@ -0,0 +1,74 @@
1
+ /** What the back office says about command-line tokens (story 351). Pure. */
2
+
3
+ export const HEADLINE = 'Command-line tokens'
4
+
5
+ /** What the profile box says the tokens are for. */
6
+ export const INTRO =
7
+ 'A token lets a script or an automated job run commands as you, with your permissions. ' +
8
+ 'Treat it like a password.'
9
+
10
+ /** What the user's screen says, for an administrator looking at someone else's. */
11
+ export const OTHERS_INTRO =
12
+ 'Tokens this person made so scripts can run commands as them. Revoking one stops it working straight away.'
13
+
14
+ export const NONE = 'No tokens.'
15
+
16
+ /** Shown above a new token, the one time it can be seen. */
17
+ export const SHOWN_ONCE = "Copy this token now. You won't be able to see it again."
18
+
19
+ /** The group editor's words for the permission. */
20
+ export const PERMISSION_LABEL = 'Command-line tokens'
21
+ export const PERMISSION_DESCRIPTION = 'Create tokens that let scripts run commands as you'
22
+
23
+ /**
24
+ * A date as the browser writes dates: "14 Dec 2026".
25
+ * @param {string} iso
26
+ * @param {string} [locale]
27
+ * @returns {string}
28
+ */
29
+ export function day(iso, locale) {
30
+ return new Date(iso).toLocaleDateString(locale, {
31
+ day: 'numeric',
32
+ month: 'short',
33
+ year: 'numeric',
34
+ })
35
+ }
36
+
37
+ /**
38
+ * The line under a token's name: when it stops working and when it was last used.
39
+ * @param {{ expiresAt: string, lastUsedAt: string | null }} token
40
+ * @param {string} [locale]
41
+ * @returns {string}
42
+ */
43
+ export function tokenLine(token, locale) {
44
+ const used = token.lastUsedAt ? `last used ${day(token.lastUsedAt, locale)}` : 'not used yet'
45
+ return `Works until ${day(token.expiresAt, locale)}, ${used}`
46
+ }
47
+
48
+ /**
49
+ * How long a new token may last, as choices: the usual lengths up to the site's limit, and the limit.
50
+ * @param {number} maxDays
51
+ * @returns {Array<{ days: number, label: string }>}
52
+ */
53
+ export function expiryChoices(maxDays) {
54
+ const days = [...new Set([7, 30, 60, 90].filter((d) => d < maxDays).concat(maxDays))]
55
+ return days.map((d) => ({ days: d, label: d === 1 ? '1 day' : `${d} days` }))
56
+ }
57
+
58
+ /**
59
+ * Whether Create may be pressed, and what it says.
60
+ * @param {string} name
61
+ * @returns {{ enabled: boolean, label: string }}
62
+ */
63
+ export function createButton(name) {
64
+ return name.trim() === ''
65
+ ? { enabled: false, label: 'Give it a name' }
66
+ : { enabled: true, label: 'Create token' }
67
+ }
68
+
69
+ /**
70
+ * The question before revoking.
71
+ * @param {string} name
72
+ * @returns {string}
73
+ */
74
+ export const revokeQuestion = (name) => `Revoke "${name}"? Anything using it will stop working.`
@@ -0,0 +1,196 @@
1
+ /**
2
+ * A person's command-line tokens (story 351), in their profile: listed, made
3
+ * from a name and how long it lasts and shown once with a copy button, and
4
+ * revoked. Making one is offered only to someone whose groups give it.
5
+ */
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import {
9
+ createButton,
10
+ expiryChoices,
11
+ HEADLINE,
12
+ INTRO,
13
+ NONE,
14
+ revokeQuestion,
15
+ SHOWN_ONCE,
16
+ tokenLine,
17
+ } from './cli-tokens-words.js'
18
+
19
+ /** The plugin's API, under the back office wherever it is mounted. */
20
+ export const TOKENS_API = `${(document.querySelector('base')?.getAttribute('href') ?? '/crombolo/').replace(/\/$/, '')}/crombolo/api/cli-tokens`
21
+
22
+ export default class CromboloCliTokensElement extends UmbLitElement {
23
+ static properties = {
24
+ _state: { state: true },
25
+ _error: { state: true },
26
+ _name: { state: true },
27
+ _days: { state: true },
28
+ _made: { state: true },
29
+ }
30
+
31
+ constructor() {
32
+ super()
33
+ this._state = undefined
34
+ this._error = ''
35
+ this._name = ''
36
+ this._days = undefined
37
+ this._made = undefined
38
+ }
39
+
40
+ connectedCallback() {
41
+ super.connectedCallback()
42
+ this.#load()
43
+ }
44
+
45
+ async #load() {
46
+ try {
47
+ const response = await fetch(TOKENS_API, { credentials: 'include' })
48
+ this._state = response.ok ? await response.json() : { enabled: false }
49
+ this._days ??= this._state.defaultDays
50
+ } catch {
51
+ this._error = 'Could not load your tokens.'
52
+ }
53
+ }
54
+
55
+ async #create() {
56
+ this._error = ''
57
+ const response = await fetch(TOKENS_API, {
58
+ method: 'POST',
59
+ credentials: 'include',
60
+ headers: { 'content-type': 'application/json' },
61
+ body: JSON.stringify({ name: this._name, days: Number(this._days) }),
62
+ })
63
+ const body = await response.json().catch(() => ({}))
64
+ if (!response.ok) this._error = body.message ?? 'The token could not be made.'
65
+ else {
66
+ this._made = body
67
+ this._name = ''
68
+ }
69
+ await this.#load()
70
+ }
71
+
72
+ async #revoke(token) {
73
+ if (!confirm(revokeQuestion(token.name))) return
74
+ const response = await fetch(`${TOKENS_API}/${token.key}`, {
75
+ method: 'DELETE',
76
+ credentials: 'include',
77
+ })
78
+ if (!response.ok) this._error = 'That token could not be revoked.'
79
+ if (this._made?.key === token.key) this._made = undefined
80
+ await this.#load()
81
+ }
82
+
83
+ async #copy() {
84
+ await navigator.clipboard?.writeText(this._made.token)
85
+ }
86
+
87
+ #renderNew() {
88
+ if (!this._state.mayCreate) return nothing
89
+ const button = createButton(this._name)
90
+ return html`<div class="new">
91
+ <uui-input
92
+ label="Name"
93
+ placeholder="What it is for"
94
+ .value=${this._name}
95
+ @input=${(e) => {
96
+ this._name = e.target.value
97
+ }}></uui-input>
98
+ <uui-select
99
+ label="Lasts"
100
+ .options=${expiryChoices(this._state.maxDays).map((c) => ({
101
+ name: c.label,
102
+ value: String(c.days),
103
+ selected: c.days === Number(this._days),
104
+ }))}
105
+ @change=${(e) => {
106
+ this._days = e.target.value
107
+ }}></uui-select>
108
+ <uui-button
109
+ look="primary"
110
+ label=${button.label}
111
+ ?disabled=${!button.enabled}
112
+ @click=${() => this.#create()}></uui-button>
113
+ </div>`
114
+ }
115
+
116
+ render() {
117
+ if (!this._state?.enabled) return nothing
118
+ const items = this._state.items ?? []
119
+ return html`<uui-box headline=${HEADLINE}>
120
+ <p class="muted">${INTRO}</p>
121
+ ${this._error ? html`<p class="error">${this._error}</p>` : nothing}
122
+ ${
123
+ this._made
124
+ ? html`<div class="made">
125
+ <strong>${SHOWN_ONCE}</strong>
126
+ <code>${this._made.token}</code>
127
+ <uui-button look="secondary" label="Copy" @click=${() => this.#copy()}></uui-button>
128
+ </div>`
129
+ : nothing
130
+ }
131
+ ${this.#renderNew()}
132
+ ${
133
+ items.length === 0
134
+ ? html`<p>${NONE}</p>`
135
+ : html`<ul>
136
+ ${items.map(
137
+ (token) => html`<li>
138
+ <div>
139
+ <strong>${token.name}</strong>
140
+ <small>${tokenLine(token)}</small>
141
+ </div>
142
+ <uui-button look="secondary" color="danger" label="Revoke" @click=${() => this.#revoke(token)}></uui-button>
143
+ </li>`,
144
+ )}
145
+ </ul>`
146
+ }
147
+ </uui-box>`
148
+ }
149
+
150
+ static styles = css`
151
+ ul {
152
+ list-style: none;
153
+ margin: 0;
154
+ padding: 0;
155
+ }
156
+ li {
157
+ display: flex;
158
+ justify-content: space-between;
159
+ align-items: center;
160
+ gap: var(--uui-size-space-4);
161
+ padding: var(--uui-size-space-3) 0;
162
+ border-bottom: 1px solid var(--uui-color-divider);
163
+ }
164
+ li div {
165
+ display: flex;
166
+ flex-direction: column;
167
+ }
168
+ .new {
169
+ display: flex;
170
+ gap: var(--uui-size-space-3);
171
+ align-items: center;
172
+ margin-bottom: var(--uui-size-space-4);
173
+ }
174
+ .made {
175
+ display: flex;
176
+ flex-direction: column;
177
+ gap: var(--uui-size-space-2);
178
+ padding: var(--uui-size-space-4);
179
+ margin-bottom: var(--uui-size-space-4);
180
+ border: 1px solid var(--uui-color-positive);
181
+ border-radius: var(--uui-border-radius);
182
+ }
183
+ code {
184
+ word-break: break-all;
185
+ }
186
+ small,
187
+ .muted {
188
+ color: var(--uui-color-text-alt);
189
+ }
190
+ .error {
191
+ color: var(--uui-color-danger);
192
+ }
193
+ `
194
+ }
195
+
196
+ customElements.define('crombolo-cli-tokens', CromboloCliTokensElement)
@@ -4,6 +4,8 @@
4
4
  * server's (`@crombolo/core`, `permission-levels.ts`).
5
5
  */
6
6
 
7
+ import { PERMISSION_DESCRIPTION, PERMISSION_LABEL } from './cli-tokens-words.js'
8
+
7
9
  export const TABS = [
8
10
  { id: 'access', label: 'Access' },
9
11
  { id: 'permissions', label: 'Permissions' },
@@ -243,6 +245,12 @@ export const TRANSFER = [
243
245
  label: 'Install code on this site',
244
246
  line: 'Templates, server code and whole-site pushes: all of these run on the server. Nobody has this unless a group gives it, administrators included. Keep it on a group of its own, such as "Deployers".',
245
247
  },
248
+ {
249
+ group: 'Command line',
250
+ verb: 'Crombolo.CliTokens.Create',
251
+ label: PERMISSION_LABEL,
252
+ line: `${PERMISSION_DESCRIPTION}. Nobody has this unless a group gives it, administrators included.`,
253
+ },
246
254
  ]
247
255
 
248
256
  /** Verbs the editor speaks for; anything else a group holds is an extension's, kept as it is. */
@@ -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.65.1",
5
+ "version": "0.66.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -5,7 +5,8 @@
5
5
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
6
6
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
7
7
  import { UMB_MEDIA_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/media'
8
- import { readMediaAccess, summarise, usedByText } from './media-access.js'
8
+ import { readMediaAccess } from './media-access.js'
9
+ import { summarise, usedByText } from './media-access-rules.js'
9
10
 
10
11
  export default class CromboloMediaAccessInfoElement extends UmbLitElement {
11
12
  static properties = {
@@ -6,6 +6,7 @@
6
6
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
7
  import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
8
8
  import '@umbraco-cms/backoffice/member'
9
+ import { readMediaAccess, saveMediaAccess } from './media-access.js'
9
10
  import {
10
11
  bytesOf,
11
12
  describeAccess,
@@ -14,12 +15,10 @@ import {
14
15
  megabytesOf,
15
16
  PUBLIC_NOTE,
16
17
  READ_MODES,
17
- readMediaAccess,
18
18
  requestFor,
19
- saveMediaAccess,
20
19
  usedByText,
21
20
  WRITE_MODES,
22
- } from './media-access.js'
21
+ } from './media-access-rules.js'
23
22
 
24
23
  export default class CromboloMediaAccessModalElement extends UmbModalBaseElement {
25
24
  static properties = {
@@ -0,0 +1,96 @@
1
+ /** Types for media-access-rules.js, so a site's own tsconfig, without allowJs, checks the server against them. */
2
+
3
+ export interface GroupGrant {
4
+ name: string
5
+ read: boolean
6
+ write: boolean
7
+ }
8
+ export interface MemberGrant {
9
+ key: string
10
+ read: boolean
11
+ write: boolean
12
+ }
13
+ export interface Rule {
14
+ publicRead?: boolean
15
+ groups?: GroupGrant[]
16
+ members?: MemberGrant[]
17
+ newRead?: string | null
18
+ newWrite?: string | null
19
+ memberTypes?: string[]
20
+ memberMaxBytes?: number | null
21
+ }
22
+ export interface ItemPolicy {
23
+ readPolicy: string
24
+ writePolicy: string
25
+ }
26
+ export interface AccessState {
27
+ key?: string
28
+ name?: string
29
+ hasParent?: boolean
30
+ hasFile?: boolean
31
+ own?: Rule | null
32
+ inherited?: (Rule & { from?: { key?: string; name: string } }) | null
33
+ item: ItemPolicy & { creator?: { key: string; name?: string | null } | null }
34
+ protected?: boolean
35
+ memberGroups?: string[]
36
+ usedBy?: string[]
37
+ }
38
+ export interface AccessView {
39
+ read: string
40
+ write: string
41
+ allMembers: boolean
42
+ groups: GroupGrant[]
43
+ members: MemberGrant[]
44
+ newRead: string | null
45
+ newWrite: string | null
46
+ memberTypes: string[]
47
+ memberMaxBytes: number | null
48
+ }
49
+ export interface AccessForm {
50
+ inherit: boolean
51
+ read: string
52
+ write: string
53
+ allMembers?: boolean
54
+ groups: GroupGrant[]
55
+ members: MemberGrant[]
56
+ newRead?: string | null
57
+ newWrite?: string | null
58
+ memberTypes?: string[]
59
+ memberMaxBytes?: number | null
60
+ }
61
+ export interface AccessRequest {
62
+ rule:
63
+ | (Required<
64
+ Pick<
65
+ Rule,
66
+ 'publicRead' | 'groups' | 'newRead' | 'newWrite' | 'memberTypes' | 'memberMaxBytes'
67
+ >
68
+ > &
69
+ Pick<Rule, 'members'>)
70
+ | null
71
+ item: ItemPolicy
72
+ }
73
+
74
+ export const PUBLIC_NOTE: string
75
+ export function summarise(state: AccessState | undefined): string
76
+ export function groupRows(rule: Rule | null | undefined, memberGroups: string[]): GroupGrant[]
77
+ export function megabytesOf(bytes: number | null | undefined): string
78
+ export function bytesOf(megabytes: string | number | null | undefined): number | null
79
+ export const READ_MODES: { value: string; label: string }[]
80
+ export const WRITE_MODES: { value: string; label: string }[]
81
+ export function accessMode(
82
+ policy: string,
83
+ action: 'read' | 'write',
84
+ rule: Rule | null | undefined,
85
+ ): string
86
+ export function inheritsParent(state: AccessState): boolean
87
+ export function viewOf(
88
+ rule: Rule | null | undefined,
89
+ item: ItemPolicy & { creator?: { key: string } | null },
90
+ state: AccessState,
91
+ ): AccessView
92
+ export function formFor(state: AccessState): AccessForm & AccessView
93
+ export function inheritedForm(state: AccessState): AccessForm & AccessView
94
+ export function describeAccess(form: AccessForm, state: AccessState): string
95
+ export function requestFor(form: AccessForm, original?: ItemPolicy): AccessRequest
96
+ export function usedByText(bundles: string[] | null | undefined): string
@@ -0,0 +1,253 @@
1
+ /**
2
+ * The Permissions dialog's rules for a media folder or item (stories 204, 355):
3
+ * the form a saved state comes to, the one-line summary, and the body a form
4
+ * saves as. Browser-free, so the dialog, the command line and the tests share
5
+ * one copy. docs/rendering.md, "Protected media".
6
+ */
7
+
8
+ /**
9
+ * @typedef {{ name: string, read: boolean, write: boolean }} GroupGrant
10
+ * @typedef {{ key: string, read: boolean, write: boolean }} MemberGrant
11
+ * @typedef {{
12
+ * publicRead?: boolean,
13
+ * groups?: GroupGrant[],
14
+ * members?: MemberGrant[],
15
+ * newRead?: string | null,
16
+ * newWrite?: string | null,
17
+ * memberTypes?: string[],
18
+ * memberMaxBytes?: number | null,
19
+ * }} Rule
20
+ * @typedef {{
21
+ * key?: string,
22
+ * name?: string,
23
+ * hasParent?: boolean,
24
+ * hasFile?: boolean,
25
+ * own?: Rule | null,
26
+ * inherited?: (Rule & { from?: { key?: string, name: string } }) | null,
27
+ * item: {
28
+ * readPolicy: string,
29
+ * writePolicy: string,
30
+ * creator?: { key: string, name?: string | null } | null,
31
+ * },
32
+ * protected?: boolean,
33
+ * memberGroups?: string[],
34
+ * usedBy?: string[],
35
+ * }} AccessState
36
+ * @typedef {{
37
+ * inherit: boolean,
38
+ * read: string,
39
+ * write: string,
40
+ * allMembers?: boolean,
41
+ * groups: GroupGrant[],
42
+ * members: MemberGrant[],
43
+ * newRead?: string | null,
44
+ * newWrite?: string | null,
45
+ * memberTypes?: string[],
46
+ * memberMaxBytes?: number | null,
47
+ * }} AccessForm
48
+ */
49
+
50
+ export const PUBLIC_NOTE =
51
+ 'Anyone who has the link can open these files, without signing in, and can pass the link on.'
52
+
53
+ /**
54
+ * One line saying who can see and change a folder or file, as saved.
55
+ * @param {AccessState | undefined} state
56
+ * @returns {string}
57
+ */
58
+ export const summarise = (state) => (state ? describeAccess(formFor(state), state) : '')
59
+
60
+ /**
61
+ * The groups a rule shows: every member group on the site, ticked as the rule
62
+ * says, and any the rule names that no longer exists.
63
+ * @param {Rule | null | undefined} rule
64
+ * @param {string[]} memberGroups
65
+ * @returns {GroupGrant[]}
66
+ */
67
+ export function groupRows(rule, memberGroups) {
68
+ const named = new Map((rule?.groups ?? []).map((g) => [g.name.toLowerCase(), g]))
69
+ const rows = memberGroups.map((name) => {
70
+ const set = named.get(name.toLowerCase())
71
+ return { name, read: set?.read ?? false, write: set?.write ?? false }
72
+ })
73
+ for (const g of rule?.groups ?? [])
74
+ if (!memberGroups.some((name) => name.toLowerCase() === g.name.toLowerCase())) rows.push(g)
75
+ return rows
76
+ }
77
+
78
+ /** Megabytes as the dialog shows a size limit; empty for none. */
79
+ export const megabytesOf = (bytes) =>
80
+ bytes ? String(Math.round((bytes / (1024 * 1024)) * 100) / 100) : ''
81
+
82
+ /** A size limit typed in megabytes, as bytes; null when empty or not a size. */
83
+ export const bytesOf = (megabytes) => {
84
+ const value = Number(String(megabytes ?? '').trim())
85
+ return String(megabytes ?? '').trim() !== '' && Number.isFinite(value) && value > 0
86
+ ? Math.round(value * 1024 * 1024)
87
+ : null
88
+ }
89
+
90
+ /** Read audiences; the default, Enabled, lets anyone with the link see a file. */
91
+ export const READ_MODES = [
92
+ { value: 'public', label: 'Enabled' },
93
+ { value: 'private', label: 'Disabled' },
94
+ { value: 'custom', label: 'Custom' },
95
+ ]
96
+ /** Write audiences: members are never allowed to change files publicly. */
97
+ export const WRITE_MODES = [
98
+ { value: 'private', label: 'No Public Access' },
99
+ { value: 'custom', label: 'Custom' },
100
+ ]
101
+
102
+ /**
103
+ * An existing setting shown without broadening its audience.
104
+ * @param {string} policy
105
+ * @param {'read' | 'write'} action
106
+ * @param {Rule | null | undefined} rule
107
+ */
108
+ export function accessMode(policy, action, rule) {
109
+ if (policy === 'none' || (action === 'write' && ['public', 'members'].includes(policy)))
110
+ return 'private'
111
+ if (policy === 'public') return 'public'
112
+ if (policy !== 'inherit') return 'custom'
113
+ if (action === 'read' && (!rule || rule.publicRead)) return 'public'
114
+ const flag = action === 'read' ? 'read' : 'write'
115
+ return [...(rule?.groups ?? []), ...(rule?.members ?? [])].some((grant) => grant[flag])
116
+ ? 'custom'
117
+ : 'private'
118
+ }
119
+
120
+ /** Whether a folder or item follows the folder above it, with no settings of its own. */
121
+ export const inheritsParent = (state) =>
122
+ Boolean(state.hasParent) &&
123
+ !state.own &&
124
+ state.item.readPolicy === 'inherit' &&
125
+ state.item.writePolicy === 'inherit'
126
+
127
+ /**
128
+ * The dialog's form: the audiences a rule and an item's own policies come to.
129
+ * A file that may only be seen by the member who added it lists that member.
130
+ */
131
+ export function viewOf(rule, item, state) {
132
+ const members = (rule?.members ?? []).map((m) => ({ ...m }))
133
+ const creator = item.creator?.key
134
+ for (const action of ['read', 'write']) {
135
+ if (item[`${action}Policy`] !== 'creator' || !creator) continue
136
+ const existing = members.find((m) => m.key === creator)
137
+ if (existing) existing[action] = true
138
+ else members.push({ key: creator, read: action === 'read', write: action === 'write' })
139
+ }
140
+ const kept = (value) => (value === 'creator' ? value : null)
141
+ return {
142
+ read: accessMode(item.readPolicy, 'read', rule),
143
+ write: accessMode(item.writePolicy, 'write', rule),
144
+ allMembers: item.readPolicy === 'members',
145
+ groups: groupRows(rule, state.memberGroups ?? []),
146
+ members,
147
+ newRead: kept(state.own?.newRead),
148
+ newWrite: kept(state.own?.newWrite),
149
+ memberTypes: [...(rule?.memberTypes ?? [])],
150
+ memberMaxBytes: rule?.memberMaxBytes ?? null,
151
+ }
152
+ }
153
+
154
+ const INHERITED_ITEM = { readPolicy: 'inherit', writePolicy: 'inherit' }
155
+
156
+ /**
157
+ * The form for a folder or item as saved: following the folder above, or its own settings.
158
+ * @param {AccessState} state
159
+ * @returns {AccessForm}
160
+ */
161
+ export function formFor(state) {
162
+ const inherit = inheritsParent(state)
163
+ return {
164
+ inherit,
165
+ ...(inherit
166
+ ? viewOf(state.inherited, INHERITED_ITEM, state)
167
+ : viewOf(state.own ?? state.inherited, state.item, state)),
168
+ }
169
+ }
170
+
171
+ /** The form when "Inherit parent permissions" is ticked again: the folder above's settings. */
172
+ export const inheritedForm = (state) => ({
173
+ inherit: true,
174
+ ...viewOf(state.inherited, INHERITED_ITEM, state),
175
+ })
176
+
177
+ const listed = (names) =>
178
+ names.length <= 1 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`
179
+
180
+ const chosen = (form, action) => {
181
+ const groups = form.groups.filter((g) => g[action]).map((g) => g.name)
182
+ const count = form.members.filter((m) => m[action]).length
183
+ return listed([...groups, ...(count ? [`${count} chosen member${count === 1 ? '' : 's'}`] : [])])
184
+ }
185
+
186
+ /**
187
+ * Where a form's settings come from and who they let in, in a sentence or two.
188
+ * @param {AccessForm} form
189
+ * @param {AccessState} state
190
+ * @returns {string}
191
+ */
192
+ export function describeAccess(form, state) {
193
+ const source = form.inherit
194
+ ? state.inherited?.from
195
+ ? `Inherited from ${state.inherited.from.name}.`
196
+ : 'Default permissions.'
197
+ : state.hasParent
198
+ ? 'Set for this item.'
199
+ : ''
200
+ const readers = chosen(form, 'read')
201
+ const writers = chosen(form, 'write')
202
+ const read =
203
+ form.read === 'public'
204
+ ? 'Anyone with the link can see this.'
205
+ : form.read === 'private'
206
+ ? 'Only back-office users can see this.'
207
+ : form.allMembers
208
+ ? 'All signed-in members can see this.'
209
+ : readers
210
+ ? `Only ${readers} can see this.`
211
+ : 'Nobody has been chosen to see this yet.'
212
+ const write =
213
+ form.write === 'custom' && writers ? `${writers} can change it.` : 'No members can change it.'
214
+ return [source, read, write].filter(Boolean).join(' ')
215
+ }
216
+
217
+ /**
218
+ * What the dialog sends: no settings of its own when it inherits, else a rule
219
+ * holding both audiences. An all-members read nobody changed is kept as it was.
220
+ * @param {AccessForm} form
221
+ * @param {{ readPolicy: string, writePolicy: string }} [original]
222
+ */
223
+ export function requestFor(form, original = INHERITED_ITEM) {
224
+ if (form.inherit) return { rule: null, item: { ...INHERITED_ITEM } }
225
+ const grants = (list) =>
226
+ list
227
+ .map((g) => ({
228
+ ...g,
229
+ read: form.read === 'custom' && g.read,
230
+ write: form.write === 'custom' && g.write,
231
+ }))
232
+ .filter((g) => g.read || g.write)
233
+ const members = grants(form.members)
234
+ return {
235
+ rule: {
236
+ publicRead: form.read === 'public',
237
+ groups: grants(form.groups),
238
+ ...(members.length ? { members } : {}),
239
+ newRead: form.newRead ?? null,
240
+ newWrite: form.newWrite ?? null,
241
+ memberTypes: form.memberTypes ?? [],
242
+ memberMaxBytes: form.memberMaxBytes ?? null,
243
+ },
244
+ item: {
245
+ readPolicy: form.allMembers && original.readPolicy === 'members' ? 'members' : 'inherit',
246
+ writePolicy: 'inherit',
247
+ },
248
+ }
249
+ }
250
+
251
+ /** Says which site features use a folder, in a sentence. */
252
+ export const usedByText = (bundles) =>
253
+ bundles?.length ? `Used by ${bundles.join(', ')} to store members' files.` : ''
@@ -2,7 +2,8 @@
2
2
  * "Permissions" on media folders and items (story 204): who may read and
3
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/rendering.md, "Protected media".
5
+ * refuses what the user may not do whatever this shows. The dialog's rules are
6
+ * in `media-access-rules.js`. docs/rendering.md, "Protected media".
6
7
  */
7
8
 
8
9
  export const MEDIA_ACCESS_MODAL = 'Crombolo.Modal.MediaAccess'
@@ -40,188 +41,6 @@ export const problemFor = (status) =>
40
41
  ? 'This media item could not be found.'
41
42
  : 'The permissions could not be loaded. Try again.'
42
43
 
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
44
  const MEDIA_WRITE = /\/management\/api\/v1\/media\/([0-9a-f-]{36})(\/move|\/move-to-recycle-bin)?$/i
226
45
 
227
46
  /**
@@ -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.65.1",
5
+ "version": "0.66.0",
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.65.1",
5
+ "version": "0.66.0",
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.65.1",
5
+ "version": "0.66.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -98,6 +98,17 @@
98
98
  "description": "Install bundles, the code a bundle carries and the templates it adds or changes, and push a whole site: all of these run on the server. Administrators only have this when a group gives it to them: give it to a group of its own rather than Administrators"
99
99
  }
100
100
  },
101
+ {
102
+ "type": "entityUserPermission",
103
+ "alias": "Crombolo.UserPermission.CliTokens.Create",
104
+ "name": "Crombolo Command-line Tokens Permission",
105
+ "forEntityTypes": ["crombolo-remote"],
106
+ "meta": {
107
+ "verbs": ["Crombolo.CliTokens.Create"],
108
+ "label": "Command-line tokens",
109
+ "description": "Create tokens that let scripts run commands as you"
110
+ }
111
+ },
101
112
  {
102
113
  "type": "entityUserPermission",
103
114
  "alias": "Crombolo.UserPermission.Media.Read",
@@ -167,6 +178,17 @@
167
178
  "pathname": "devices"
168
179
  }
169
180
  },
181
+ {
182
+ "type": "userProfileApp",
183
+ "alias": "Crombolo.UserProfileApp.CliTokens",
184
+ "name": "Crombolo Command-line Tokens",
185
+ "element": "/crombolo-plugin/cli-tokens.js",
186
+ "weight": 90,
187
+ "meta": {
188
+ "label": "Command-line tokens",
189
+ "pathname": "tokens"
190
+ }
191
+ },
170
192
  {
171
193
  "type": "mfaLoginProvider",
172
194
  "alias": "Crombolo.MfaLoginProvider.Authenticator",
@@ -442,6 +464,27 @@
442
464
  }
443
465
  ]
444
466
  },
467
+ {
468
+ "type": "workspaceView",
469
+ "alias": "Crombolo.WorkspaceView.User.CliTokens",
470
+ "name": "Crombolo User Command-line Tokens",
471
+ "element": "/crombolo-plugin/cli-tokens-user.js",
472
+ "weight": 50,
473
+ "meta": {
474
+ "label": "Tokens",
475
+ "pathname": "tokens",
476
+ "icon": "icon-key"
477
+ },
478
+ "conditions": [
479
+ {
480
+ "alias": "Umb.Condition.WorkspaceAlias",
481
+ "match": "Umb.Workspace.User"
482
+ },
483
+ {
484
+ "alias": "Umb.Condition.CurrentUser.IsAdmin"
485
+ }
486
+ ]
487
+ },
445
488
  {
446
489
  "type": "dashboard",
447
490
  "alias": "Crombolo.Dashboard.ContentSettings",