@quazardous/qdadm 2.50.1 → 2.51.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 +2 -1
- package/src/components/edit/FormActions.vue +33 -9
- package/src/components/edit/FormPage.vue +8 -0
- package/src/components/editors/JsonStructuredField.vue +36 -219
- package/src/components/editors/PermissionEditor.vue +62 -204
- package/src/components/editors/permissionSuggestions.ts +139 -0
- package/src/components/editors/structured/JsonRawFace.vue +37 -0
- package/src/components/editors/structured/StructuredField.vue +214 -0
- package/src/components/editors/structured/YamlRawFace.vue +70 -0
- package/src/components/editors/structured/faces.ts +35 -0
- package/src/components/editors/structured/registerJson.ts +5 -0
- package/src/components/editors/structured/registerYaml.ts +5 -0
- package/src/components/index.ts +8 -2
- package/src/composables/confirmDelete.ts +6 -3
- package/src/composables/useEntityItemFormPage.ts +15 -5
- package/src/composables/useEntityItemFormPage.types.ts +7 -1
- package/src/editors/index.ts +4 -14
- package/src/editors/json.ts +19 -0
- package/src/editors/yaml.ts +6 -1
- package/src/i18n/defaults/core.en.generated.ts +17 -0
- package/src/i18n/defaults/core.en.yml +17 -0
- package/src/i18n/defaults/core.fr.generated.ts +17 -0
- package/src/i18n/defaults/core.fr.yml +17 -0
- package/src/styles/_forms.scss +2 -1
- package/src/styles/_responsive.scss +2 -1
|
@@ -1,60 +1,26 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* JsonStructuredField -
|
|
3
|
+
* JsonStructuredField - StructuredField with a JSON raw face (#5333)
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* Uses a mini SelectButton to toggle between views.
|
|
5
|
+
* The structured face is the slot; a toggle opens the same value as JSON.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
7
|
+
* <JsonStructuredField v-model="myData">
|
|
8
|
+
* <MyStructuredEditor v-model="myData" />
|
|
9
|
+
* </JsonStructuredField>
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 2. With separate JSON binding (for complex computed mappings):
|
|
16
|
-
* <JsonStructuredField v-model="myData" :jsonValue="jsonComputed" @update:jsonValue="onJsonUpdate">
|
|
17
|
-
* <MyStructuredEditor v-model="myData" />
|
|
18
|
-
* </JsonStructuredField>
|
|
19
|
-
*
|
|
20
|
-
* 3. Controlled mode (parent manages viewMode):
|
|
21
|
-
* <JsonStructuredField v-model="myData" v-model:mode="viewMode">
|
|
22
|
-
* <MyStructuredEditor v-model="myData" />
|
|
23
|
-
* </JsonStructuredField>
|
|
24
|
-
*
|
|
25
|
-
* Props:
|
|
26
|
-
* - modelValue: The JSON object to edit (used for JSON view if jsonValue not provided)
|
|
27
|
-
* - jsonValue: Optional separate binding for JSON editor (for complex computed mappings)
|
|
28
|
-
* - mode: Optional v-model for view mode ('structured' or 'json')
|
|
29
|
-
* - label: Optional label for the field
|
|
30
|
-
* - jsonHeight: Height of JSON editor (default: 400px)
|
|
31
|
-
* - jsonMode: Mode for JSON editor - 'tree', 'text' or 'table' (default: 'text');
|
|
32
|
-
* string literals accepted so consumers don't need the vanilla-jsoneditor Mode enum (#1280)
|
|
33
|
-
* - defaultMode: Initial mode if not using v-model:mode (default: 'structured')
|
|
34
|
-
* - showToggle: Whether to show the toggle (default: true, useful to hide in nested usage)
|
|
35
|
-
* - guardInvalidJson: Block switching to structured view while JSON is invalid (default: true)
|
|
36
|
-
* - invalidJsonMessage: Error message shown when JSON is invalid (default: 'Invalid JSON — fix errors before switching views')
|
|
37
|
-
*
|
|
38
|
-
* Events:
|
|
39
|
-
* - update:modelValue, update:jsonValue, update:mode: standard v-model
|
|
40
|
-
* - json-error: emitted with true when JSON becomes invalid, false when valid again
|
|
11
|
+
* Its props are StructuredField's under their JSON names: jsonValue
|
|
12
|
+
* (rawValue), mode 'json' (raw), jsonHeight, jsonMode ('text' | 'tree' |
|
|
13
|
+
* 'table'), guardInvalidJson, invalidJsonMessage; `json-error` is `invalid`.
|
|
14
|
+
* For YAML, use StructuredField with format="yaml".
|
|
41
15
|
*/
|
|
42
|
-
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import QdMessage from '../base/QdMessage.vue'
|
|
46
|
-
import VanillaJsonEditor from './VanillaJsonEditor.vue'
|
|
16
|
+
import { computed } from 'vue'
|
|
17
|
+
import StructuredField from './structured/StructuredField.vue'
|
|
18
|
+
import './structured/registerJson'
|
|
47
19
|
import type { Mode } from 'vanilla-jsoneditor'
|
|
48
20
|
|
|
49
21
|
type JsonValue = Record<string, unknown> | unknown[] | string | null
|
|
50
22
|
type ViewMode = 'structured' | 'json'
|
|
51
23
|
|
|
52
|
-
interface ViewModeOption {
|
|
53
|
-
label: string
|
|
54
|
-
value: ViewMode
|
|
55
|
-
icon: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
24
|
interface Props {
|
|
59
25
|
modelValue?: JsonValue
|
|
60
26
|
jsonValue?: JsonValue | null
|
|
@@ -65,7 +31,7 @@ interface Props {
|
|
|
65
31
|
defaultMode?: ViewMode
|
|
66
32
|
showToggle?: boolean
|
|
67
33
|
guardInvalidJson?: boolean
|
|
68
|
-
invalidJsonMessage?: string
|
|
34
|
+
invalidJsonMessage?: string | null
|
|
69
35
|
}
|
|
70
36
|
|
|
71
37
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -78,7 +44,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
78
44
|
defaultMode: 'structured',
|
|
79
45
|
showToggle: true,
|
|
80
46
|
guardInvalidJson: true,
|
|
81
|
-
invalidJsonMessage:
|
|
47
|
+
invalidJsonMessage: null,
|
|
82
48
|
})
|
|
83
49
|
|
|
84
50
|
const emit = defineEmits<{
|
|
@@ -88,178 +54,29 @@ const emit = defineEmits<{
|
|
|
88
54
|
'json-error': [hasError: boolean]
|
|
89
55
|
}>()
|
|
90
56
|
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
// Invalid JSON state, tracked from VanillaJsonEditor error/update events
|
|
95
|
-
const hasJsonError = ref<boolean>(false)
|
|
96
|
-
|
|
97
|
-
// Computed view mode - use external if provided, else internal
|
|
98
|
-
const viewMode = computed<ViewMode>({
|
|
99
|
-
get: () => props.mode ?? internalMode.value,
|
|
100
|
-
set: (val: ViewMode) => {
|
|
101
|
-
// Guard: block json → structured while JSON is invalid
|
|
102
|
-
if (
|
|
103
|
-
props.guardInvalidJson &&
|
|
104
|
-
hasJsonError.value &&
|
|
105
|
-
(props.mode ?? internalMode.value) === 'json' &&
|
|
106
|
-
val === 'structured'
|
|
107
|
-
) {
|
|
108
|
-
return
|
|
109
|
-
}
|
|
110
|
-
if (props.mode !== null) {
|
|
111
|
-
emit('update:mode', val)
|
|
112
|
-
} else {
|
|
113
|
-
internalMode.value = val
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
const viewModeOptions: ViewModeOption[] = [
|
|
119
|
-
{ label: 'Structured', value: 'structured', icon: 'pi pi-list' },
|
|
120
|
-
{ label: 'JSON', value: 'json', icon: 'pi pi-code' }
|
|
121
|
-
]
|
|
122
|
-
|
|
123
|
-
// Computed JSON value - use separate jsonValue if provided, else modelValue
|
|
124
|
-
const effectiveJsonValue = computed<JsonValue>(() => {
|
|
125
|
-
return props.jsonValue !== null ? props.jsonValue : props.modelValue
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
// Handle JSON editor updates (fires only when JSON is valid)
|
|
129
|
-
function onJsonUpdate(newValue: JsonValue): void {
|
|
130
|
-
if (hasJsonError.value) {
|
|
131
|
-
hasJsonError.value = false
|
|
132
|
-
emit('json-error', false)
|
|
133
|
-
}
|
|
134
|
-
if (props.jsonValue !== null) {
|
|
135
|
-
// Using separate jsonValue binding
|
|
136
|
-
emit('update:jsonValue', newValue)
|
|
137
|
-
} else {
|
|
138
|
-
// Using modelValue for both
|
|
139
|
-
emit('update:modelValue', newValue)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Track invalid JSON state from the editor
|
|
144
|
-
function onJsonError(): void {
|
|
145
|
-
if (!hasJsonError.value) {
|
|
146
|
-
hasJsonError.value = true
|
|
147
|
-
emit('json-error', true)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Sync internal mode with prop if it changes
|
|
152
|
-
watch(() => props.mode, (newMode: ViewMode | null | undefined) => {
|
|
153
|
-
if (newMode !== null && newMode !== undefined) {
|
|
154
|
-
internalMode.value = newMode
|
|
155
|
-
}
|
|
156
|
-
})
|
|
57
|
+
const toRaw = (m: ViewMode | null) => (m === null ? null : m === 'json' ? 'raw' : 'structured')
|
|
58
|
+
const rawOptions = computed(() => ({ mode: props.jsonMode }))
|
|
157
59
|
</script>
|
|
158
60
|
|
|
159
61
|
<template>
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<!-- JSON View -->
|
|
181
|
-
<div v-if="viewMode === 'json'" class="json-view">
|
|
182
|
-
<QdMessage
|
|
183
|
-
v-if="guardInvalidJson && hasJsonError"
|
|
184
|
-
severity="error"
|
|
185
|
-
:closable="false"
|
|
186
|
-
class="json-error"
|
|
187
|
-
>
|
|
188
|
-
{{ invalidJsonMessage }}
|
|
189
|
-
</QdMessage>
|
|
190
|
-
<VanillaJsonEditor
|
|
191
|
-
:modelValue="effectiveJsonValue"
|
|
192
|
-
:mode="jsonMode"
|
|
193
|
-
:height="jsonHeight"
|
|
194
|
-
@update:modelValue="onJsonUpdate"
|
|
195
|
-
@error="onJsonError"
|
|
196
|
-
/>
|
|
197
|
-
</div>
|
|
198
|
-
|
|
199
|
-
<!-- Structured View (slot) -->
|
|
200
|
-
<div v-else class="structured-view">
|
|
201
|
-
<slot></slot>
|
|
202
|
-
</div>
|
|
203
|
-
</div>
|
|
62
|
+
<StructuredField
|
|
63
|
+
class="json-structured-field"
|
|
64
|
+
format="json"
|
|
65
|
+
:modelValue="modelValue"
|
|
66
|
+
:rawValue="jsonValue !== null ? jsonValue : undefined"
|
|
67
|
+
:mode="toRaw(mode)"
|
|
68
|
+
:defaultMode="toRaw(defaultMode)!"
|
|
69
|
+
:label="label"
|
|
70
|
+
:rawHeight="jsonHeight"
|
|
71
|
+
:rawOptions="rawOptions"
|
|
72
|
+
:showToggle="showToggle"
|
|
73
|
+
:guardInvalid="guardInvalidJson"
|
|
74
|
+
:invalidMessage="invalidJsonMessage"
|
|
75
|
+
@update:modelValue="emit('update:modelValue', $event as JsonValue)"
|
|
76
|
+
@update:rawValue="emit('update:jsonValue', $event as JsonValue)"
|
|
77
|
+
@update:mode="emit('update:mode', $event === 'raw' ? 'json' : 'structured')"
|
|
78
|
+
@invalid="emit('json-error', $event)"
|
|
79
|
+
>
|
|
80
|
+
<slot></slot>
|
|
81
|
+
</StructuredField>
|
|
204
82
|
</template>
|
|
205
|
-
|
|
206
|
-
<style scoped>
|
|
207
|
-
/*
|
|
208
|
-
* Only keep styles here that REQUIRE scoping (:deep, dynamic binding, component-specific overrides).
|
|
209
|
-
* Generic/reusable styles belong in src/styles/ partials (see _forms.scss, _cards.scss, etc.).
|
|
210
|
-
*/
|
|
211
|
-
.json-structured-field {
|
|
212
|
-
width: 100%;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
.field-header {
|
|
216
|
-
display: flex;
|
|
217
|
-
justify-content: space-between;
|
|
218
|
-
align-items: center;
|
|
219
|
-
margin-bottom: 0.75rem;
|
|
220
|
-
flex-wrap: wrap;
|
|
221
|
-
gap: 0.5rem;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.field-label {
|
|
225
|
-
font-weight: 600;
|
|
226
|
-
font-size: 0.95rem;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
.mode-toggle {
|
|
230
|
-
flex-shrink: 0;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/* Smaller toggle buttons */
|
|
234
|
-
.mode-toggle :deep(.p-button) {
|
|
235
|
-
padding: 0.35rem 0.6rem;
|
|
236
|
-
font-size: 0.8rem;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
.mode-toggle :deep(.p-button i) {
|
|
240
|
-
font-size: 0.75rem;
|
|
241
|
-
margin-right: 0.25rem;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.toggle-label {
|
|
245
|
-
display: none;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
@media (min-width: 640px) {
|
|
249
|
-
.toggle-label {
|
|
250
|
-
display: inline;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
.json-view {
|
|
255
|
-
margin-top: 0.25rem;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
.json-error {
|
|
259
|
-
margin-bottom: 0.5rem;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
.structured-view {
|
|
263
|
-
margin-top: 0.25rem;
|
|
264
|
-
}
|
|
265
|
-
</style>
|
|
@@ -10,30 +10,27 @@
|
|
|
10
10
|
* Permission format: namespace:action
|
|
11
11
|
* - entity:books:read (namespace=entity:books, action=read)
|
|
12
12
|
* - auth:impersonate (namespace=auth, action=impersonate)
|
|
13
|
+
*
|
|
14
|
+
* The permissions to suggest: a `permissionRegistry`, or a plain list of keys
|
|
15
|
+
* as `permissions` (#5333). Wildcards follow PermissionMatcher (`*` one
|
|
16
|
+
* segment, `**` any number): `**`, `**:read`, `logs:**`, `logs:*:read`…
|
|
17
|
+
*
|
|
18
|
+
* For a raw text face of the same list, put it in a StructuredField:
|
|
19
|
+
* <StructuredField v-model="scopes" format="yaml"><PermissionEditor v-model="scopes" :permissions="all" /></StructuredField>
|
|
13
20
|
*/
|
|
14
21
|
|
|
15
22
|
import { ref, computed, nextTick, type ComponentPublicInstance } from 'vue'
|
|
16
23
|
import AutoComplete from 'primevue/autocomplete'
|
|
17
24
|
import Chip from 'primevue/chip'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
getAll(): Permission[]
|
|
28
|
-
get(key: string): Permission | undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface Suggestion {
|
|
32
|
-
label: string
|
|
33
|
-
value: string
|
|
34
|
-
type: 'namespace' | 'permission' | 'wildcard' | 'wildcard-action'
|
|
35
|
-
description: string
|
|
36
|
-
}
|
|
25
|
+
import { useI18n } from '../../i18n/useI18n'
|
|
26
|
+
import {
|
|
27
|
+
permissionRegistryFromList,
|
|
28
|
+
suggestPermissions,
|
|
29
|
+
type PermissionRegistry,
|
|
30
|
+
type Permission,
|
|
31
|
+
type Suggestion,
|
|
32
|
+
type SuggestionTexts,
|
|
33
|
+
} from './permissionSuggestions'
|
|
37
34
|
|
|
38
35
|
interface PermissionInfo {
|
|
39
36
|
namespace: string
|
|
@@ -45,216 +42,77 @@ interface PermissionInfo {
|
|
|
45
42
|
interface Props {
|
|
46
43
|
modelValue?: string[]
|
|
47
44
|
disabled?: boolean
|
|
45
|
+
/** The permissions to suggest, as a registry… */
|
|
48
46
|
permissionRegistry?: PermissionRegistry | null
|
|
49
|
-
|
|
47
|
+
/** …or as a plain list of keys (#5333) */
|
|
48
|
+
permissions?: string[] | null
|
|
49
|
+
/** Default from the catalogue */
|
|
50
|
+
placeholder?: string | null
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const props = withDefaults(defineProps<Props>(), {
|
|
53
54
|
modelValue: () => [],
|
|
54
55
|
disabled: false,
|
|
55
|
-
|
|
56
|
+
permissionRegistry: null,
|
|
57
|
+
permissions: null,
|
|
58
|
+
placeholder: null,
|
|
56
59
|
})
|
|
57
60
|
|
|
58
61
|
const emit = defineEmits<{
|
|
59
62
|
'update:modelValue': [value: string[]]
|
|
60
63
|
}>()
|
|
61
64
|
|
|
65
|
+
const { tOr } = useI18n()
|
|
66
|
+
|
|
62
67
|
// Current input value
|
|
63
68
|
const inputValue = ref<string>('')
|
|
64
69
|
const suggestions = ref<Suggestion[]>([])
|
|
65
70
|
const autocompleteRef = ref<ComponentPublicInstance | null>(null)
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
const perms = props.permissionRegistry.getAll()
|
|
74
|
-
return perms
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
// Check if registry is available
|
|
78
|
-
const hasRegistry = computed<boolean>(() => {
|
|
79
|
-
return !!props.permissionRegistry && allPermissions.value.length > 0
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// Get all permission keys
|
|
83
|
-
const allPermissionKeys = computed<string[]>(() => {
|
|
84
|
-
return allPermissions.value.map(p => p.key)
|
|
72
|
+
/** The registry given, or one made from the plain list; labels `permissions.<key>` from the catalogue */
|
|
73
|
+
const registry = computed<PermissionRegistry | null>(() => {
|
|
74
|
+
if (props.permissionRegistry) return props.permissionRegistry
|
|
75
|
+
if (props.permissions) return permissionRegistryFromList(props.permissions, (key) => tOr(`permissions.${key}`, key))
|
|
76
|
+
return null
|
|
85
77
|
})
|
|
86
78
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let current = ''
|
|
94
|
-
for (let i = 0; i < parts.length; i++) {
|
|
95
|
-
const part = parts[i]
|
|
96
|
-
if (part !== undefined) {
|
|
97
|
-
current = current ? current + ':' + part : part
|
|
98
|
-
prefixes.add(current)
|
|
99
|
-
}
|
|
79
|
+
let warnedNoSource = false
|
|
80
|
+
const allPermissions = computed<Permission[]>(() => {
|
|
81
|
+
if (!registry.value) {
|
|
82
|
+
if (!warnedNoSource) {
|
|
83
|
+
warnedNoSource = true
|
|
84
|
+
console.warn('[PermissionEditor] No permissionRegistry or permissions given: nothing to suggest')
|
|
100
85
|
}
|
|
86
|
+
return []
|
|
101
87
|
}
|
|
102
|
-
return
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
// Get unique actions across all namespaces
|
|
106
|
-
const allActions = computed<string[]>(() => {
|
|
107
|
-
const actions = new Set<string>()
|
|
108
|
-
for (const perm of allPermissions.value) {
|
|
109
|
-
actions.add(perm.action)
|
|
110
|
-
}
|
|
111
|
-
return [...actions].sort()
|
|
88
|
+
return registry.value.getAll()
|
|
112
89
|
})
|
|
113
90
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
suggestions.value = [{
|
|
128
|
-
label: '**',
|
|
129
|
-
value: '**',
|
|
130
|
-
type: 'wildcard',
|
|
131
|
-
description: 'All permissions (super admin)'
|
|
132
|
-
}]
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Handle wildcard patterns
|
|
137
|
-
if (query.includes('*')) {
|
|
138
|
-
suggestions.value = generateWildcardSuggestions(query)
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Check if query ends with ':' - user wants next level suggestions
|
|
143
|
-
const endsWithColon = query.endsWith(':')
|
|
144
|
-
|
|
145
|
-
const results: Suggestion[] = []
|
|
146
|
-
|
|
147
|
-
// Add wildcard option if at start or after colon
|
|
148
|
-
if (query === '' || endsWithColon) {
|
|
149
|
-
results.push({
|
|
150
|
-
label: query + '*:',
|
|
151
|
-
value: query + '*:',
|
|
152
|
-
type: 'namespace',
|
|
153
|
-
description: 'Wildcard (all at this level)'
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Find matching prefixes that are NEXT level completions
|
|
158
|
-
for (const prefix of allPrefixes.value) {
|
|
159
|
-
const prefixLower = prefix.toLowerCase()
|
|
160
|
-
|
|
161
|
-
if (endsWithColon) {
|
|
162
|
-
// After "entity:", suggest "entity:books", "entity:users", etc.
|
|
163
|
-
if (prefixLower.startsWith(queryLower) && prefix !== query.slice(0, -1)) {
|
|
164
|
-
const isComplete = allPermissionKeys.value.includes(prefix)
|
|
165
|
-
results.push({
|
|
166
|
-
label: isComplete ? prefix : prefix + ':',
|
|
167
|
-
value: isComplete ? prefix : prefix + ':',
|
|
168
|
-
type: isComplete ? 'permission' : 'namespace',
|
|
169
|
-
description: isComplete ? getPermissionLabel(prefix) : `${countChildren(prefix)} sub-items`
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
// Partial match: "ent" matches "entity", "entity:books:re" matches "entity:books:read"
|
|
174
|
-
if (prefixLower.startsWith(queryLower) || (query === '' && true)) {
|
|
175
|
-
// Only suggest if it's a progression from current input
|
|
176
|
-
if (prefix.toLowerCase() !== queryLower) {
|
|
177
|
-
const isComplete = allPermissionKeys.value.includes(prefix)
|
|
178
|
-
// Find the next colon boundary for namespace suggestions
|
|
179
|
-
const nextColonIdx = prefix.indexOf(':', query.length)
|
|
180
|
-
const suggestionValue = nextColonIdx > -1 ? prefix.slice(0, nextColonIdx + 1) : (isComplete ? prefix : prefix + ':')
|
|
181
|
-
|
|
182
|
-
// Avoid duplicates
|
|
183
|
-
if (!results.some(r => r.value === suggestionValue)) {
|
|
184
|
-
results.push({
|
|
185
|
-
label: suggestionValue,
|
|
186
|
-
value: suggestionValue,
|
|
187
|
-
type: suggestionValue.endsWith(':') ? 'namespace' : 'permission',
|
|
188
|
-
description: isComplete && !suggestionValue.endsWith(':') ? getPermissionLabel(prefix) : `${countChildren(suggestionValue.replace(/:$/, ''))} sub-items`
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Sort: namespaces first, then permissions
|
|
197
|
-
results.sort((a, b) => {
|
|
198
|
-
if (a.type === 'namespace' && b.type !== 'namespace') return -1
|
|
199
|
-
if (a.type !== 'namespace' && b.type === 'namespace') return 1
|
|
200
|
-
return a.label.localeCompare(b.label)
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
suggestions.value = results.slice(0, 20) // Limit to 20 suggestions
|
|
91
|
+
const hasRegistry = computed<boolean>(() => allPermissions.value.length > 0)
|
|
92
|
+
const allPermissionKeys = computed<string[]>(() => allPermissions.value.map((p) => p.key))
|
|
93
|
+
const placeholderText = computed(() => props.placeholder ?? tOr('core.permissionEditor.placeholder', 'Type a permission…'))
|
|
94
|
+
|
|
95
|
+
const texts: SuggestionTexts = {
|
|
96
|
+
all: () => tOr('core.permissionEditor.all', 'All permissions'),
|
|
97
|
+
actionEverywhere: (action) => tOr('core.permissionEditor.actionEverywhere', '{action}, everywhere', { action }),
|
|
98
|
+
anActionEverywhere: () => tOr('core.permissionEditor.anActionEverywhere', 'One action, everywhere'),
|
|
99
|
+
allUnder: (prefix) => tOr('core.permissionEditor.allUnder', 'Everything under {prefix}', { prefix }),
|
|
100
|
+
directUnder: (prefix) => tOr('core.permissionEditor.directUnder', 'Every {prefix} permission, one level', { prefix }),
|
|
101
|
+
actionUnder: (action, prefix) => tOr('core.permissionEditor.actionUnder', '{action} under {prefix}', { action, prefix }),
|
|
102
|
+
subItems: (count) => tOr('core.permissionEditor.subItems', '{count} sub-item | {count} sub-items', { count }),
|
|
103
|
+
label: (key) => getPermissionLabel(key),
|
|
204
104
|
}
|
|
205
105
|
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
function generateWildcardSuggestions(query: string): Suggestion[] {
|
|
210
|
-
const results: Suggestion[] = []
|
|
211
|
-
|
|
212
|
-
// *: pattern - suggest actions
|
|
213
|
-
if (query === '*:' || query.startsWith('*:')) {
|
|
214
|
-
const actionPart = query.slice(2).toLowerCase()
|
|
215
|
-
|
|
216
|
-
results.push({
|
|
217
|
-
label: '*:*',
|
|
218
|
-
value: '*:*',
|
|
219
|
-
type: 'wildcard',
|
|
220
|
-
description: 'All permissions'
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
for (const action of allActions.value) {
|
|
224
|
-
if (actionPart === '' || action.toLowerCase().startsWith(actionPart)) {
|
|
225
|
-
results.push({
|
|
226
|
-
label: '*:' + action,
|
|
227
|
-
value: '*:' + action,
|
|
228
|
-
type: 'wildcard-action',
|
|
229
|
-
description: `All ${action} permissions`
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
} else if (query === '*') {
|
|
234
|
-
// Just * - suggest *: to continue
|
|
235
|
-
results.push({
|
|
236
|
-
label: '*:',
|
|
237
|
-
value: '*:',
|
|
238
|
-
type: 'namespace',
|
|
239
|
-
description: 'All namespaces (wildcard)'
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return results
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Count children of a prefix
|
|
248
|
-
*/
|
|
249
|
-
function countChildren(prefix: string): number {
|
|
250
|
-
return allPrefixes.value.filter(p => p.startsWith(prefix + ':') || p === prefix).length
|
|
106
|
+
/** Suggestions for the current input: next segments and the wildcards that make sense */
|
|
107
|
+
function searchSuggestions(event: { query?: string }): void {
|
|
108
|
+
suggestions.value = suggestPermissions(event.query ?? '', allPermissionKeys.value, texts)
|
|
251
109
|
}
|
|
252
110
|
|
|
253
111
|
/**
|
|
254
112
|
* Get permission label
|
|
255
113
|
*/
|
|
256
114
|
function getPermissionLabel(key: string): string {
|
|
257
|
-
const perm =
|
|
115
|
+
const perm = registry.value?.get(key)
|
|
258
116
|
return perm?.label || key
|
|
259
117
|
}
|
|
260
118
|
|
|
@@ -344,7 +202,7 @@ function getPermissionInfo(permKey: string): PermissionInfo {
|
|
|
344
202
|
return {
|
|
345
203
|
namespace: '',
|
|
346
204
|
action: '**',
|
|
347
|
-
label: 'All permissions',
|
|
205
|
+
label: tOr('core.permissionEditor.all', 'All permissions'),
|
|
348
206
|
isWildcard: true
|
|
349
207
|
}
|
|
350
208
|
}
|
|
@@ -362,7 +220,7 @@ function getPermissionInfo(permKey: string): PermissionInfo {
|
|
|
362
220
|
}
|
|
363
221
|
}
|
|
364
222
|
|
|
365
|
-
const perm =
|
|
223
|
+
const perm = registry.value?.get(permKey)
|
|
366
224
|
if (perm) {
|
|
367
225
|
return {
|
|
368
226
|
namespace: perm.namespace,
|
|
@@ -426,7 +284,7 @@ function getSuggestionClass(item: Suggestion): string {
|
|
|
426
284
|
:suggestions="suggestions"
|
|
427
285
|
optionLabel="label"
|
|
428
286
|
:disabled="disabled"
|
|
429
|
-
:placeholder="
|
|
287
|
+
:placeholder="placeholderText"
|
|
430
288
|
:minLength="0"
|
|
431
289
|
completeOnFocus
|
|
432
290
|
@complete="searchSuggestions"
|
|
@@ -444,18 +302,18 @@ function getSuggestionClass(item: Suggestion): string {
|
|
|
444
302
|
</template>
|
|
445
303
|
<template #empty>
|
|
446
304
|
<div class="suggestion-empty">
|
|
447
|
-
No matching
|
|
305
|
+
{{ tOr('core.permissionEditor.noMatch', 'No matching permission') }}
|
|
448
306
|
</div>
|
|
449
307
|
</template>
|
|
450
308
|
</AutoComplete>
|
|
451
309
|
<small class="text-color-secondary mt-1 block">
|
|
452
|
-
Type permission
|
|
310
|
+
{{ tOr('core.permissionEditor.help', 'Type a permission (e.g. "entity:books:read"), Tab to complete') }}
|
|
453
311
|
</small>
|
|
454
312
|
</template>
|
|
455
313
|
<template v-else>
|
|
456
314
|
<div class="no-registry">
|
|
457
315
|
<i class="pi pi-info-circle"></i>
|
|
458
|
-
<span>No
|
|
316
|
+
<span>{{ tOr('core.permissionEditor.noPermissions', 'No permission to suggest') }}</span>
|
|
459
317
|
</div>
|
|
460
318
|
</template>
|
|
461
319
|
</div>
|