refactor: association block acl improve (#2682)
This commit is contained in:
parent
ebc1d1afb4
commit
64b5471084
@ -5,7 +5,7 @@ import { Navigate } from 'react-router-dom';
|
||||
import { useAPIClient, useRequest } from '../api-client';
|
||||
import { useAppSpin } from '../application/hooks/useAppSpin';
|
||||
import { useBlockRequestContext } from '../block-provider/BlockProvider';
|
||||
import { useCollection } from '../collection-manager';
|
||||
import { useCollection, useCollectionManager } from '../collection-manager';
|
||||
import { useResourceActionContext } from '../collection-manager/ResourceActionProvider';
|
||||
import { useRecord } from '../record-provider';
|
||||
import { SchemaComponentOptions, useDesignable } from '../schema-component';
|
||||
@ -148,6 +148,7 @@ const useResourceName = () => {
|
||||
export function useACLRoleContext() {
|
||||
const { data, getActionAlias, inResources, getResourceActionParams, getStrategyActionParams } = useACLRolesCheck();
|
||||
const allowedActions = useAllowedActions();
|
||||
const { getCollectionJoinField } = useCollectionManager();
|
||||
const verifyScope = (actionName: string, recordPkValue: any) => {
|
||||
const actionAlias = getActionAlias(actionName);
|
||||
if (!Array.isArray(allowedActions?.[actionAlias])) {
|
||||
@ -159,6 +160,7 @@ export function useACLRoleContext() {
|
||||
...data,
|
||||
parseAction: (actionPath: string, options: any = {}) => {
|
||||
const [resourceName, actionName] = actionPath.split(':');
|
||||
const targetResource = resourceName?.includes('.') && getCollectionJoinField(resourceName)?.target;
|
||||
if (!getIgnoreScope(options)) {
|
||||
const r = verifyScope(actionName, options.recordPkValue);
|
||||
if (r !== null) {
|
||||
@ -168,6 +170,9 @@ export function useACLRoleContext() {
|
||||
if (data?.allowAll) {
|
||||
return {};
|
||||
}
|
||||
if (inResources(targetResource)) {
|
||||
return getResourceActionParams(`${targetResource}:${actionName}`);
|
||||
}
|
||||
if (inResources(resourceName)) {
|
||||
return getResourceActionParams(actionPath);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import { CollectionProvider } from '../../../collection-manager';
|
||||
import { useSchemaOptionsContext } from '../../../schema-component';
|
||||
import Select from '../select/Select';
|
||||
import { useAssociationFieldContext, useInsertSchema } from './hooks';
|
||||
import { ACLCollectionProvider, useACLActionParamsContext } from '../../../acl';
|
||||
import schema from './schema';
|
||||
|
||||
export const InternalSubTable = observer(
|
||||
@ -14,6 +15,7 @@ export const InternalSubTable = observer(
|
||||
const fieldSchema = useFieldSchema();
|
||||
const insert = useInsertSchema('SubTable');
|
||||
const { options } = useAssociationFieldContext();
|
||||
const { actionName } = useACLActionParamsContext();
|
||||
useEffect(() => {
|
||||
insert(schema.SubTable);
|
||||
field.required = fieldSchema['required'];
|
||||
@ -27,40 +29,42 @@ export const InternalSubTable = observer(
|
||||
};
|
||||
return (
|
||||
<CollectionProvider name={options.target}>
|
||||
<FormLayout
|
||||
className={css`
|
||||
.ant-formily-item-bordered-none {
|
||||
.ant-input-number-group-addon {
|
||||
border: none !important;
|
||||
background: none;
|
||||
<ACLCollectionProvider actionPath={`${options.target}:${actionName}`}>
|
||||
<FormLayout
|
||||
className={css`
|
||||
.ant-formily-item-bordered-none {
|
||||
.ant-input-number-group-addon {
|
||||
border: none !important;
|
||||
background: none;
|
||||
}
|
||||
.ant-checkbox-wrapper {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.ant-table {
|
||||
margin: 0px !important;
|
||||
}
|
||||
}
|
||||
.ant-checkbox-wrapper {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.ant-table {
|
||||
margin: 0px !important;
|
||||
}
|
||||
}
|
||||
`}
|
||||
layout={'vertical'}
|
||||
bordered={false}
|
||||
>
|
||||
<SchemaOptionsContext.Provider
|
||||
value={{
|
||||
scope: option.scope,
|
||||
components,
|
||||
}}
|
||||
`}
|
||||
layout={'vertical'}
|
||||
bordered={false}
|
||||
>
|
||||
<RecursionField
|
||||
onlyRenderProperties
|
||||
basePath={field.address}
|
||||
schema={fieldSchema}
|
||||
filterProperties={(s) => {
|
||||
return s['x-component'] === 'AssociationField.SubTable';
|
||||
<SchemaOptionsContext.Provider
|
||||
value={{
|
||||
scope: option.scope,
|
||||
components,
|
||||
}}
|
||||
/>
|
||||
</SchemaOptionsContext.Provider>
|
||||
</FormLayout>
|
||||
>
|
||||
<RecursionField
|
||||
onlyRenderProperties
|
||||
basePath={field.address}
|
||||
schema={fieldSchema}
|
||||
filterProperties={(s) => {
|
||||
return s['x-component'] === 'AssociationField.SubTable';
|
||||
}}
|
||||
/>
|
||||
</SchemaOptionsContext.Provider>
|
||||
</FormLayout>
|
||||
</ACLCollectionProvider>
|
||||
</CollectionProvider>
|
||||
);
|
||||
},
|
||||
|
@ -37,7 +37,7 @@ const useTableColumns = (props) => {
|
||||
const { exists, render } = useSchemaInitializer(schema['x-initializer']);
|
||||
const columns = schema
|
||||
.reduceProperties((buf, s) => {
|
||||
if (isColumnComponent(s) && schemaInWhitelist(Object.values(s.properties || {}).pop(), props?.isSubTable)) {
|
||||
if (isColumnComponent(s) && schemaInWhitelist(Object.values(s.properties || {}).pop())) {
|
||||
return buf.concat([s]);
|
||||
}
|
||||
return buf;
|
||||
|
Loading…
Reference in New Issue
Block a user