mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 19:47:26 +00:00
chore: roles collection list
This commit is contained in:
parent
103552d79c
commit
f38041ff3b
@ -236,5 +236,14 @@ describe('data source with acl', () => {
|
|||||||
|
|
||||||
expect(getResourceResp.status).toBe(200);
|
expect(getResourceResp.status).toBe(200);
|
||||||
expect(getResourceResp.body.data.actions[0].scope).toBeNull();
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import remoteCollectionsResourcer from './resourcers/data-sources-collections';
|
|||||||
import remoteFieldsResourcer from './resourcers/data-sources-collections-fields';
|
import remoteFieldsResourcer from './resourcers/data-sources-collections-fields';
|
||||||
import { RemoteCollectionModel } from './models/remote-collection-model';
|
import { RemoteCollectionModel } from './models/remote-collection-model';
|
||||||
import { RemoteFieldModel } from './models/remote-field-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 databaseConnectionsRolesResourcer from './resourcers/data-sources-roles';
|
||||||
import rolesConnectionResourcesResourcer from './resourcers/data-sources-resources';
|
import rolesConnectionResourcesResourcer from './resourcers/data-sources-resources';
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Database } from '@nocobase/database';
|
|
||||||
import { FullDataRepository } from '../services/full-data-repository';
|
import { FullDataRepository } from '../services/full-data-repository';
|
||||||
|
|
||||||
type UsingConfigType = 'strategy' | 'resourceAction';
|
type UsingConfigType = 'strategy' | 'resourceAction';
|
||||||
@ -8,27 +7,25 @@ function totalPage(total, pageSize): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rolesRemoteCollectionsResourcer = {
|
const rolesRemoteCollectionsResourcer = {
|
||||||
name: 'roles.remoteCollections',
|
name: 'roles.dataSourcesCollections',
|
||||||
actions: {
|
actions: {
|
||||||
async list(ctx, next) {
|
async list(ctx, next) {
|
||||||
const role = ctx.action.params.associatedIndex;
|
const role = ctx.action.params.associatedIndex;
|
||||||
const { page = 1, pageSize = 20 } = ctx.action.params;
|
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<any>(dataSource.collectionManager.getCollections());
|
||||||
|
|
||||||
const collectionRepository = new FullDataRepository([...db.collections.values()]);
|
|
||||||
|
|
||||||
// all collections
|
// all collections
|
||||||
const [collections, count] = await collectionRepository.findAndCount();
|
const [collections, count] = await collectionRepository.findAndCount();
|
||||||
|
|
||||||
const roleResources = await mainDb.getRepository('connectionsRolesResources').find({
|
const roleResources = await ctx.app.db.getRepository('dataSourcesRolesResources').find({
|
||||||
filter: {
|
filter: {
|
||||||
roleName: role,
|
roleName: role,
|
||||||
connectionName: connectionName,
|
dataSourceKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,7 +37,7 @@ const rolesRemoteCollectionsResourcer = {
|
|||||||
.map((roleResources) => roleResources.get('name'));
|
.map((roleResources) => roleResources.get('name'));
|
||||||
|
|
||||||
const items = collections.map((collection, i) => {
|
const items = collections.map((collection, i) => {
|
||||||
const collectionName = collection.name;
|
const collectionName = collection.options.name;
|
||||||
const exists = roleResourcesNames.includes(collectionName);
|
const exists = roleResourcesNames.includes(collectionName);
|
||||||
|
|
||||||
const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collectionName)
|
const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collectionName)
|
Loading…
Reference in New Issue
Block a user