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