Skip to content

Commit b88f083

Browse files
committed
Enable admin user to join project as manager.
1 parent 99282bc commit b88f083

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-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: 83 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,81 @@ 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.MANAGER,
223+
}],
224+
},
225+
},
226+
}),
227+
post: () => Promise.resolve({
228+
status: 200,
229+
data: {
230+
id: 'requesterId',
231+
version: 'v3',
232+
result: {
233+
success: true,
234+
status: 200,
235+
content: {},
236+
},
237+
},
238+
}),
239+
});
240+
sandbox.stub(util, 'getHttpClient', () => mockHttpClient);
241+
request(server)
242+
.post(`/v5/projects/${project1.id}/members/`)
243+
.set({
244+
Authorization: `Bearer ${testUtil.jwts.admin}`,
245+
})
246+
.expect('Content-Type', /json/)
247+
.expect(201)
248+
.end((err, res) => {
249+
if (err) {
250+
done(err);
251+
} else {
252+
const resJson = res.body;
253+
should.exist(resJson);
254+
resJson.role.should.equal('manager');
255+
resJson.isPrimary.should.be.truthy;
256+
resJson.projectId.should.equal(project1.id);
257+
resJson.userId.should.equal(40051333);
258+
server.services.pubsub.publish.calledWith('project.member.added').should.be.true;
259+
done();
260+
}
261+
});
262+
});
263+
264+
it('should return 401 if register admin as role other than manager (copilot) ', (done) => {
265+
request(server)
266+
.post(`/v5/projects/${project1.id}/members/`)
267+
.set({
268+
Authorization: `Bearer ${testUtil.jwts.admin}`,
269+
})
270+
.send({ role: PROJECT_MEMBER_ROLE.COPILOT })
271+
.expect('Content-Type', /json/)
272+
.expect(401, done);
273+
});
274+
275+
it('should return 401 if register admin as role other than manager (project manager) ', (done) => {
276+
request(server)
277+
.post(`/v5/projects/${project1.id}/members/`)
278+
.set({
279+
Authorization: `Bearer ${testUtil.jwts.admin}`,
280+
})
281+
.send({ role: PROJECT_MEMBER_ROLE.PROJECT_MANAGER })
282+
.expect('Content-Type', /json/)
283+
.expect(401, done);
284+
});
285+
204286
describe('Bus api', () => {
205287
let createEventSpy;
206288

0 commit comments

Comments
 (0)