fix(acl): association field acl check error (#2675)

* fix: association field acl check

* fix: association field acl check

* fix: import action form field acl check error
This commit is contained in:
katherinehhh 2023-09-19 17:26:29 +08:00 committed by GitHub
parent 630c6f2d79
commit bc5ecc9b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 36 deletions

View File

@ -182,7 +182,7 @@ export const ACLCollectionProvider = (props) => {
if (allowAll) {
return props.children;
}
const actionPath = schema?.['x-acl-action'];
const actionPath = schema?.['x-acl-action'] || props.actionPath;
if (!actionPath) {
return props.children;
}
@ -190,6 +190,8 @@ export const ACLCollectionProvider = (props) => {
if (!params) {
return null;
}
const [_, actionName] = actionPath.split(':');
params.actionName = actionName;
return <ACLActionParamsContext.Provider value={params}>{props.children}</ACLActionParamsContext.Provider>;
};
@ -258,7 +260,8 @@ export const ACLCollectionFieldProvider = (props) => {
const field = useField<Field>();
const { allowAll } = useACLRoleContext();
const { whitelist } = useACLFieldWhitelist();
const allowed = whitelist.length > 0 ? whitelist.includes(fieldSchema.name) : true;
const [name] = (fieldSchema.name as string).split('.');
const allowed = whitelist.length > 0 ? whitelist.includes(name) : true;
useEffect(() => {
if (!allowed) {

View File

@ -4,6 +4,7 @@ import { RecursionField, useField, useFieldSchema, observer } from '@formily/rea
import React, { useEffect } from 'react';
import { CollectionProvider } from '../../../collection-manager';
import { useAssociationFieldContext, useInsertSchema } from './hooks';
import { ACLCollectionProvider, useACLActionParamsContext } from '../../../acl';
import schema from './schema';
export const InternalNester = observer(
@ -13,11 +14,13 @@ export const InternalNester = observer(
const insertNester = useInsertSchema('Nester');
const { options: collectionField } = useAssociationFieldContext();
const showTitle = fieldSchema['x-decorator-props']?.showTitle ?? true;
const { actionName } = useACLActionParamsContext();
useEffect(() => {
insertNester(schema.Nester);
}, []);
return (
<CollectionProvider name={collectionField.target}>
<ACLCollectionProvider actionPath={`${collectionField.target}:${actionName}`}>
<FormLayout layout={'vertical'}>
<div
className={cx(
@ -54,6 +57,7 @@ export const InternalNester = observer(
/>
</div>
</FormLayout>
</ACLCollectionProvider>
</CollectionProvider>
);
},

View File

@ -77,6 +77,11 @@ export const ImportActionInitializer = (props) => {
formLayout: {
type: 'void',
'x-component': 'FormLayout',
'x-component-props': {
labelCol: 6,
wrapperCol: 10,
layout: 'vertical',
},
properties: {
download: {
type: 'void',

View File

@ -1,6 +1,7 @@
import { SchemaComponentOptions } from '@nocobase/client';
import React, { useState } from 'react';
import { createPortal } from 'react-dom';
import { FormLayout, FormItem } from '@formily/antd-v5';
import { ImportActionInitializer, ImportDesigner, ImportInitializerProvider } from '.';
import { ImportContext } from './context';
import { ImportModal, ImportStatus } from './ImportModal';
@ -11,7 +12,7 @@ export const ImportPluginProvider = (props: any) => {
const { uploadValidator, beforeUploadHandler, validateUpload } = useShared();
return (
<SchemaComponentOptions
components={{ ImportActionInitializer, ImportDesigner }}
components={{ ImportActionInitializer, ImportDesigner, FormLayout, FormItem }}
scope={{
uploadValidator,
validateUpload,