Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions requests/Switcher API.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,24 @@
},
"response": []
},
{
"name": "Domain - Read Collab",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/domain/collaboration",
"host": [
"{{url}}"
],
"path": [
"domain",
"collaboration"
]
}
},
"response": []
},
{
"name": "Domain - Read Single",
"request": {
Expand Down
13 changes: 13 additions & 0 deletions src/api-docs/paths/path-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ export default {
}
}
},
'/doamin/collaboration': {
get: {
tags: ['Domain'],
description: 'Get domains for collaboration',
security: [{ bearerAuth: [] }],
responses: {
'200': {
description: 'Success',
content: commonArraySchemaContent('Domain')
}
}
}
},
'/domain/history/{id}': {
get: {
tags: ['Domain'],
Expand Down
1 change: 1 addition & 0 deletions src/routers/config-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ router.get('/configstrategy', auth, [
elements => elements.activated.get(req.query.env ? req.query.env : EnvType.DEFAULT) != undefined);

configStrategies = await verifyOwnership(req.admin, configStrategies, config.domain, ActionTypes.READ, RouterTypes.STRATEGY, true);
await Services.populateAdmin(configStrategies);

res.send(configStrategies);
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions src/routers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ router.get('/config', auth, [

let configs = groupConfig.config;
configs = await verifyOwnership(req.admin, configs, groupConfig.domain, ActionTypes.READ, RouterTypes.CONFIG, true);
await Services.populateAdmin(configs);

if (req.query.fields) {
configs = getFields(configs, req.query.fields);
Expand Down
17 changes: 17 additions & 0 deletions src/routers/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,26 @@ router.get('/domain', auth, async (req, res) => {
sort: sortBy(req.query)
}
});

req.admin.domain.forEach(domain => domain.admin = {
_id: req.admin._id,
name: req.admin.name
});

res.send(req.admin.domain);
});

router.get('/domain/collaboration', auth, async (req, res) => {
await req.admin.populate({ path: 'team_list' });

const domains = [];
for (const adm of req.admin.team_list) {
domains.push(await Services.getDomainById(adm.domain.toString(), false, true));
}

res.send(domains);
});

router.get('/domain/:id', auth, [
check('id').isMongoId()
], validate, async (req, res) => {
Expand Down
1 change: 1 addition & 0 deletions src/routers/group-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ router.get('/groupconfig', auth, [

let groups = domain.groupConfig;
groups = await verifyOwnership(req.admin, groups, domain._id, ActionTypes.READ, RouterTypes.GROUP, true);
await Services.populateAdmin(groups);

res.send(groups);
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions src/services/config-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export async function getStrategies(where, lean = false) {
return query.exec();
}

export async function populateAdmin(configStrategies) {
for (const configStrategy of configStrategies) {
await configStrategy.populate({ path: 'admin', select: 'name' });
}
}

export async function createStrategy(args, admin) {
const config = await getConfigById(args.config);

Expand Down
6 changes: 6 additions & 0 deletions src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export async function getTotalConfigsByDomainId(domain) {
return Config.find({ domain }).countDocuments();
}

export async function populateAdmin(configs) {
for (const config of configs) {
await config.populate({ path: 'admin', select: 'name' });
}
}

export async function createConfig(args, admin) {
// validates account plan permissions
const group = await getGroupConfigById(args.group);
Expand Down
6 changes: 6 additions & 0 deletions src/services/group-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export async function getTotalGroupsByDomainId(domain) {
return GroupConfig.find({ domain }).countDocuments();
}

export async function populateAdmin(groups) {
for (const group of groups) {
await group.populate({ path: 'admin', select: 'name' });
}
}

export async function createGroup(args, admin) {
let groupconfig = new GroupConfig({
...args,
Expand Down
1 change: 1 addition & 0 deletions tests/config-strategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ describe('Testing reading strategies #1', () => {
expect(response.body[0].operation).toEqual(configStrategyDocument.operation);
expect(String(response.body[0].owner)).toEqual(String(configStrategyDocument.owner));
expect(response.body[0].activated[EnvType.DEFAULT]).toEqual(configStrategyDocument.activated.get(EnvType.DEFAULT));
expect(response.body[0].admin.name).toEqual(adminMasterAccount.name);

// Adding new Config Strategy
response = await request(app)
Expand Down
1 change: 1 addition & 0 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('Testing fetch configuration info', () => {
expect(response.body[0].key).toEqual(config1Document.key);
expect(String(response.body[0].owner)).toEqual(String(config1Document.owner));
expect(response.body[0].activated[EnvType.DEFAULT]).toEqual(config1Document.activated.get(EnvType.DEFAULT));
expect(response.body[0].admin.name).toEqual(adminMasterAccount.name);
});

test('CONFIG_SUITE - Should get Config information - only fields (key, activated.default)', async () => {
Expand Down
24 changes: 22 additions & 2 deletions tests/domain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
configStrategyId,
environment1Id,
adminAccountId,
component1Id
component1Id,
teamId
} from './fixtures/db_api';
import Component from '../src/models/component';

Expand Down Expand Up @@ -88,7 +89,7 @@ describe('Testing fetch Domain info', () => {
expect(String(response.body[0]._id)).toEqual(String(domainDocument._id));
expect(response.body[0].name).toEqual(domainDocument.name);
expect(String(response.body[0].owner)).toEqual(String(domainDocument.owner));
expect(response.body[0].token).toEqual(domainDocument.token);
expect(response.body[0].admin.name).toBe(adminMasterAccount.name);

// Adding new Domain
response = await request(app)
Expand Down Expand Up @@ -118,6 +119,25 @@ describe('Testing fetch Domain info', () => {
expect(response.body.length).toEqual(1);
});

test('DOMAIN_SUITE - Should read domains in which a user is collaborating', async () => {
await request(app)
.patch('/team/member/add/' + teamId)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
member: adminMasterAccountId
}).expect(200);

let response = await request(app)
.get('/domain/collaboration')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send()
.expect(200);

expect(response.body.length).toEqual(1);
expect(response.body[0].name).toEqual(domainDocument.name);
expect(response.body[0].admin.name).toEqual(adminMasterAccount.name);
});

test('DOMAIN_SUITE - Should get Domain information by Id', async () => {
let response = await request(app)
.get('/domain/' + domainId)
Expand Down
1 change: 1 addition & 0 deletions tests/group-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('Testing fetch Group info', () => {
expect(response.body[0].name).toEqual(groupConfigDocument.name);
expect(String(response.body[0].owner)).toEqual(String(groupConfigDocument.owner));
expect(response.body[0].activated[EnvType.DEFAULT]).toEqual(groupConfigDocument.activated.get(EnvType.DEFAULT));
expect(response.body[0].admin.name).toBe(adminMasterAccount.name);

// Adding new Group Config
response = await request(app)
Expand Down