chore: roles collection list

This commit is contained in:
Chareice 2024-01-26 17:34:34 +08:00
parent 103552d79c
commit f38041ff3b
No known key found for this signature in database
3 changed files with 17 additions and 11 deletions

View File

@ -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);
});
});

View File

@ -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';

View File

@ -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<any>(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)