From f38041ff3b353eef73df7204ea32da11f042a423 Mon Sep 17 00:00:00 2001 From: Chareice Date: Fri, 26 Jan 2024 17:34:34 +0800 Subject: [PATCH] chore: roles collection list --- .../__tests__/data-source-with-acl.test.ts | 9 +++++++++ .../src/server/plugin.ts | 2 +- ...ons.ts => roles-data-sources-collections.ts} | 17 +++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) rename packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/{roles-remote-collections.ts => roles-data-sources-collections.ts} (77%) diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts index 0e2ef538c9..54b7d5001a 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts @@ -236,5 +236,14 @@ describe('data source with acl', () => { expect(getResourceResp.status).toBe(200); expect(getResourceResp.body.data.actions[0].scope).toBeNull(); + + // get collection list + + const collectionListRep = await adminAgent.resource('roles.dataSourcesCollections', 'testRole').list({ + filter: { + dataSourceKey: 'mockInstance1', + }, + }); + expect(collectionListRep.status).toBe(200); }); }); diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts index 8a1f35854e..c7ac17172e 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts @@ -6,7 +6,7 @@ import remoteCollectionsResourcer from './resourcers/data-sources-collections'; import remoteFieldsResourcer from './resourcers/data-sources-collections-fields'; import { RemoteCollectionModel } from './models/remote-collection-model'; import { RemoteFieldModel } from './models/remote-field-model'; -import { rolesRemoteCollectionsResourcer } from './resourcers/roles-remote-collections'; +import { rolesRemoteCollectionsResourcer } from './resourcers/roles-data-sources-collections'; import databaseConnectionsRolesResourcer from './resourcers/data-sources-roles'; import rolesConnectionResourcesResourcer from './resourcers/data-sources-resources'; diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-remote-collections.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts similarity index 77% rename from packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-remote-collections.ts rename to packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts index e3d27f988f..731585e466 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-remote-collections.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/roles-data-sources-collections.ts @@ -1,4 +1,3 @@ -import { Database } from '@nocobase/database'; import { FullDataRepository } from '../services/full-data-repository'; type UsingConfigType = 'strategy' | 'resourceAction'; @@ -8,27 +7,25 @@ function totalPage(total, pageSize): number { } const rolesRemoteCollectionsResourcer = { - name: 'roles.remoteCollections', + name: 'roles.dataSourcesCollections', actions: { async list(ctx, next) { const role = ctx.action.params.associatedIndex; const { page = 1, pageSize = 20 } = ctx.action.params; - const { connectionName } = ctx.action.params.filter; + const { dataSourceKey } = ctx.action.params.filter; - const db: Database = ctx.app.getDb(connectionName); + const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey); - const mainDb = ctx.app.getDb('main'); - - const collectionRepository = new FullDataRepository([...db.collections.values()]); + const collectionRepository = new FullDataRepository(dataSource.collectionManager.getCollections()); // all collections const [collections, count] = await collectionRepository.findAndCount(); - const roleResources = await mainDb.getRepository('connectionsRolesResources').find({ + const roleResources = await ctx.app.db.getRepository('dataSourcesRolesResources').find({ filter: { roleName: role, - connectionName: connectionName, + dataSourceKey, }, }); @@ -40,7 +37,7 @@ const rolesRemoteCollectionsResourcer = { .map((roleResources) => roleResources.get('name')); const items = collections.map((collection, i) => { - const collectionName = collection.name; + const collectionName = collection.options.name; const exists = roleResourcesNames.includes(collectionName); const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collectionName)