@quazardous/qdadm 2.46.0 → 2.48.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/dist/styles/qdadm.css +1 -1
- package/package.json +1 -1
- package/src/components/SeverityTag.vue +15 -1
- package/src/components/display/QdPending.vue +58 -0
- package/src/components/display/QdPendingZone.vue +104 -0
- package/src/components/index.ts +5 -0
- package/src/components/lists/ListPage.vue +33 -4
- package/src/components/show/ShowDisplay.vue +13 -2
- package/src/components/show/ShowPage.vue +6 -6
- package/src/components/tasks/TaskDialog.vue +13 -157
- package/src/components/tasks/TaskHost.vue +28 -2
- package/src/components/tasks/TaskRunStatus.vue +63 -0
- package/src/components/tasks/TaskRunView.vue +197 -0
- package/src/components/tasks/TaskSequenceDialog.vue +157 -0
- package/src/components/tasks/TaskTray.vue +33 -13
- package/src/composables/index.ts +6 -0
- package/src/composables/useAsyncRead.ts +109 -0
- package/src/composables/useEntityItemFormPage.ts +13 -6
- package/src/composables/useEntityItemFormPage.types.ts +4 -1
- package/src/composables/useEntityItemShowPage.ts +18 -7
- package/src/composables/useFieldManager.ts +11 -2
- package/src/composables/useListPage.filters.ts +21 -1
- package/src/composables/useListPage.ts +68 -9
- package/src/composables/useListPage.types.ts +4 -1
- package/src/composables/useNavContext.ts +5 -4
- package/src/entity/EntityManager.ts +17 -0
- package/src/entity/EntityManager.types.ts +2 -0
- package/src/entity/storage/MockApiStorage.ts +31 -7
- package/src/i18n/defaults/core.en.generated.ts +32 -0
- package/src/i18n/defaults/core.en.yml +32 -0
- package/src/i18n/defaults/core.fr.generated.ts +32 -0
- package/src/i18n/defaults/core.fr.yml +32 -0
- package/src/i18n/optionLabels.ts +35 -0
- package/src/i18n/types.ts +5 -0
- package/src/index.ts +11 -0
- package/src/kernel/Kernel.i18n.ts +36 -3
- package/src/kernel/Kernel.registries.ts +11 -7
- package/src/kernel/Kernel.ts +2 -0
- package/src/kernel/KernelContext.permissions.ts +11 -0
- package/src/kernel/KernelContext.ts +6 -0
- package/src/kernel/KernelContext.types.ts +2 -0
- package/src/orchestrator/Orchestrator.ts +3 -0
- package/src/security/PersistableRolesProvider.ts +61 -3
- package/src/security/StaticRolesProvider.ts +6 -0
- package/src/styles/_pending.scss +125 -0
- package/src/styles/_tasks.scss +126 -0
- package/src/styles/index.scss +1 -0
- package/src/tasks/taskStore.ts +449 -14
- package/src/tasks/taskUi.ts +6 -0
- package/src/tasks/useTaskNotifications.ts +6 -2
- package/src/tasks/useTaskRunner.ts +24 -0
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
/* GENERATED from core.fr.yml — DO NOT EDIT.
|
|
2
2
|
* Run `npm run gen:i18n-defaults -w packages/qdadm` to regenerate. */
|
|
3
3
|
export default `core:
|
|
4
|
+
# A filter's "all" choice (#4692)
|
|
5
|
+
filters:
|
|
6
|
+
all: "Tous : {field}"
|
|
7
|
+
# The table's own column headers (#4686)
|
|
8
|
+
table:
|
|
9
|
+
actions: Actions
|
|
10
|
+
# Boolean values (#4686)
|
|
11
|
+
values:
|
|
12
|
+
"yes": Oui
|
|
13
|
+
"no": Non
|
|
4
14
|
actions:
|
|
5
15
|
save: Enregistrer
|
|
6
16
|
cancel: Annuler
|
|
7
17
|
delete: Supprimer
|
|
8
18
|
edit: Modifier
|
|
9
19
|
create: Créer
|
|
20
|
+
createEntity: "Créer : {entity}"
|
|
10
21
|
update: Mettre à jour
|
|
11
22
|
createAndClose: Créer et fermer
|
|
12
23
|
updateAndClose: Mettre à jour et fermer
|
|
@@ -158,6 +169,8 @@ export default `core:
|
|
|
158
169
|
close: Fermer
|
|
159
170
|
background: Continuer en arrière-plan
|
|
160
171
|
open: Ouvrir la tâche
|
|
172
|
+
follow: Suivre
|
|
173
|
+
notRun: Pas encore lancée
|
|
161
174
|
readError: "Lecture de la tâche impossible ({error}), nouvel essai"
|
|
162
175
|
start: Lancer
|
|
163
176
|
dontStart: Ne pas lancer
|
|
@@ -176,6 +189,25 @@ export default `core:
|
|
|
176
189
|
subs: "{count} sous-phase | {count} sous-phases"
|
|
177
190
|
filter: "Phase : {name}"
|
|
178
191
|
showAll: Voir tout le journal
|
|
192
|
+
# Tasks chained in one window (#4934)
|
|
193
|
+
sequence:
|
|
194
|
+
progress: "{done}/{total}"
|
|
195
|
+
step: "Étape {n}"
|
|
196
|
+
pending: En attente
|
|
197
|
+
skipped: Non lancée
|
|
198
|
+
why:
|
|
199
|
+
error: Une étape précédente a échoué
|
|
200
|
+
cancelled: La suite a été arrêtée
|
|
201
|
+
reload: La page a été rechargée
|
|
202
|
+
back: Retour à la liste
|
|
203
|
+
details: Voir cette étape
|
|
204
|
+
cancel: Arrêter la suite
|
|
205
|
+
# Waiting states (#4665)
|
|
206
|
+
pending:
|
|
207
|
+
reading: Lecture…
|
|
208
|
+
unavailable: Indisponible
|
|
209
|
+
failed: "Lecture impossible : {error}"
|
|
210
|
+
retry: Réessayer
|
|
179
211
|
# LoginPage (#4168)
|
|
180
212
|
login:
|
|
181
213
|
username: Identifiant
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
core:
|
|
2
|
+
# A filter's "all" choice (#4692)
|
|
3
|
+
filters:
|
|
4
|
+
all: "Tous : {field}"
|
|
5
|
+
# The table's own column headers (#4686)
|
|
6
|
+
table:
|
|
7
|
+
actions: Actions
|
|
8
|
+
# Boolean values (#4686)
|
|
9
|
+
values:
|
|
10
|
+
"yes": Oui
|
|
11
|
+
"no": Non
|
|
2
12
|
actions:
|
|
3
13
|
save: Enregistrer
|
|
4
14
|
cancel: Annuler
|
|
5
15
|
delete: Supprimer
|
|
6
16
|
edit: Modifier
|
|
7
17
|
create: Créer
|
|
18
|
+
createEntity: "Créer : {entity}"
|
|
8
19
|
update: Mettre à jour
|
|
9
20
|
createAndClose: Créer et fermer
|
|
10
21
|
updateAndClose: Mettre à jour et fermer
|
|
@@ -156,6 +167,8 @@ core:
|
|
|
156
167
|
close: Fermer
|
|
157
168
|
background: Continuer en arrière-plan
|
|
158
169
|
open: Ouvrir la tâche
|
|
170
|
+
follow: Suivre
|
|
171
|
+
notRun: Pas encore lancée
|
|
159
172
|
readError: "Lecture de la tâche impossible ({error}), nouvel essai"
|
|
160
173
|
start: Lancer
|
|
161
174
|
dontStart: Ne pas lancer
|
|
@@ -174,6 +187,25 @@ core:
|
|
|
174
187
|
subs: "{count} sous-phase | {count} sous-phases"
|
|
175
188
|
filter: "Phase : {name}"
|
|
176
189
|
showAll: Voir tout le journal
|
|
190
|
+
# Tasks chained in one window (#4934)
|
|
191
|
+
sequence:
|
|
192
|
+
progress: "{done}/{total}"
|
|
193
|
+
step: "Étape {n}"
|
|
194
|
+
pending: En attente
|
|
195
|
+
skipped: Non lancée
|
|
196
|
+
why:
|
|
197
|
+
error: Une étape précédente a échoué
|
|
198
|
+
cancelled: La suite a été arrêtée
|
|
199
|
+
reload: La page a été rechargée
|
|
200
|
+
back: Retour à la liste
|
|
201
|
+
details: Voir cette étape
|
|
202
|
+
cancel: Arrêter la suite
|
|
203
|
+
# Waiting states (#4665)
|
|
204
|
+
pending:
|
|
205
|
+
reading: Lecture…
|
|
206
|
+
unavailable: Indisponible
|
|
207
|
+
failed: "Lecture impossible : {error}"
|
|
208
|
+
retry: Réessayer
|
|
177
209
|
# LoginPage (#4168)
|
|
178
210
|
login:
|
|
179
211
|
username: Identifiant
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option labels from the catalogue (#4686)
|
|
3
|
+
*
|
|
4
|
+
* A select field's options translate through
|
|
5
|
+
* `entities.<entity>.fields.<field>.options.<value>`; an option without a key
|
|
6
|
+
* keeps the label it was declared with. The declared labels are kept on the
|
|
7
|
+
* result so a later locale change translates from them again.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface CatalogueLike {
|
|
11
|
+
resolve: (key: string) => { hit: boolean; result: string }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface LabeledOption {
|
|
15
|
+
label?: string
|
|
16
|
+
value?: unknown
|
|
17
|
+
[key: string]: unknown
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The options with their labels in the current language. */
|
|
21
|
+
export function translateOptions<O extends LabeledOption>(
|
|
22
|
+
i18n: CatalogueLike | null | undefined,
|
|
23
|
+
entity: string | null | undefined,
|
|
24
|
+
field: string,
|
|
25
|
+
options: O[] | null | undefined
|
|
26
|
+
): O[] | null | undefined {
|
|
27
|
+
if (!i18n || !entity || !Array.isArray(options)) return options
|
|
28
|
+
return options.map((option) => {
|
|
29
|
+
if (option === null || typeof option !== 'object' || option.value === undefined || option.value === null) return option
|
|
30
|
+
const declared = (option as O & { _declaredLabel?: string })._declaredLabel ?? option.label
|
|
31
|
+
const trace = i18n.resolve(`entities.${entity}.fields.${field}.options.${String(option.value)}`)
|
|
32
|
+
const label = trace.hit && typeof trace.result === 'string' ? trace.result : declared
|
|
33
|
+
return { ...option, label, _declaredLabel: declared }
|
|
34
|
+
})
|
|
35
|
+
}
|
package/src/i18n/types.ts
CHANGED
|
@@ -39,4 +39,9 @@ export interface I18nOptions extends BaseI18nOptions {
|
|
|
39
39
|
* but the debug collector consumes this signal.
|
|
40
40
|
*/
|
|
41
41
|
emitMissing?: boolean
|
|
42
|
+
/**
|
|
43
|
+
* Keep the user's language across reloads, in localStorage
|
|
44
|
+
* (`qdadm.locale.<app>`). Default: `true` (#4686).
|
|
45
|
+
*/
|
|
46
|
+
rememberLocale?: boolean
|
|
42
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -341,6 +341,12 @@ export {
|
|
|
341
341
|
type UseLogStreamOptions,
|
|
342
342
|
type UseLogStreamReturn,
|
|
343
343
|
} from './composables/useLogStream'
|
|
344
|
+
export {
|
|
345
|
+
useAsyncRead,
|
|
346
|
+
readErrorMessage,
|
|
347
|
+
type UseAsyncReadOptions,
|
|
348
|
+
type UseAsyncReadReturn,
|
|
349
|
+
} from './composables/useAsyncRead'
|
|
344
350
|
|
|
345
351
|
// Route-state persistence (#2146) — where a route remembers what it shows.
|
|
346
352
|
export {
|
|
@@ -475,6 +481,11 @@ export {
|
|
|
475
481
|
type TaskFollow,
|
|
476
482
|
type TaskConfirm,
|
|
477
483
|
type RunOptions,
|
|
484
|
+
type SequenceStep,
|
|
485
|
+
type SequenceOptions,
|
|
486
|
+
type SequenceStepStatus,
|
|
487
|
+
type TaskSequence,
|
|
488
|
+
type TaskSequenceStep,
|
|
478
489
|
} from './tasks/taskStore'
|
|
479
490
|
export {
|
|
480
491
|
TASK_PHASE_STATE_ICONS,
|
|
@@ -14,16 +14,49 @@ import type { Kernel } from './Kernel'
|
|
|
14
14
|
// #1196 Phase B — this-typing against the real Kernel shape (was Self = any)
|
|
15
15
|
type Self = Kernel
|
|
16
16
|
|
|
17
|
+
/** Where the user's language is kept: one key per app (#4686) */
|
|
18
|
+
function localeKey(kernel: Self): string {
|
|
19
|
+
const name = ((kernel.options.app as { name?: string } | undefined)?.name ?? 'app').toLowerCase().replace(/[^a-z0-9]+/g, '-')
|
|
20
|
+
return `qdadm.locale.${name}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function readLocale(key: string): string | null {
|
|
24
|
+
try {
|
|
25
|
+
return globalThis.localStorage?.getItem(key) ?? null
|
|
26
|
+
} catch {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function writeLocale(key: string, locale: string): void {
|
|
32
|
+
try {
|
|
33
|
+
globalThis.localStorage?.setItem(key, locale)
|
|
34
|
+
} catch {
|
|
35
|
+
// No storage: the language lasts the page
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
export function applyI18nMethods(KernelClass: { prototype: Kernel }): void {
|
|
18
40
|
const proto = KernelClass.prototype
|
|
19
41
|
|
|
20
42
|
proto._createI18n = function (this: Self): void {
|
|
21
43
|
const opts = (this.options.i18n as I18nOptions | undefined) ?? {}
|
|
22
44
|
this.i18nInstance = new I18n(opts, { signals: this.signals })
|
|
45
|
+
// The user's language survives a reload (#4686), per app
|
|
46
|
+
if (opts.rememberLocale !== false) {
|
|
47
|
+
this.signals.on('locale:changed', (event) => {
|
|
48
|
+
if (typeof event.data === 'string') writeLocale(localeKey(this), event.data)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
23
51
|
}
|
|
24
52
|
|
|
25
|
-
proto._bootstrapI18n = function (this: Self): Promise<void> {
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
proto._bootstrapI18n = async function (this: Self): Promise<void> {
|
|
54
|
+
const i18n = this.i18nInstance
|
|
55
|
+
if (!i18n) return
|
|
56
|
+
await i18n.bootstrap()
|
|
57
|
+
const opts = (this.options.i18n as I18nOptions | undefined) ?? {}
|
|
58
|
+
if (opts.rememberLocale === false) return
|
|
59
|
+
const saved = readLocale(localeKey(this))
|
|
60
|
+
if (saved && saved !== i18n.locale.value) await i18n.changeLocale(saved)
|
|
28
61
|
}
|
|
29
62
|
}
|
|
@@ -45,8 +45,12 @@ export function applyRegistryMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
45
45
|
this.signals = this.options.existingSignals
|
|
46
46
|
return
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Not this.options.debug (#4685): the debug bar turns that on, and the
|
|
49
|
+
// event kernel's own tracing JSON-stringifies every payload, so a payload
|
|
50
|
+
// holding a cycle (a manager with its I18n) threw before any handler ran
|
|
51
|
+
// and every save failed in dev. The bar's signal panel traces safely;
|
|
52
|
+
// signals.debug(true) still turns the raw tracing on by hand.
|
|
53
|
+
this.signals = createSignalBus({ debug: false })
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/**
|
|
@@ -58,11 +62,8 @@ export function applyRegistryMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
58
62
|
// which is the failure this lot exists to remove.
|
|
59
63
|
if (this.hookRegistry) return
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
this.hookRegistry = createHookRegistry({
|
|
63
|
-
kernel: this.signals.getKernel(),
|
|
64
|
-
debug,
|
|
65
|
-
})
|
|
65
|
+
// It shares the signal bus's kernel, tracing off (see _createSignalBus)
|
|
66
|
+
this.hookRegistry = createHookRegistry({ kernel: this.signals.getKernel() })
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
@@ -90,6 +91,8 @@ export function applyRegistryMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
90
91
|
this.orchestrator.kernelOptions = {
|
|
91
92
|
defaultEntityCacheTtlMs: this.options.defaultEntityCacheTtlMs,
|
|
92
93
|
}
|
|
94
|
+
// Entity labels come from the catalogue (#4686)
|
|
95
|
+
this.orchestrator.i18n = this.i18nInstance ?? null
|
|
93
96
|
|
|
94
97
|
if (this.options.toast) {
|
|
95
98
|
this.orchestrator.setToastConfig(this.options.toast)
|
|
@@ -160,6 +163,7 @@ export function applyRegistryMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
160
163
|
})
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
this.rolesProvider = (rolesProvider as Self['rolesProvider']) ?? null
|
|
163
167
|
this.securityChecker = createSecurityChecker({
|
|
164
168
|
rolesProvider: rolesProvider || undefined,
|
|
165
169
|
grant: security.grant,
|
package/src/kernel/Kernel.ts
CHANGED
|
@@ -109,6 +109,8 @@ export class Kernel {
|
|
|
109
109
|
liveEntityRouter: LiveEntityRouter | null = null
|
|
110
110
|
layoutComponents: InternalLayoutComponents | null = null
|
|
111
111
|
securityChecker: SecurityChecker | null = null
|
|
112
|
+
/** The roles provider, where a module's default grants go (`ctx.grant`, #4694) */
|
|
113
|
+
rolesProvider: { addDefaultGrants?: (role: string, permissions: string[]) => void } | null = null
|
|
112
114
|
permissionRegistry!: PermissionRegistry
|
|
113
115
|
moduleLoader: ModuleLoader | null = null
|
|
114
116
|
activeStack: ActiveStack | null = null
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Patch KernelContext prototype with permission registration methods:
|
|
3
3
|
* - permissions(namespace, perms, options) — generic registration
|
|
4
4
|
* - entityPermissions(entity, perms) — shorthand for entity-scoped
|
|
5
|
+
* - grant(role, perms) — default grants brought by the module (#4694)
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import type { PermissionMeta, PermissionOptions } from './KernelContext.types'
|
|
@@ -28,6 +29,16 @@ export function applyPermissionMethods(KernelContextClass: { prototype: KernelCo
|
|
|
28
29
|
return this
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
proto.grant = function (this: Self, role: string, permissions: string | string[]): Self {
|
|
33
|
+
const list = Array.isArray(permissions) ? permissions : [permissions]
|
|
34
|
+
const provider = this._kernel.rolesProvider
|
|
35
|
+
if (provider?.addDefaultGrants) provider.addDefaultGrants(role, list)
|
|
36
|
+
else if (this._kernel.options.debug) {
|
|
37
|
+
console.warn(`[qdadm] ctx.grant('${role}', …): the roles provider takes no default grants, nothing granted`)
|
|
38
|
+
}
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
proto.entityPermissions = function (
|
|
32
43
|
this: Self,
|
|
33
44
|
entity: string,
|
|
@@ -229,6 +229,12 @@ export interface KernelContext {
|
|
|
229
229
|
entity: string,
|
|
230
230
|
permissions: Record<string, string | PermissionMeta>
|
|
231
231
|
): this
|
|
232
|
+
/**
|
|
233
|
+
* Default grants brought by this module (#4694): `ctx.grant('ROLE_USER',
|
|
234
|
+
* ['entity:suppliers:create'])`. The app's roles and the Roles screen still
|
|
235
|
+
* have the last word.
|
|
236
|
+
*/
|
|
237
|
+
grant(role: string, permissions: string | string[]): this
|
|
232
238
|
|
|
233
239
|
// i18n (KernelContext.i18n.ts)
|
|
234
240
|
messages(locale: string, bundle: MessagesBundle): this
|
|
@@ -62,6 +62,8 @@ export interface KernelInterface {
|
|
|
62
62
|
hookRegistry: HookRegistry | null
|
|
63
63
|
deferred: DeferredRegistry | null
|
|
64
64
|
securityChecker: SecurityChecker | null
|
|
65
|
+
/** Where a module's default grants go (`ctx.grant`, #4694) */
|
|
66
|
+
rolesProvider?: { addDefaultGrants?: (role: string, permissions: string[]) => void } | null
|
|
65
67
|
permissionRegistry: PermissionRegistry | null
|
|
66
68
|
activeStack: unknown
|
|
67
69
|
stackHydrator: unknown
|
|
@@ -112,6 +112,9 @@ export class Orchestrator {
|
|
|
112
112
|
defaultEntityCacheTtlMs?: number
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/** The app's catalogue, set by the Kernel: managers read their labels from it (#4686). */
|
|
116
|
+
i18n: { resolve: (key: string) => { hit: boolean; result: string } } | null = null
|
|
117
|
+
|
|
115
118
|
constructor(options: OrchestratorOptions = {}) {
|
|
116
119
|
const {
|
|
117
120
|
entityFactory = null,
|
|
@@ -68,6 +68,11 @@ export interface RoleConfig {
|
|
|
68
68
|
role_hierarchy?: Record<string, string[]>
|
|
69
69
|
role_permissions?: Record<string, string[]>
|
|
70
70
|
role_labels?: Record<string, string>
|
|
71
|
+
/**
|
|
72
|
+
* The default grants as they were when this config was saved (#4694): a
|
|
73
|
+
* default added since reaches the role, one the user removed stays removed.
|
|
74
|
+
*/
|
|
75
|
+
defaults_snapshot?: Record<string, string[]>
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
/**
|
|
@@ -95,6 +100,13 @@ export interface PersistableRolesProviderOptions {
|
|
|
95
100
|
defaults?: RoleConfig
|
|
96
101
|
mergeStrategy?: MergeStrategy
|
|
97
102
|
autoLoad?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* Save the defaults the roles were saved against (`defaults_snapshot`), so a
|
|
105
|
+
* default added later reaches a saved role (#4694). On for
|
|
106
|
+
* createLocalStorageRolesProvider; off by default, so a backend's payload
|
|
107
|
+
* keeps its shape.
|
|
108
|
+
*/
|
|
109
|
+
trackDefaults?: boolean
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
/**
|
|
@@ -107,17 +119,42 @@ export interface LocalStorageRolesProviderOptions {
|
|
|
107
119
|
mergeStrategy?: MergeStrategy
|
|
108
120
|
}
|
|
109
121
|
|
|
122
|
+
function cloneGrants(grants: Record<string, string[]>): Record<string, string[]> {
|
|
123
|
+
return Object.fromEntries(Object.entries(grants).map(([role, perms]) => [role, [...perms]]))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A saved role's grants, plus the defaults added since it was saved (#4694).
|
|
128
|
+
* Without a snapshot (a config saved before it existed) the saved list stands
|
|
129
|
+
* as it is: there is no telling a default the user removed from a new one.
|
|
130
|
+
*/
|
|
131
|
+
function withNewDefaults(
|
|
132
|
+
saved: Record<string, string[]>,
|
|
133
|
+
defaults: Record<string, string[]>,
|
|
134
|
+
snapshot: Record<string, string[]> | undefined
|
|
135
|
+
): Record<string, string[]> {
|
|
136
|
+
if (!snapshot) return saved
|
|
137
|
+
const out: Record<string, string[]> = {}
|
|
138
|
+
for (const [role, perms] of Object.entries(saved)) {
|
|
139
|
+
const seen = snapshot[role] ?? []
|
|
140
|
+
const added = (defaults[role] ?? []).filter((p) => !seen.includes(p) && !perms.includes(p))
|
|
141
|
+
out[role] = [...perms, ...added]
|
|
142
|
+
}
|
|
143
|
+
return out
|
|
144
|
+
}
|
|
145
|
+
|
|
110
146
|
export class PersistableRoleProvider extends RoleProvider {
|
|
111
147
|
private _loadFn: LoadCallback | null
|
|
112
148
|
private _persistFn: PersistCallback | null
|
|
113
149
|
private _mergeStrategy: MergeStrategy
|
|
114
150
|
private _autoLoad: boolean
|
|
151
|
+
private _trackDefaults: boolean
|
|
115
152
|
|
|
116
153
|
// Fixed (incompressible, always applied on top)
|
|
117
|
-
private _fixed: Required<RoleConfig
|
|
154
|
+
private _fixed: Required<Omit<RoleConfig, 'defaults_snapshot'>>
|
|
118
155
|
|
|
119
156
|
// Defaults (fallback)
|
|
120
|
-
private _defaults: Required<RoleConfig
|
|
157
|
+
private _defaults: Required<Omit<RoleConfig, 'defaults_snapshot'>>
|
|
121
158
|
|
|
122
159
|
// Current state (starts with defaults)
|
|
123
160
|
protected _hierarchy: Record<string, string[]>
|
|
@@ -129,6 +166,8 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
129
166
|
public _loaded: boolean = false
|
|
130
167
|
private _loading: Promise<void> | null = null
|
|
131
168
|
private _dirty: boolean = false
|
|
169
|
+
// The last saved config applied, kept to merge again when defaults grow (#4694)
|
|
170
|
+
private _lastData: RoleConfig | null = null
|
|
132
171
|
|
|
133
172
|
/**
|
|
134
173
|
* Create a persistable roles provider
|
|
@@ -139,6 +178,7 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
139
178
|
this._loadFn = options.load || null
|
|
140
179
|
this._persistFn = options.persist || null
|
|
141
180
|
this._mergeStrategy = options.mergeStrategy || 'extend'
|
|
181
|
+
this._trackDefaults = options.trackDefaults ?? false
|
|
142
182
|
this._autoLoad = options.autoLoad ?? true
|
|
143
183
|
|
|
144
184
|
// Fixed (incompressible, always applied on top)
|
|
@@ -207,6 +247,7 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
207
247
|
* Apply loaded data according to merge strategy
|
|
208
248
|
*/
|
|
209
249
|
_applyData(data: RoleConfig): void {
|
|
250
|
+
this._lastData = data
|
|
210
251
|
switch (this._mergeStrategy) {
|
|
211
252
|
case 'replace':
|
|
212
253
|
// Loaded data replaces everything
|
|
@@ -228,7 +269,7 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
228
269
|
}
|
|
229
270
|
this._permissions = {
|
|
230
271
|
...this._defaults.role_permissions,
|
|
231
|
-
...(data.role_permissions || {}),
|
|
272
|
+
...withNewDefaults(data.role_permissions || {}, this._defaults.role_permissions, data.defaults_snapshot),
|
|
232
273
|
}
|
|
233
274
|
this._labels = {
|
|
234
275
|
...this._defaults.role_labels,
|
|
@@ -238,6 +279,21 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
238
279
|
}
|
|
239
280
|
}
|
|
240
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Default grants brought by a module (`ctx.grant`, #4694). They join the
|
|
284
|
+
* defaults; a role the user saved keeps its own list, plus the defaults it
|
|
285
|
+
* has not seen yet (see `defaults_snapshot`).
|
|
286
|
+
*/
|
|
287
|
+
addDefaultGrants(role: string, permissions: string[]): void {
|
|
288
|
+
const current = this._defaults.role_permissions[role] ?? []
|
|
289
|
+
this._defaults.role_permissions = {
|
|
290
|
+
...this._defaults.role_permissions,
|
|
291
|
+
[role]: [...current, ...permissions.filter((p) => !current.includes(p))],
|
|
292
|
+
}
|
|
293
|
+
if (this._lastData) this._applyData(this._lastData)
|
|
294
|
+
else this._permissions = { ...this._permissions, [role]: [...this._defaults.role_permissions[role]!] }
|
|
295
|
+
}
|
|
296
|
+
|
|
241
297
|
/**
|
|
242
298
|
* Persist current configuration to source
|
|
243
299
|
*/
|
|
@@ -251,6 +307,7 @@ export class PersistableRoleProvider extends RoleProvider {
|
|
|
251
307
|
role_hierarchy: this._hierarchy,
|
|
252
308
|
role_permissions: this._permissions,
|
|
253
309
|
role_labels: this._labels,
|
|
310
|
+
...(this._trackDefaults ? { defaults_snapshot: cloneGrants(this._defaults.role_permissions) } : {}),
|
|
254
311
|
}
|
|
255
312
|
|
|
256
313
|
try {
|
|
@@ -571,6 +628,7 @@ export function createLocalStorageRolesProvider(
|
|
|
571
628
|
fixed: options.fixed,
|
|
572
629
|
defaults: options.defaults,
|
|
573
630
|
mergeStrategy: options.mergeStrategy,
|
|
631
|
+
trackDefaults: true, // a module's later grants reach roles saved here (#4694)
|
|
574
632
|
autoLoad: false, // We load synchronously below
|
|
575
633
|
})
|
|
576
634
|
|
|
@@ -58,6 +58,12 @@ export class StaticRoleProvider extends RoleProvider {
|
|
|
58
58
|
this._labels = config.role_labels || {}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** Default grants brought by a module (`ctx.grant`, #4694) */
|
|
62
|
+
addDefaultGrants(role: string, permissions: string[]): void {
|
|
63
|
+
const current = this._permissions[role] ?? []
|
|
64
|
+
this._permissions = { ...this._permissions, [role]: [...current, ...permissions.filter((p) => !current.includes(p))] }
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
/**
|
|
62
68
|
* Get permissions for a role
|
|
63
69
|
*/
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waiting states (#4665): QdPending, a badge that waits for its value, and
|
|
3
|
+
* QdPendingZone, an area that waits for its data. Neutral colours: a wait is
|
|
4
|
+
* not a warning.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
@use 'variables' as *;
|
|
8
|
+
|
|
9
|
+
.qd-pending.p-tag {
|
|
10
|
+
gap: 0.375rem;
|
|
11
|
+
font-weight: 500;
|
|
12
|
+
color: var(--p-text-muted-color);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.qd-pending--failed.p-tag {
|
|
16
|
+
opacity: 0.8;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.qd-pending-zone {
|
|
20
|
+
position: relative;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.qd-pending-zone-content {
|
|
24
|
+
transition: opacity 0.2s;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.qd-pending-zone--reloading > .qd-pending-zone-content {
|
|
28
|
+
opacity: 0.55;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.qd-pending-zone-corner {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 0.375rem;
|
|
34
|
+
right: 0.375rem;
|
|
35
|
+
color: var(--p-text-muted-color);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.qd-pending-zone-skeleton {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
gap: 0.625rem;
|
|
42
|
+
padding: 0.25rem 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.qd-pending-zone-line {
|
|
46
|
+
display: block;
|
|
47
|
+
height: 0.875rem;
|
|
48
|
+
border-radius: $radius-sm;
|
|
49
|
+
background: linear-gradient(
|
|
50
|
+
90deg,
|
|
51
|
+
var(--p-content-border-color) 0%,
|
|
52
|
+
var(--p-content-hover-background) 50%,
|
|
53
|
+
var(--p-content-border-color) 100%
|
|
54
|
+
);
|
|
55
|
+
background-size: 200% 100%;
|
|
56
|
+
animation: qd-pending-shimmer 1.4s ease-in-out infinite;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@keyframes qd-pending-shimmer {
|
|
60
|
+
from { background-position: 100% 0; }
|
|
61
|
+
to { background-position: -100% 0; }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.qd-pending-zone-spinner {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
justify-content: center;
|
|
68
|
+
gap: 0.5rem;
|
|
69
|
+
padding: 1.5rem 0.5rem;
|
|
70
|
+
color: var(--p-text-muted-color);
|
|
71
|
+
font-size: $font-size-sm;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.qd-pending-zone-error,
|
|
75
|
+
.qd-pending-zone-stale {
|
|
76
|
+
display: flex;
|
|
77
|
+
flex-wrap: wrap;
|
|
78
|
+
align-items: center;
|
|
79
|
+
gap: 0.5rem;
|
|
80
|
+
color: var(--p-text-muted-color);
|
|
81
|
+
font-size: $font-size-sm;
|
|
82
|
+
overflow-wrap: anywhere;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.qd-pending-zone-error {
|
|
86
|
+
padding: 0.75rem;
|
|
87
|
+
border: 1px dashed var(--p-content-border-color);
|
|
88
|
+
border-radius: $radius-sm;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.qd-pending-zone-stale {
|
|
92
|
+
margin-top: 0.5rem;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A still spinner and a still skeleton: the label and the shape say it waits
|
|
96
|
+
@media (prefers-reduced-motion: reduce) {
|
|
97
|
+
.qd-pending-spinner {
|
|
98
|
+
animation: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.qd-pending-zone-line {
|
|
102
|
+
animation: none;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// "Unavailable", and Retry next to it (#4687)
|
|
107
|
+
.qd-pending-failed {
|
|
108
|
+
display: inline-flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
gap: 0.25rem;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.qd-pending-retry {
|
|
114
|
+
display: inline-flex;
|
|
115
|
+
padding: 0.25rem;
|
|
116
|
+
border: none;
|
|
117
|
+
border-radius: 50%;
|
|
118
|
+
background: none;
|
|
119
|
+
color: var(--p-text-muted-color);
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
|
|
122
|
+
&:hover {
|
|
123
|
+
background: var(--p-content-hover-background);
|
|
124
|
+
}
|
|
125
|
+
}
|