Skip to content

Feature/self service email #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,16 +1096,6 @@ async function createChallenge (currentUser, challenge, userToken) {

// post bus event
await helper.postBusEvent(constants.Topics.ChallengeCreated, ret)
// send email notification
if (challenge.legacy.selfService && currentUser.handle) {
await helper.sendSelfServiceNotification(
constants.SelfServiceNotificationTypes.WORK_REQUEST_SUBMITTED,
[{ userId: currentUser.userId }],
{
handle: currentUser.handle,
workItemName: ret.name
})
}
return ret
}

Expand Down Expand Up @@ -1391,6 +1381,7 @@ async function validateWinners (winners, challengeId) {
*/
async function update (currentUser, challengeId, data, isFull) {
const cancelReason = _.cloneDeep(data.cancelReason)
let sendActivationEmail = false
delete data.cancelReason
if (!_.isUndefined(_.get(data, 'legacy.reviewType'))) {
_.set(data, 'legacy.reviewType', _.toUpper(_.get(data, 'legacy.reviewType')))
Expand All @@ -1417,6 +1408,7 @@ async function update (currentUser, challengeId, data, isFull) {
try {
const selfServiceProjectName = `Self service - ${currentUser.createdBy} - ${challenge.name}`
await helper.activateProject(challenge.projectId, currentUser, selfServiceProjectName, challenge.description)
sendActivationEmail = true
} catch (e) {
await update(
currentUser,
Expand Down Expand Up @@ -1901,6 +1893,15 @@ async function update (currentUser, challengeId, data, isFull) {
doc: challenge
}
})
if (sendActivationEmail && challenge.legacy.selfService && currentUser.handle) {
await helper.sendSelfServiceNotification(
constants.SelfServiceNotificationTypes.WORK_REQUEST_SUBMITTED,
[{ email: currentUser.email }],
{
handle: currentUser.handle,
workItemName: challenge.name
})
}
return challenge
}

Expand Down