Skip to content

Commit c8f2de9

Browse files
authored
Merge pull request #255 from topcoder-platform/feature/accountManager
Account manager changes
2 parents 80ab3f2 + db19f45 commit c8f2de9

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

src/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const PROJECT_MEMBER_ROLE = {
1818
OBSERVER: 'observer',
1919
CUSTOMER: 'customer',
2020
COPILOT: 'copilot',
21+
ACCOUNT_MANAGER: 'account_manager',
2122
};
2223

2324
export const PROJECT_MEMBER_MANAGER_ROLES = [PROJECT_MEMBER_ROLE.MANAGER, PROJECT_MEMBER_ROLE.OBSERVER];
@@ -31,7 +32,7 @@ export const USER_ROLE = {
3132

3233
export const ADMIN_ROLES = [USER_ROLE.CONNECT_ADMIN, USER_ROLE.TOPCODER_ADMIN];
3334

34-
export const MANAGER_ROLES = [...ADMIN_ROLES, USER_ROLE.MANAGER];
35+
export const MANAGER_ROLES = [...ADMIN_ROLES, USER_ROLE.MANAGER, PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER];
3536

3637
export const EVENT = {
3738
ROUTING_KEY: {

src/routes/projectMembers/create.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
2-
31
import _ from 'lodash';
2+
import Joi from 'joi';
3+
import validate from 'express-validation';
44
import { middleware as tcMiddleware } from 'tc-core-library-js';
55
import util from '../../util';
6-
import { USER_ROLE, PROJECT_MEMBER_ROLE, MANAGER_ROLES, INVITE_STATUS } from '../../constants';
6+
import { INVITE_STATUS, MANAGER_ROLES, PROJECT_MEMBER_ROLE, USER_ROLE } from '../../constants';
77
import models from '../../models';
88

99
/**
@@ -13,14 +13,40 @@ import models from '../../models';
1313
*/
1414
const permissions = tcMiddleware.permissions;
1515

16+
const createProjectMemberValidations = {
17+
body: {
18+
param: Joi.object()
19+
.keys({
20+
role: Joi.any()
21+
.valid(PROJECT_MEMBER_ROLE.MANAGER, PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER, PROJECT_MEMBER_ROLE.COPILOT),
22+
}),
23+
},
24+
};
25+
1626
module.exports = [
1727
// handles request validations
28+
validate(createProjectMemberValidations),
1829
permissions('project.addMember'),
1930
(req, res, next) => {
2031
let targetRole;
21-
if (util.hasRoles(req, [USER_ROLE.MANAGER])) {
32+
if (_.get(req, 'body.param.role')) {
33+
targetRole = _.get(req, 'body.param.role');
34+
35+
if ([PROJECT_MEMBER_ROLE.MANAGER, PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER].includes(targetRole) &&
36+
!util.hasRoles(req, [USER_ROLE.MANAGER])) {
37+
const err = new Error(`Only manager is able to join as ${targetRole}`);
38+
err.status = 401;
39+
return next(err);
40+
}
41+
42+
if (targetRole === PROJECT_MEMBER_ROLE.COPILOT && !util.hasRoles(req, [USER_ROLE.COPILOT])) {
43+
const err = new Error(`Only copilot is able to join as ${targetRole}`);
44+
err.status = 401;
45+
return next(err);
46+
}
47+
} else if (util.hasRoles(req, [USER_ROLE.MANAGER, USER_ROLE.CONNECT_ADMIN])) {
2248
targetRole = PROJECT_MEMBER_ROLE.MANAGER;
23-
} else if (util.hasRoles(req, [USER_ROLE.COPILOT])) {
49+
} else if (util.hasRoles(req, [USER_ROLE.COPILOT, USER_ROLE.CONNECT_ADMIN])) {
2450
targetRole = PROJECT_MEMBER_ROLE.COPILOT;
2551
} else {
2652
const err = new Error('Only copilot or manager is able to call this endpoint');
@@ -60,13 +86,17 @@ module.exports = [
6086
.then((_invite) => {
6187
invite = _invite;
6288
if (!invite) {
63-
return res.status(201).json(util.wrapResponse(req.id, newMember, 1, 201));
89+
return res.status(201)
90+
.json(util.wrapResponse(req.id, newMember, 1, 201));
6491
}
6592
return invite.update({
6693
status: INVITE_STATUS.ACCEPTED,
67-
}).then(() => res.status(201).json(util.wrapResponse(req.id, newMember, 1, 201)));
94+
})
95+
.then(() => res.status(201)
96+
.json(util.wrapResponse(req.id, newMember, 1, 201)));
6897
});
6998
});
70-
}).catch(err => next(err));
99+
})
100+
.catch(err => next(err));
71101
},
72102
];

src/routes/projectMembers/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const updateProjectMemberValdiations = {
1717
param: Joi.object().keys({
1818
isPrimary: Joi.boolean(),
1919
role: Joi.any().valid(PROJECT_MEMBER_ROLE.CUSTOMER, PROJECT_MEMBER_ROLE.MANAGER,
20-
PROJECT_MEMBER_ROLE.COPILOT, PROJECT_MEMBER_ROLE.OBSERVER).required(),
20+
PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER, PROJECT_MEMBER_ROLE.COPILOT, PROJECT_MEMBER_ROLE.OBSERVER).required(),
2121
}),
2222
},
2323
};

0 commit comments

Comments
 (0)