Skip to content

Commit 63eec1d

Browse files
author
vikasrohit
authored
Merge pull request #451 from topcoder-platform/cf20
CF20
2 parents fa5a31c + f9784c5 commit 63eec1d

File tree

5 files changed

+369
-7
lines changed

5 files changed

+369
-7
lines changed

docs/Project API.postman_collection.json

Lines changed: 247 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "2e0a1b99-3cb9-4c77-a562-7e6fe4956358",
3+
"_postman_id": "49981b6e-f611-4016-999e-737ef4103435",
44
"name": "Project API",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -5837,6 +5837,252 @@
58375837
],
58385838
"protocolProfileBehavior": {}
58395839
},
5840+
{
5841+
"name": "Org Config",
5842+
"item": [
5843+
{
5844+
"name": "Create org config",
5845+
"event": [
5846+
{
5847+
"listen": "test",
5848+
"script": {
5849+
"id": "fbc45946-a3f2-433a-8ec5-0af82b69d2bd",
5850+
"exec": [
5851+
"pm.test(\"Status code is 201\", function () {",
5852+
" pm.response.to.have.status(201);",
5853+
" console.log(pm.response.json())",
5854+
" pm.environment.set(\"orgStrId\", pm.response.json().orgId);",
5855+
" pm.environment.set(\"orgConfigName\", pm.response.json().configName);",
5856+
" pm.environment.set(\"orgId\", pm.response.json().id);",
5857+
"});"
5858+
],
5859+
"type": "text/javascript"
5860+
}
5861+
}
5862+
],
5863+
"request": {
5864+
"method": "POST",
5865+
"header": [
5866+
{
5867+
"key": "Content-Type",
5868+
"value": "application/json"
5869+
},
5870+
{
5871+
"key": "Authorization",
5872+
"value": "Bearer {{jwt-token}}"
5873+
}
5874+
],
5875+
"body": {
5876+
"mode": "raw",
5877+
"raw": "{ \n\t\"orgId\": \"testStr Id\",\n \"configName\": \"project_catefory_url\",\n \"configValue\": \"http://localhost/url\"\n}"
5878+
},
5879+
"url": {
5880+
"raw": "{{api-url}}/projects/metadata/orgConfig",
5881+
"host": [
5882+
"{{api-url}}"
5883+
],
5884+
"path": [
5885+
"projects",
5886+
"metadata",
5887+
"orgConfig"
5888+
]
5889+
}
5890+
},
5891+
"response": []
5892+
},
5893+
{
5894+
"name": "List org configs without orgId",
5895+
"request": {
5896+
"method": "GET",
5897+
"header": [
5898+
{
5899+
"key": "Content-Type",
5900+
"value": "application/json"
5901+
},
5902+
{
5903+
"key": "Authorization",
5904+
"value": "Bearer {{jwt-token}}"
5905+
}
5906+
],
5907+
"url": {
5908+
"raw": "{{api-url}}/projects/metadata/orgConfig",
5909+
"host": [
5910+
"{{api-url}}"
5911+
],
5912+
"path": [
5913+
"projects",
5914+
"metadata",
5915+
"orgConfig"
5916+
]
5917+
}
5918+
},
5919+
"response": []
5920+
},
5921+
{
5922+
"name": "List org configs with only orgId",
5923+
"request": {
5924+
"method": "GET",
5925+
"header": [
5926+
{
5927+
"key": "Content-Type",
5928+
"value": "application/json"
5929+
},
5930+
{
5931+
"key": "Authorization",
5932+
"value": "Bearer {{jwt-token}}"
5933+
}
5934+
],
5935+
"url": {
5936+
"raw": "{{api-url}}/projects/metadata/orgConfig?orgId={{orgStrId}}",
5937+
"host": [
5938+
"{{api-url}}"
5939+
],
5940+
"path": [
5941+
"projects",
5942+
"metadata",
5943+
"orgConfig"
5944+
],
5945+
"query": [
5946+
{
5947+
"key": "orgId",
5948+
"value": "{{orgStrId}}",
5949+
"description": "orgId can be array with ',', 'id1,id2'"
5950+
}
5951+
]
5952+
}
5953+
},
5954+
"response": []
5955+
},
5956+
{
5957+
"name": "List org configs with orgId and configName",
5958+
"request": {
5959+
"method": "GET",
5960+
"header": [
5961+
{
5962+
"key": "Content-Type",
5963+
"value": "application/json"
5964+
},
5965+
{
5966+
"key": "Authorization",
5967+
"value": "Bearer {{jwt-token}}"
5968+
}
5969+
],
5970+
"url": {
5971+
"raw": "{{api-url}}/projects/metadata/orgConfig?orgId={{orgStrId}}&configName={{orgConfigName}}",
5972+
"host": [
5973+
"{{api-url}}"
5974+
],
5975+
"path": [
5976+
"projects",
5977+
"metadata",
5978+
"orgConfig"
5979+
],
5980+
"query": [
5981+
{
5982+
"key": "orgId",
5983+
"value": "{{orgStrId}}",
5984+
"description": "orgId can be array with ',', 'id1,id2'"
5985+
},
5986+
{
5987+
"key": "configName",
5988+
"value": "{{orgConfigName}}"
5989+
}
5990+
]
5991+
}
5992+
},
5993+
"response": []
5994+
},
5995+
{
5996+
"name": "Delete org config",
5997+
"request": {
5998+
"method": "DELETE",
5999+
"header": [
6000+
{
6001+
"key": "Content-Type",
6002+
"value": "application/json"
6003+
},
6004+
{
6005+
"key": "Authorization",
6006+
"value": "Bearer {{jwt-token}}"
6007+
}
6008+
],
6009+
"body": {
6010+
"mode": "raw",
6011+
"raw": ""
6012+
},
6013+
"url": {
6014+
"raw": "{{api-url}}/projects/metadata/orgConfig/{{orgId}}",
6015+
"host": [
6016+
"{{api-url}}"
6017+
],
6018+
"path": [
6019+
"projects",
6020+
"metadata",
6021+
"orgConfig",
6022+
"{{orgId}}"
6023+
]
6024+
}
6025+
},
6026+
"response": []
6027+
},
6028+
{
6029+
"name": "Update org config",
6030+
"request": {
6031+
"method": "PATCH",
6032+
"header": [
6033+
{
6034+
"key": "Content-Type",
6035+
"value": "application/json"
6036+
},
6037+
{
6038+
"key": "Authorization",
6039+
"value": "Bearer {{jwt-token}}"
6040+
}
6041+
],
6042+
"body": {
6043+
"mode": "raw",
6044+
"raw": "{ \n\t\"orgId\": \"another orgId\",\n \"configName\": \"project_catefory_url\",\n \"configValue\": \"http://localhost/url\"\n}"
6045+
},
6046+
"url": {
6047+
"raw": "{{api-url}}/projects/metadata/orgConfig/{{orgId}}",
6048+
"host": [
6049+
"{{api-url}}"
6050+
],
6051+
"path": [
6052+
"projects",
6053+
"metadata",
6054+
"orgConfig",
6055+
"{{orgId}}"
6056+
]
6057+
}
6058+
},
6059+
"response": []
6060+
}
6061+
],
6062+
"event": [
6063+
{
6064+
"listen": "prerequest",
6065+
"script": {
6066+
"id": "2e274cc9-22e6-4dd2-9eee-c4f1fd98253d",
6067+
"type": "text/javascript",
6068+
"exec": [
6069+
""
6070+
]
6071+
}
6072+
},
6073+
{
6074+
"listen": "test",
6075+
"script": {
6076+
"id": "9d171dbf-2a50-4483-b172-ce240ac09413",
6077+
"type": "text/javascript",
6078+
"exec": [
6079+
""
6080+
]
6081+
}
6082+
}
6083+
],
6084+
"protocolProfileBehavior": {}
6085+
},
58406086
{
58416087
"name": "Product Category",
58426088
"item": [

src/routes/projectMembers/create.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ module.exports = [
3838
targetRole = _.get(req, 'body.role');
3939

4040
if (PROJECT_MEMBER_ROLE.MANAGER === targetRole &&
41-
!util.hasRoles(req, [USER_ROLE.MANAGER])) {
42-
const err = new Error(`Only manager is able to join as ${targetRole}`);
41+
!util.hasRoles(req, [USER_ROLE.TOPCODER_ADMIN, USER_ROLE.CONNECT_ADMIN, USER_ROLE.MANAGER])) {
42+
const err = new Error(`Only admin or manager is able to join as ${targetRole}`);
4343
err.status = 401;
4444
return next(err);
4545
}
@@ -96,7 +96,7 @@ module.exports = [
9696
err.status = 401;
9797
return next(err);
9898
}
99-
} else if (util.hasRoles(req, [USER_ROLE.MANAGER, USER_ROLE.CONNECT_ADMIN])) {
99+
} else if (util.hasRoles(req, [USER_ROLE.MANAGER, USER_ROLE.CONNECT_ADMIN, USER_ROLE.TOPCODER_ADMIN])) {
100100
targetRole = PROJECT_MEMBER_ROLE.MANAGER;
101101
} else if (util.hasRoles(req, [
102102
USER_ROLE.TOPCODER_ACCOUNT_MANAGER,

src/routes/projectMembers/create.spec.js

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import util from '../../util';
99
import server from '../../app';
1010
import testUtil from '../../tests/util';
1111
import busApi from '../../services/busApi';
12-
import { USER_ROLE, BUS_API_EVENT, RESOURCES, CONNECT_NOTIFICATION_EVENT, INVITE_STATUS } from '../../constants';
12+
import {
13+
USER_ROLE,
14+
BUS_API_EVENT,
15+
RESOURCES,
16+
CONNECT_NOTIFICATION_EVENT,
17+
INVITE_STATUS,
18+
PROJECT_MEMBER_ROLE,
19+
} from '../../constants';
1320

1421
const should = chai.should();
1522

@@ -201,6 +208,69 @@ describe('Project Members create', () => {
201208
});
202209
});
203210

211+
it('should return 201 and register admin as manager', (done) => {
212+
const mockHttpClient = _.merge(testUtil.mockHttpClient, {
213+
get: () => Promise.resolve({
214+
status: 200,
215+
data: {
216+
id: 'requesterId',
217+
version: 'v3',
218+
result: {
219+
success: true,
220+
status: 200,
221+
content: [{
222+
roleName: USER_ROLE.TOPCODER_ADMIN,
223+
}],
224+
},
225+
},
226+
}),
227+
});
228+
sandbox.stub(util, 'getHttpClient', () => mockHttpClient);
229+
request(server)
230+
.post(`/v5/projects/${project1.id}/members/`)
231+
.set({
232+
Authorization: `Bearer ${testUtil.jwts.admin}`,
233+
})
234+
.expect('Content-Type', /json/)
235+
.expect(201)
236+
.end((err, res) => {
237+
if (err) {
238+
done(err);
239+
} else {
240+
const resJson = res.body;
241+
should.exist(resJson);
242+
resJson.role.should.equal('manager');
243+
resJson.isPrimary.should.be.truthy;
244+
resJson.projectId.should.equal(project1.id);
245+
resJson.userId.should.equal(40051333);
246+
server.services.pubsub.publish.calledWith('project.member.added').should.be.true;
247+
done();
248+
}
249+
});
250+
});
251+
252+
it('should return 401 if register admin as role other than manager (copilot) ', (done) => {
253+
request(server)
254+
.post(`/v5/projects/${project1.id}/members/`)
255+
.set({
256+
Authorization: `Bearer ${testUtil.jwts.admin}`,
257+
})
258+
.send({ role: PROJECT_MEMBER_ROLE.COPILOT })
259+
.expect('Content-Type', /json/)
260+
.expect(401, done);
261+
});
262+
263+
it('should return 401 if register admin as role other than manager (project manager) ', (done) => {
264+
request(server)
265+
.post(`/v5/projects/${project1.id}/members/`)
266+
.set({
267+
Authorization: `Bearer ${testUtil.jwts.admin}`,
268+
})
269+
.send({ role: PROJECT_MEMBER_ROLE.PROJECT_MANAGER })
270+
.expect('Content-Type', /json/)
271+
.expect(401, done);
272+
});
273+
204274
describe('Bus api', () => {
205275
let createEventSpy;
206276

src/routes/projects/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
333333
if (_.has(criteria, 'filters.customer')) {
334334
mustQuery = _.concat(mustQuery, setFilter('customer',
335335
criteria.filters.customer,
336-
['members.firstName', 'members.lastName']));
336+
['members.firstName', 'members.lastName', 'members.handle']));
337337
}
338338

339339
if (_.has(criteria, 'filters.manager')) {
340340
mustQuery = _.concat(mustQuery, setFilter('manager',
341341
criteria.filters.manager,
342-
['members.firstName', 'members.lastName']));
342+
['members.firstName', 'members.lastName', 'members.handle']));
343343
}
344344

345345
if (_.has(criteria, 'filters.userId') || _.has(criteria, 'filters.email')) {

0 commit comments

Comments
 (0)