From 3535a8d5595fc928011d1d8e1b650d5ad3c92c13 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 18 Jan 2024 14:44:02 +0800 Subject: [PATCH 1/2] refactor: acl support namespace --- packages/core/client/src/acl/ACLProvider.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx index c8f7b69df6..5d8052e4b1 100644 --- a/packages/core/client/src/acl/ACLProvider.tsx +++ b/packages/core/client/src/acl/ACLProvider.tsx @@ -2,6 +2,7 @@ import { Field } from '@formily/core'; import { Schema, useField, useFieldSchema } from '@formily/react'; import React, { createContext, useContext, useEffect } from 'react'; import { Navigate } from 'react-router-dom'; +import { omit } from 'lodash'; import { useAPIClient, useRequest } from '../api-client'; import { useAppSpin } from '../application/hooks/useAppSpin'; import { useBlockRequestContext } from '../block-provider/BlockProvider'; @@ -10,6 +11,7 @@ import { useResourceActionContext } from '../collection-manager/ResourceActionPr import { useRecord } from '../record-provider'; import { SchemaComponentOptions, useDesignable } from '../schema-component'; import { useApp } from '../application'; +import { useCollectionNamespace } from '../block-provider'; export const ACLContext = createContext({}); @@ -91,7 +93,9 @@ export const ACLActionParamsContext = createContext({}); export const useACLRolesCheck = () => { const ctx = useContext(ACLContext); - const data = ctx?.data?.data; + const ns = useCollectionNamespace(); + const { dataSources: dataSourcesAcl } = ctx.data.meta; + const data = { ...ctx?.data?.data, ...omit(dataSourcesAcl[ns], 'snippets') }; const getActionAlias = (actionPath: string) => { const actionName = actionPath.split(':').pop(); return data?.actionAlias?.[actionName] || actionName; From ccee2df920a65890249683bfcea09ff86e0c0ac2 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 18 Jan 2024 14:44:58 +0800 Subject: [PATCH 2/2] refactor: acl support namespace --- packages/core/client/src/acl/ACLProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx index 5d8052e4b1..a1699e6908 100644 --- a/packages/core/client/src/acl/ACLProvider.tsx +++ b/packages/core/client/src/acl/ACLProvider.tsx @@ -95,7 +95,7 @@ export const useACLRolesCheck = () => { const ctx = useContext(ACLContext); const ns = useCollectionNamespace(); const { dataSources: dataSourcesAcl } = ctx.data.meta; - const data = { ...ctx?.data?.data, ...omit(dataSourcesAcl[ns], 'snippets') }; + const data = { ...ctx?.data?.data, ...omit(dataSourcesAcl?.[ns], 'snippets') }; const getActionAlias = (actionPath: string) => { const actionName = actionPath.split(':').pop(); return data?.actionAlias?.[actionName] || actionName;