Skip to content
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

Completed DAR deadline emails #197

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 35 additions & 18 deletions src/resources/datarequest/datarequest.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,11 @@ module.exports = {
.json({ status: 'error', message: 'Application not found.' });
}
let { workflow } = accessRecord;
if (_.isEmpty(workflow)) {
return res
.status(400)
.json({ status: 'error', message: 'There is no workflow attached to this application.' });
}
let activeStepIndex = workflow.steps.findIndex((step) => {
return step.active === true;
});
Expand Down Expand Up @@ -1540,11 +1545,11 @@ module.exports = {
let { firstname, lastname } = user;
// Instantiate default params
let custodianManagers = [],
managerUserIds = [],
emailRecipients = [],
options = {},
html = '',
authors = [];

authors = []
// Get applicants from 5 Safes form, using main applicant as fall back for single dataset applications
let answers = JSON.parse(accessRecord.questionAnswers);
let applicants = module.exports.extractApplicantNames(answers).join(', ');
Expand All @@ -1569,6 +1574,9 @@ module.exports = {
stepReviewers = [],
stepReviewerUserIds = [],
currentDeadline = '',
remainingReviewers = [],
remainingReviewerUserIds = [],
dateDeadline
} = context;

switch (type) {
Expand Down Expand Up @@ -1875,16 +1883,16 @@ module.exports = {
accessRecord.publisherObj.team,
teamController.roleTypes.MANAGER
);
let managerUserIds = custodianManagers.map((user) => user.id);
managerUserIds = custodianManagers.map((user) => user.id);

// 1. Create manager notifications
// 2. Create manager notifications
notificationBuilder.triggerNotificationMessage(
managerUserIds,
`Action is required as a Data Access Request application for ${publisher} is now awaiting a final decision`,
'data access request',
accessRecord._id
);
// 2. Create manager emails
// 3. Create manager emails
options = {
id: accessRecord._id,
projectName,
Expand All @@ -1906,15 +1914,14 @@ module.exports = {
);
break;
case notificationTypes.DEADLINEWARNING:
// 1. Get all reviewers who have not yet voted on active phase
// 2. Create reviewer notifications
// 1. Create reviewer notifications
await notificationBuilder.triggerNotificationMessage(
stepReviewerUserIds,
`${firstname} ${lastname} has approved a Data Access Request phase you are reviewing`,
remainingReviewerUserIds,
`The deadline is approaching for a Data Access Request application you are reviewing`,
'data access request',
accessRecord._id
);
// 3. Create reviewer emails
// 2. Create reviewer emails
options = {
id: accessRecord._id,
projectName,
Expand All @@ -1928,23 +1935,32 @@ module.exports = {
reviewSections,
reviewerNames,
nextStepName,
dateDeadline
};
html = await emailGenerator.generateReviewDeadlineWarning(options);
await emailGenerator.sendEmail(
stepReviewers,
remainingReviewers,
hdrukEmail,
`${firstname} ${lastname} has approved a Data Access Request phase you are reviewing`,
`The deadline is approaching for a Data Access Request application you are reviewing`,
html,
false
);
break;
case notificationTypes.DEADLINEPASSED:
// 1. Get all reviewers who have not yet voted on active phase
// 2. Get all managers
// 1. Get all managers
custodianManagers = teamController.getTeamMembersByRole(
accessRecord.publisherObj.team,
teamController.roleTypes.MANAGER
);
managerUserIds = custodianManagers.map((user) => user.id);
// 2. Combine managers and reviewers remaining
let deadlinePassedUserIds = [...remainingReviewerUserIds, ...managerUserIds];
let deadlinePassedUsers = [...remainingReviewers, ...custodianManagers];

// 3. Create notifications
await notificationBuilder.triggerNotificationMessage(
stepReviewerUserIds,
`${firstname} ${lastname} has approved a Data Access Request phase you are reviewing`,
deadlinePassedUserIds,
`The deadline for a Data Access Request review phase has now elapsed`,
'data access request',
accessRecord._id
);
Expand All @@ -1962,12 +1978,13 @@ module.exports = {
reviewSections,
reviewerNames,
nextStepName,
dateDeadline
};
html = await emailGenerator.generateReviewDeadlinePassed(options);
await emailGenerator.sendEmail(
stepReviewers,
deadlinePassedUsers,
hdrukEmail,
`${firstname} ${lastname} has approved a Data Access Request phase you are reviewing`,
`The deadline for a Data Access Request review phase has now elapsed`,
html,
false
);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/datarequest/datarequest.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ router.post('/:id', passport.authenticate('jwt'), datarequestController.submitAc
// @route POST api/v1/data-access-request/:id/notify
// @desc External facing endpoint to trigger notifications for Data Access Request workflows
// @access Private
router.post('/:id', passport.authenticate('jwt'), datarequestController.notifyAccessRequestById);
router.post('/:id/notify', passport.authenticate('jwt'), datarequestController.notifyAccessRequestById);

module.exports = router;
38 changes: 21 additions & 17 deletions src/resources/utilities/emailGenerator.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const _buildEmail = (fullQuestions, questionAnswers, options) => {
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 50%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Date of submission</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 50%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment().format(
'D MMM YYYY HH:mm'
'D MMM YYYY'
)}</td>
</tr>
<tr>
Expand Down Expand Up @@ -545,7 +545,7 @@ const _generateDARStatusChangedEmail = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateSubmitted
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
</table>
</td>
Expand Down Expand Up @@ -703,7 +703,7 @@ const _generateStepOverrideEmail = (options) => {
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(dateSubmitted).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(dateSubmitted).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Workflow</td>
Expand All @@ -722,11 +722,11 @@ const _generateStepOverrideEmail = (options) => {
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase commenced</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(startDateTime).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(startDateTime).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase completed</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(endDateTime).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(endDateTime).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase duration</td>
Expand Down Expand Up @@ -838,7 +838,7 @@ const _generateNewReviewPhaseEmail = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateSubmitted
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Workflow</td>
Expand Down Expand Up @@ -889,7 +889,8 @@ const _generateReviewDeadlineWarning = (options) => {
stepName,
reviewSections,
reviewerNames,
dateSubmitted,
dateSubmitted,
dateDeadline
} = options;
let body = `<div style="border: 1px solid #d0d3d4; border-radius: 15px; width: 700px; margin: 0 auto;">
<table
Expand All @@ -902,12 +903,14 @@ const _generateReviewDeadlineWarning = (options) => {
<thead>
<tr>
<th style="border: 0; color: #29235c; font-size: 22px; text-align: left;">
Data access request application review phase approaching deadline in ${days} days
The deadline is approaching for a Data Access Request application you are reviewing
</th>
</tr>
<tr>
<th style="border: 0; font-size: 14px; font-weight: normal; color: #333333; text-align: left;">
The following data access request application is approaching the review deadline.
The following data access request application is approaching the review deadline of ${moment(
dateDeadline
).format('D MMM YYYY')}.
</th>
</tr>
</thead>
Expand Down Expand Up @@ -939,7 +942,7 @@ const _generateReviewDeadlineWarning = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateSubmitted
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Review phase</td>
Expand All @@ -957,7 +960,7 @@ const _generateReviewDeadlineWarning = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Deadline</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateDeadline
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
</table>
</td>
Expand All @@ -982,7 +985,8 @@ const _generateReviewDeadlinePassed = (options) => {
stepName,
reviewSections,
reviewerNames,
dateSubmitted,
dateSubmitted,
dateDeadline
} = options;
let body = `<div style="border: 1px solid #d0d3d4; border-radius: 15px; width: 700px; margin: 0 auto;">
<table
Expand Down Expand Up @@ -1032,7 +1036,7 @@ const _generateReviewDeadlinePassed = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateSubmitted
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Review phase</td>
Expand All @@ -1050,7 +1054,7 @@ const _generateReviewDeadlinePassed = (options) => {
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Deadline</td>
<td style=" font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(
dateDeadline
).format('D MMM YYYY HH:mm')}</td>
).format('D MMM YYYY')}</td>
</tr>
</table>
</td>
Expand Down Expand Up @@ -1118,7 +1122,7 @@ const _generateFinalDecisionRequiredEmail = (options) => {
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Submitted</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(dateSubmitted).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(dateSubmitted).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Workflow</td>
Expand All @@ -1137,11 +1141,11 @@ const _generateFinalDecisionRequiredEmail = (options) => {
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase commenced</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(startDateTime).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(startDateTime).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase completed</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(endDateTime).format('D MMM YYYY HH:mm')}</td>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 70%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">${moment(endDateTime).format('D MMM YYYY')}</td>
</tr>
<tr>
<td style="font-size: 14px; color: #3c3c3b; padding: 10px 5px; width: 30%; text-align: left; vertical-align: top; border-bottom: 1px solid #d0d3d4;">Phase duration</td>
Expand Down
Loading