Skip to content

Commit 23fc994

Browse files
authored
Merge pull request #447 from gets0ul/connect-app_issue_3423
Fix for connect-app issue 3423
2 parents 99282bc + 618fdb8 commit 23fc994

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

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

0 commit comments

Comments
 (0)