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
This commit is contained in:
katherinehhh 2023-11-04 08:29:59 +08:00 committed by GitHub
parent 9da6606e86
commit 9ec2b50990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 2 deletions

View File

@ -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 <ACLActionParamsContext.Provider value={params}>{props.children}</ACLActionParamsContext.Provider>;
}
return null;
}
return <ACLActionParamsContext.Provider value={params}>{props.children}</ACLActionParamsContext.Provider>;
};

View File

@ -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';
},
},
{

View File

@ -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';
},
},
{

View File

@ -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,
},