|
|
@@ -1,6 +1,5 @@
|
|
|
import { ALL_SIGN, type Scope } from '@growi/core/dist/interfaces';
|
|
|
|
|
|
-
|
|
|
// Data structure for the final merged scopes
|
|
|
interface ScopeMap {
|
|
|
[key: string]: Scope | ScopeMap;
|
|
|
@@ -9,17 +8,17 @@ interface ScopeMap {
|
|
|
// Input object with arbitrary action keys (e.g., READ, WRITE)
|
|
|
type ScopesInput = Record<string, any>;
|
|
|
|
|
|
-
|
|
|
function parseSubScope(
|
|
|
- parentKey: string,
|
|
|
- subObjForActions: Record<string, any>,
|
|
|
- actions: string[],
|
|
|
+ parentKey: string,
|
|
|
+ subObjForActions: Record<string, any>,
|
|
|
+ actions: string[],
|
|
|
): ScopeMap {
|
|
|
const result: ScopeMap = {};
|
|
|
|
|
|
for (const action of actions) {
|
|
|
if (typeof subObjForActions[action] === 'string') {
|
|
|
- result[`${action.toLowerCase()}:${parentKey.toLowerCase()}`] = subObjForActions[action];
|
|
|
+ result[`${action.toLowerCase()}:${parentKey.toLowerCase()}`] =
|
|
|
+ subObjForActions[action];
|
|
|
subObjForActions[action] = undefined;
|
|
|
}
|
|
|
}
|
|
|
@@ -28,7 +27,7 @@ function parseSubScope(
|
|
|
for (const action of actions) {
|
|
|
const obj = subObjForActions[action];
|
|
|
if (obj && typeof obj === 'object') {
|
|
|
- Object.keys(obj).forEach(k => childKeys.add(k));
|
|
|
+ Object.keys(obj).forEach((k) => childKeys.add(k));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -37,7 +36,8 @@ function parseSubScope(
|
|
|
for (const action of actions) {
|
|
|
const val = subObjForActions[action]?.[ck];
|
|
|
if (typeof val === 'string') {
|
|
|
- result[`${action.toLowerCase()}:${parentKey.toLowerCase()}:all`] = val as Scope;
|
|
|
+ result[`${action.toLowerCase()}:${parentKey.toLowerCase()}:all`] =
|
|
|
+ val as Scope;
|
|
|
}
|
|
|
}
|
|
|
continue;
|
|
|
@@ -55,13 +55,19 @@ function parseSubScope(
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-export function parseScopes({ scopes, isAdmin = false }: { scopes: ScopesInput ; isAdmin?: boolean }): ScopeMap {
|
|
|
+export function parseScopes({
|
|
|
+ scopes,
|
|
|
+ isAdmin = false,
|
|
|
+}: {
|
|
|
+ scopes: ScopesInput;
|
|
|
+ isAdmin?: boolean;
|
|
|
+}): ScopeMap {
|
|
|
const actions = Object.keys(scopes);
|
|
|
const topKeys = new Set<string>();
|
|
|
|
|
|
// Collect all top-level keys (e.g., ALL, ADMIN, USER) across all actions
|
|
|
for (const action of actions) {
|
|
|
- Object.keys(scopes[action] || {}).forEach(k => topKeys.add(k));
|
|
|
+ Object.keys(scopes[action] || {}).forEach((k) => topKeys.add(k));
|
|
|
}
|
|
|
|
|
|
const result: ScopeMap = {};
|
|
|
@@ -81,8 +87,7 @@ export function parseScopes({ scopes, isAdmin = false }: { scopes: ScopesInput ;
|
|
|
}
|
|
|
}
|
|
|
result.ALL = allObj;
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
const subObjForActions: Record<string, any> = {};
|
|
|
for (const action of actions) {
|
|
|
subObjForActions[action] = scopes[action]?.[key];
|
|
|
@@ -97,10 +102,12 @@ export function parseScopes({ scopes, isAdmin = false }: { scopes: ScopesInput ;
|
|
|
/**
|
|
|
* Determines which scopes should be disabled based on wildcard selections
|
|
|
*/
|
|
|
-export function getDisabledScopes(selectedScopes: Scope[], availableScopes: string[]): Set<Scope> {
|
|
|
+export function getDisabledScopes(
|
|
|
+ selectedScopes: Scope[],
|
|
|
+ availableScopes: string[],
|
|
|
+): Set<Scope> {
|
|
|
const disabledSet = new Set<Scope>();
|
|
|
|
|
|
-
|
|
|
// If no selected scopes, return empty set
|
|
|
if (!selectedScopes || selectedScopes.length === 0) {
|
|
|
return disabledSet;
|
|
|
@@ -133,8 +140,7 @@ export function extractScopes(obj: Record<string, any>): string[] {
|
|
|
Object.values(obj).forEach((value) => {
|
|
|
if (typeof value === 'string') {
|
|
|
result.push(value);
|
|
|
- }
|
|
|
- else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
|
+ } else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
|
result = result.concat(extractScopes(value));
|
|
|
}
|
|
|
});
|