@isoftdata/svelte-user-configuration 2.2.2 → 2.3.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.
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
interface Props extends HTMLDivAttributes {
|
|
38
38
|
permissions: Array<Permission>
|
|
39
39
|
siteLabel?: SiteLabel
|
|
40
|
+
enableSiteScope?: boolean
|
|
40
41
|
permissionValueChange?:
|
|
41
42
|
| ((change: { value: PermissionValue; permissionIds: Array<number> }) => void | Promise<void>)
|
|
42
43
|
| undefined
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
let {
|
|
51
52
|
permissions,
|
|
52
53
|
siteLabel = 'Site',
|
|
54
|
+
enableSiteScope = true,
|
|
53
55
|
permissionValueChange = undefined,
|
|
54
56
|
icon = 'user-lock',
|
|
55
57
|
cardHeaderTitle = translate('common:permissions', 'Permissions'),
|
|
@@ -63,16 +65,6 @@
|
|
|
63
65
|
let selectedPermissionValue: string | null = $state(null)
|
|
64
66
|
|
|
65
67
|
const permissionColumns: ComputedPermissionColumns = getColumns(groupPermissionValueMap)
|
|
66
|
-
const permissionValueList: Record<Scope, { label: string; value: Scope; color: ButtonColors }> = {
|
|
67
|
-
NONE: { label: translate('common:permissionLevel.none', 'None'), value: 'NONE', color: 'danger' },
|
|
68
|
-
SITE: {
|
|
69
|
-
label: translate(`common:permissionLevel.${siteLabel.toLowerCase()}`, siteLabel),
|
|
70
|
-
value: 'SITE',
|
|
71
|
-
color: 'primary',
|
|
72
|
-
},
|
|
73
|
-
GLOBAL: { label: translate('common:permissionLevel.global', 'Global'), value: 'GLOBAL', color: 'success' },
|
|
74
|
-
}
|
|
75
|
-
const permissionValues = Object.values(permissionValueList)
|
|
76
68
|
|
|
77
69
|
function getColumns(groupPermissionValueMap: PermissionValueMap | undefined): ComputedPermissionColumns {
|
|
78
70
|
let columns: ComputedPermissionColumns = [
|
|
@@ -157,9 +149,37 @@
|
|
|
157
149
|
})
|
|
158
150
|
}
|
|
159
151
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
const permissionValueList: Record<Scope, { label: string; value: Scope; color: ButtonColors }> = $derived({
|
|
153
|
+
NONE: {
|
|
154
|
+
label: enableSiteScope ? translate('common:permissionLevel.none', 'None') : translate('common:off', 'Off'),
|
|
155
|
+
value: 'NONE',
|
|
156
|
+
color: 'danger',
|
|
157
|
+
},
|
|
158
|
+
SITE: {
|
|
159
|
+
label: translate(`common:permissionLevel.${siteLabel.toLowerCase()}`, siteLabel),
|
|
160
|
+
value: 'SITE',
|
|
161
|
+
color: 'primary',
|
|
162
|
+
},
|
|
163
|
+
GLOBAL: {
|
|
164
|
+
label: enableSiteScope ? translate('common:permissionLevel.global', 'Global') : translate('common:on', 'On'),
|
|
165
|
+
value: 'GLOBAL',
|
|
166
|
+
color: 'success',
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
const permissionValues = $derived(
|
|
170
|
+
Object.values(permissionValueList).filter(permissionValue => enableSiteScope || permissionValue.value !== 'SITE'),
|
|
171
|
+
)
|
|
172
|
+
const computedPermissions = $derived(getComputedPermissions(permissions, permissionValueMap, groupPermissionValueMap))
|
|
173
|
+
$effect(() => {
|
|
174
|
+
if (
|
|
175
|
+
!enableSiteScope &&
|
|
176
|
+
computedPermissions.some(permission => [permission.value, permission.groupValue].includes('SITE'))
|
|
177
|
+
) {
|
|
178
|
+
console.warn(
|
|
179
|
+
'PermissionList: Permissions with site scope are not supported when `enableSiteScope` is false. Please ensure you want to disable site scope, or update/remove these permissions.',
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
})
|
|
163
183
|
</script>
|
|
164
184
|
|
|
165
185
|
<div
|
|
@@ -254,7 +274,9 @@
|
|
|
254
274
|
}}
|
|
255
275
|
>
|
|
256
276
|
{#each Object.values(permissionValueList) as permission}
|
|
257
|
-
|
|
277
|
+
{#if enableSiteScope || permission.value !== 'SITE'}
|
|
278
|
+
<option value={permission.value}>{permission.label}</option>
|
|
279
|
+
{/if}
|
|
258
280
|
{/each}
|
|
259
281
|
</Select>
|
|
260
282
|
<Button
|
|
@@ -8,6 +8,7 @@ declare const PermissionList: import("svelte").Component<HTMLDivAttributes & {
|
|
|
8
8
|
codeName: string;
|
|
9
9
|
}>;
|
|
10
10
|
siteLabel?: SiteLabel;
|
|
11
|
+
enableSiteScope?: boolean;
|
|
11
12
|
permissionValueChange?: ((change: {
|
|
12
13
|
value: "NONE" | "SITE" | "GLOBAL";
|
|
13
14
|
permissionIds: Array<number>;
|