Skip to content

Commit

Permalink
Fix/submission emails (responsible-ai-collaborative#2405)
Browse files Browse the repository at this point in the history
* Only send email to the submitter of that particular issue

* Fix editor filter

* Fix test for pending submissions
  • Loading branch information
clari182 authored Nov 13, 2023
1 parent 20f6e64 commit a2931a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,14 @@ const stubEverything = () => {
.returns({ toArray: () => subscriptionsToIncidentUpdates });
}

const incidentIds = pendingNotificationsToPromotedIncidents.map(
(pendingNotification) => pendingNotification.incident_id
);

stub
.withArgs({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: incidentIds },
})
.as(`subscriptions.find("${SUBSCRIPTION_TYPE.submissionPromoted}")`)
.returns({ toArray: () => subscriptionsToPromotedIncidents });
Expand Down Expand Up @@ -450,6 +455,7 @@ describe('Functions', () => {

expect(subscriptionsCollection.find.getCall(5).args[0]).to.deep.equal({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: [217] },
});

for (const subscription of subscriptionsToPromotedIncidents) {
Expand All @@ -465,8 +471,6 @@ describe('Functions', () => {
incident_id: pendingNotification.incident_id,
});

console.log('subscriptionsToPromotedIncidents', global.context.functions);

const userIds = subscriptionsToPromotedIncidents.map((subscription) => subscription.userId);

const incident = incidents.find((i) => i.incident_id == pendingNotification.incident_id);
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function CiteTemplate({
reportCount: sortedReports.length,
incidentDate: incident.date,
editors: incident.editors
.filter((editor) => editor && editor.first_name && editor.last_name)
.map(({ first_name, last_name }) => `${first_name} ${last_name}`)
.join(', '),
}}
Expand Down
10 changes: 8 additions & 2 deletions site/realm/functions/processNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getRecipients = async (userIds) => {
for (const userId of userIds) {
const userResponse = await context.functions.execute('getUser', { userId });

if (userResponse.email) {
if (userResponse?.email) {
recipients.push({
email: userResponse.email,
userId,
Expand Down Expand Up @@ -262,13 +262,19 @@ exports = async function () {

// Notifications to New Promotions
try {

// Finds all pending notifications to New Promotions
const pendingNotificationsToNewPromotions = await notificationsCollection.find({ processed: false, type: 'submission-promoted' }).toArray();

// Gets all incident ids from pending notifications to New Promotions
const pendingNotificationsIncidentIds = pendingNotificationsToNewPromotions.map((notification) => notification.incident_id);

if (pendingNotificationsToNewPromotions.length > 0) {

result += pendingNotificationsToNewPromotions.length;

const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted' }).toArray();
// Finds all subscriptions to New Promotions for those new incidents
const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted', incident_id: { $in: pendingNotificationsIncidentIds } }).toArray();

// Process subscriptions to New Incidents
if (subscriptionsToNewPromotions.length > 0) {
Expand Down

0 comments on commit a2931a5

Please sign in to comment.