From 7e0ac57057d884583fe4fdbd89353ac30f408925 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 30 Jun 2023 12:02:08 +0800 Subject: [PATCH] fix(acl): add roles.users field --- .../antd/remote-select/RemoteSelect.tsx | 6 ++++-- packages/plugins/acl/src/collections/roles.ts | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx index 4cf9d1c4b..1e0283cb0 100644 --- a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx +++ b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx @@ -10,7 +10,8 @@ import { useBlockRequestContext } from '../../../block-provider/BlockProvider'; import { mergeFilter } from '../../../block-provider/SharedFilterProvider'; import { useCollection, useCollectionManager } from '../../../collection-manager'; import { getInnermostKeyAndValue } from '../../common/utils/uitls'; -import { defaultFieldNames, Select } from '../select'; +import { useCompile } from '../../hooks'; +import { Select, defaultFieldNames } from '../select'; import { ReadPretty } from './ReadPretty'; import { extractFilterfield, extractValuesByPattern, generatePattern, parseVariables } from './utils'; const EMPTY = 'N/A'; @@ -64,13 +65,14 @@ const InternalRemoteSelect = connect( } return '$includes'; }, [targetField]); + const compile = useCompile(); const mapOptionsToTags = useCallback( (options) => { try { return options .map((option) => { - let label = option[fieldNames.label]; + let label = compile(option[fieldNames.label]); if (targetField?.uiSchema?.enum) { if (Array.isArray(label)) { diff --git a/packages/plugins/acl/src/collections/roles.ts b/packages/plugins/acl/src/collections/roles.ts index 7f9f53694..c6d533ad5 100644 --- a/packages/plugins/acl/src/collections/roles.ts +++ b/packages/plugins/acl/src/collections/roles.ts @@ -84,6 +84,17 @@ export default { type: 'set', name: 'snippets', defaultValue: ['!ui.*', '!pm', '!pm.*'], - } + }, + { + type: 'belongsToMany', + name: 'users', + target: 'users', + foreignKey: 'roleName', + otherKey: 'userId', + onDelete: 'CASCADE', + sourceKey: 'name', + targetKey: 'id', + through: 'rolesUsers', + }, ], } as CollectionOptions;