From 9ec2b50990b3ebd72dbf69011e6cfea3bf92a1b9 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Sat, 4 Nov 2023 08:29:59 +0800 Subject: [PATCH] fix: import action should not visible when view collection not editable (#2957) * fix: import action should not visible when view collection not editable * refactor: action in view collection block --- packages/core/client/src/acl/ACLProvider.tsx | 9 +++++++++ .../buttons/GridCardActionInitializers.tsx | 3 ++- .../buttons/ListActionInitializers.tsx | 3 ++- .../src/client/ImportInitializerProvider.tsx | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx index 2baf50e38..64f2318f8 100644 --- a/packages/core/client/src/acl/ACLProvider.tsx +++ b/packages/core/client/src/acl/ACLProvider.tsx @@ -212,11 +212,13 @@ export const useRecordPkValue = () => { }; export const ACLActionProvider = (props) => { + const { template, writableView } = useCollection(); const recordPkValue = useRecordPkValue(); const resource = useResourceName(); const { parseAction } = useACLRoleContext(); const schema = useFieldSchema(); let actionPath = schema['x-acl-action']; + const editablePath = ['create', 'update', 'destroy', 'importXlsx']; if (!actionPath && resource && schema['x-action']) { actionPath = `${resource}:${schema['x-action']}`; } @@ -230,6 +232,13 @@ export const ACLActionProvider = (props) => { if (!params) { return null; } + //视图表无编辑权限时不显示 + if (editablePath.includes(actionPath) || editablePath.includes(actionPath?.split(':')[1])) { + if (template !== 'view' || writableView) { + return {props.children}; + } + return null; + } return {props.children}; }; diff --git a/packages/core/client/src/schema-initializer/buttons/GridCardActionInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/GridCardActionInitializers.tsx index 701b2f1df..955d24f64 100644 --- a/packages/core/client/src/schema-initializer/buttons/GridCardActionInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/GridCardActionInitializers.tsx @@ -50,6 +50,7 @@ export const GridCardActionInitializers = { component: 'ImportActionInitializer', schema: { 'x-align': 'right', + 'x-acl-action': 'importXlsx', 'x-decorator': 'ACLActionProvider', 'x-acl-action-props': { skipScopeCheck: true, @@ -57,7 +58,7 @@ export const GridCardActionInitializers = { }, visible: function useVisible() { const collection = useCollection(); - return collection.template !== 'sql'; + return (collection.template !== 'view' || collection?.writableView) && collection.template !== 'sql'; }, }, { diff --git a/packages/core/client/src/schema-initializer/buttons/ListActionInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/ListActionInitializers.tsx index 4be57a1b9..24d3071dc 100644 --- a/packages/core/client/src/schema-initializer/buttons/ListActionInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/ListActionInitializers.tsx @@ -54,6 +54,7 @@ export const ListActionInitializers = { component: 'ImportActionInitializer', schema: { 'x-align': 'right', + 'x-acl-action': 'importXlsx', 'x-decorator': 'ACLActionProvider', 'x-acl-action-props': { skipScopeCheck: true, @@ -61,7 +62,7 @@ export const ListActionInitializers = { }, visible: function useVisible() { const collection = useCollection(); - return collection.template !== 'sql'; + return (collection.template !== 'view' || collection?.writableView) && collection.template !== 'sql'; }, }, { diff --git a/packages/plugins/@nocobase/plugin-import/src/client/ImportInitializerProvider.tsx b/packages/plugins/@nocobase/plugin-import/src/client/ImportInitializerProvider.tsx index a2433711e..ea50357e3 100644 --- a/packages/plugins/@nocobase/plugin-import/src/client/ImportInitializerProvider.tsx +++ b/packages/plugins/@nocobase/plugin-import/src/client/ImportInitializerProvider.tsx @@ -14,6 +14,7 @@ export const ImportInitializerProvider = (props: any) => { schema: { 'x-align': 'right', 'x-decorator': 'ACLActionProvider', + 'x-acl-action': 'importXlsx', 'x-acl-action-props': { skipScopeCheck: true, },