Skip to content

Commit 388e9f5

Browse files
authored
Merge pull request #814 from topcoder-platform/pm-1169
fix(PM-1169): Send source as part of email resource
2 parents 759a4db + dc019e3 commit 388e9f5

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ workflows:
149149
context : org-global
150150
filters:
151151
branches:
152-
only: ['develop', 'migration-setup']
152+
only: ['develop', 'migration-setup', 'pm-1169']
153153
- deployProd:
154154
context : org-global
155155
filters:

src/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const COPILOT_APPLICATION_STATUS = {
2222
PENDING: 'pending',
2323
INVITED: 'invited',
2424
ACCEPTED: 'accepted',
25+
CANCELED: 'canceled',
2526
};
2627

2728
export const COPILOT_OPPORTUNITY_STATUS = {
@@ -360,6 +361,11 @@ export const INVITE_STATUS = {
360361
CANCELED: 'canceled',
361362
};
362363

364+
export const INVITE_SOURCE = {
365+
WORK_MANAGER: "work_manager",
366+
COPILOT_PORTAL: "copilot_portal",
367+
};
368+
363369
export const SCOPE_CHANGE_REQ_STATUS = {
364370
PENDING: 'pending',
365371
APPROVED: 'approved',

src/events/busApi.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ module.exports = (app, logger) => {
997997
const email = resource.email;
998998
const status = resource.status;
999999
const role = resource.role;
1000+
const source = resource.source;
10001001

10011002
models.Project.findOne({
10021003
where: { id: projectId },
@@ -1011,6 +1012,7 @@ module.exports = (app, logger) => {
10111012
role,
10121013
initiatorUserId: req.authUser.userId,
10131014
isSSO: util.isSSO(project),
1015+
source,
10141016
}, logger);
10151017
} else {
10161018
// send event to bus api
@@ -1021,6 +1023,7 @@ module.exports = (app, logger) => {
10211023
role,
10221024
initiatorUserId: req.authUser.userId,
10231025
isSSO: util.isSSO(project),
1026+
source,
10241027
});
10251028
createEvent(CONNECT_NOTIFICATION_EVENT.PROJECT_MEMBER_INVITE_CREATED, {
10261029
projectId,
@@ -1029,6 +1032,7 @@ module.exports = (app, logger) => {
10291032
role,
10301033
initiatorUserId: req.authUser.userId,
10311034
isSSO: util.isSSO(project),
1035+
source,
10321036
}, logger);
10331037
}
10341038
}).catch(err => logger.error(err)); // eslint-disable-line no-unused-vars

src/routes/copilotOpportunity/assign.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ module.exports = [
107107
req,
108108
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED,
109109
RESOURCES.PROJECT_MEMBER_INVITE,
110-
invite.toJSON());
110+
Object.assign({}, invite.toJSON(), {
111+
source: 'copilot_portal',
112+
}),
113+
);
111114

112115
await application.update({
113116
status: COPILOT_APPLICATION_STATUS.INVITED,

src/routes/projectMemberInvites/create.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ module.exports = [
411411
req,
412412
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED,
413413
RESOURCES.PROJECT_MEMBER_INVITE,
414-
v.toJSON());
414+
Object.assign({}, v.toJSON(), {
415+
source: 'work_manager',
416+
}),
417+
);
415418

416419
req.log.debug(`V: ${JSON.stringify(v)}`);
417420
// send email invite (async)

src/routes/projectMemberInvites/update.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Joi from 'joi';
44
import { middleware as tcMiddleware } from 'tc-core-library-js';
55
import models from '../../models';
66
import util from '../../util';
7-
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS } from '../../constants';
7+
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants';
88
import { PERMISSION } from '../../permissions/constants';
99

1010
/**
@@ -19,6 +19,9 @@ const updateMemberValidations = {
1919
status: Joi.any()
2020
.valid(_.values(INVITE_STATUS))
2121
.required(),
22+
source: Joi.string()
23+
.valid(_.values(INVITE_SOURCE))
24+
.default(INVITE_SOURCE.WORK_MANAGER),
2225
})
2326
.required(),
2427
};
@@ -29,6 +32,7 @@ module.exports = [
2932
permissions('projectMemberInvite.edit'),
3033
(req, res, next) => {
3134
const newStatus = req.body.status;
35+
const source = req.body.source;
3236
if (newStatus === INVITE_STATUS.CANCELED) {
3337
const err = new Error('Cannot change invite status to “canceled”. Please, delete the invite instead.');
3438
err.status = 400;
@@ -121,14 +125,23 @@ module.exports = [
121125
try {
122126
await util.addUserToProject(req, member, t);
123127
if (invite.applicationId) {
128+
let nextApplicationStatus = COPILOT_APPLICATION_STATUS.CANCELED;
129+
let nextOpportunityStatus = COPILOT_OPPORTUNITY_STATUS.CANCELED;
130+
let nextOpportunityRequestStatus = COPILOT_REQUEST_STATUS.CANCELED;
131+
if (source === 'copilot_portal') {
132+
nextApplicationStatus = COPILOT_APPLICATION_STATUS.ACCEPTED;
133+
nextOpportunityStatus = COPILOT_OPPORTUNITY_STATUS.COMPLETED;
134+
nextOpportunityRequestStatus = COPILOT_REQUEST_STATUS.FULFILLED;
135+
}
136+
124137
const application = await models.CopilotApplication.findOne({
125138
where: {
126139
id: invite.applicationId,
127140
},
128141
transaction: t,
129142
});
130143

131-
await application.update({ status: COPILOT_APPLICATION_STATUS.ACCEPTED }, {
144+
await application.update({ status: nextApplicationStatus }, {
132145
transaction: t
133146
});
134147

@@ -140,7 +153,7 @@ module.exports = [
140153
});
141154

142155
await opportunity.update({
143-
status: COPILOT_OPPORTUNITY_STATUS.COMPLETED
156+
status: nextOpportunityStatus,
144157
}, {
145158
transaction: t,
146159
});
@@ -153,7 +166,7 @@ module.exports = [
153166
});
154167

155168
await request.update({
156-
status: COPILOT_REQUEST_STATUS.FULFILLED
169+
status: nextOpportunityRequestStatus,
157170
}, {
158171
transaction: t,
159172
});

0 commit comments

Comments
 (0)