Skip to content

Comments

PM- 3351 Send notifications to resources on manual phase change#70

Open
himaniraghav3 wants to merge 18 commits intodevelopfrom
PM-3351
Open

PM- 3351 Send notifications to resources on manual phase change#70
himaniraghav3 wants to merge 18 commits intodevelopfrom
PM-3351

Conversation

@himaniraghav3
Copy link
Collaborator

Sends notification to resources on a challenge when phase is changed manually

https://topcoder.atlassian.net/browse/PM-3351


/**
* Build payload for phase change email notification
* @param {String} challenge Id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 maintainability]
The JSDoc comment for buildPhaseChangeEmailData has incorrect parameter names. The parameters should match the destructured object properties: challengeId, challengeName, phaseName, operation, and at.

*/
async function sendPhaseChangeNotification(type, recipients, data) {
try {
const settings = constants.PhaseChangeNotificationSettings?.[type];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The optional chaining operator ?. is used with constants.PhaseChangeNotificationSettings?.[type]. Ensure that constants.PhaseChangeNotificationSettings is always defined to avoid potential runtime errors.

);
return;
}
const safeRecipients = Array.isArray(recipients) ? recipients.filter(Boolean) : [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 maintainability]
The safeRecipients array is created by filtering out falsy values. Consider logging or handling cases where recipients are filtered out to ensure no unintended omissions.

],
});
} catch (e) {
logger.debug(`Failed to post notification ${type}: ${e.message}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The catch block logs the error message but does not rethrow the error or handle it in a way that would alert the caller of the failure. Consider rethrowing the error or handling it to ensure the caller is aware of the failure.

at,
});

await helper.sendPhaseChangeNotification(notificationType, recipients, payload);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
Consider adding error handling for helper.sendPhaseChangeNotification. Currently, if this function fails, it will not be logged or handled, which could lead to silent failures in sending notifications.

async function sendSelfServiceNotification(type, recipients, data) {
try {
await postBusEvent(constants.Topics.Notifications, {
await postBusEvent(constants.Topics.ChallengePhaseUpdated, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The change from constants.Topics.Notifications to constants.Topics.ChallengePhaseUpdated alters the topic of the event being posted. Ensure that this change aligns with the intended behavior and that all consumers of this event are updated accordingly to handle the new topic. This could impact systems relying on the previous topic.

async function sendSelfServiceNotification(type, recipients, data) {
try {
await postBusEvent(constants.Topics.Notifications, {
await postBusEvent('external.action.email', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The topic for the bus event has been changed from constants.Topics.ChallengePhaseUpdated to 'external.action.email'. Ensure that this change aligns with the intended functionality and that all dependent systems are updated accordingly. If this is not intentional, it could lead to incorrect event handling.

await postBusEvent('external.action.email',
{
from: config.EMAIL_FROM,
replyTo: config.EMAIL_FROM,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ design]
The replyTo field is set to config.EMAIL_FROM. Ensure that this is the intended behavior, as it might be more appropriate to have a separate configuration for the reply-to address to avoid potential issues with email replies.

from: config.EMAIL_FROM,
replyTo: config.EMAIL_FROM,
recipients: safeRecipients,
data: data,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ security]
The data object is being passed directly without any transformation or validation. Consider validating or sanitizing the data object to prevent potential security issues, such as injection attacks.

return;
}

await postBusEvent('external.action.email',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The removal of detailed logging statements might hinder debugging and monitoring capabilities. Consider retaining some level of logging to track the flow and data involved in the notification process.

* @param {String} challenge name
* @param {String} challenge phase name
* @param {String} operation to be performed on the phase - open | close | reopen
* @param {String|Date} at - The date/time when the phase opened/closed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The parameter at is documented as String|Date, but the function buildPhaseChangeEmailData does not validate or convert the at parameter to ensure it is a Date object. Consider adding validation or conversion logic to handle cases where at is a string to avoid potential issues with date formatting or operations.

/**
* Send phase change notification
* @param {String} type the notification type
* @param {Array} recipients the array of recipients emails

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The updated documentation for recipients specifies it as an array of emails, but the function sendPhaseChangeNotification does not validate the email format. Consider adding validation to ensure all elements in the recipients array are valid email addresses to prevent potential errors in email delivery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant