Skip to content

Commit 2aa56f9

Browse files
author
Vikas Agarwal
committed
Github issue370, Do NOT send emails to inactive users
— Fixed, not sending emails now for inactive users. Ideally, we should not have generated the notification for inactive users, however, that requires querying all target users details when generating notifications and we are not doing that right now. So differing that change for now and instead putting a safe guard for sending emails. It would be helpful in cases where user is made inactive between notification generation and actual email sending.
1 parent d41ccbb commit 2aa56f9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

connect/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
// email service id for settings
1212
SETTINGS_EMAIL_SERVICE_ID: 'email',
1313
SETTINGS_EMAIL_BUNDLING_SERVICE_ID: 'emailBundling',
14+
ACTIVE_USER_STATUSES: ['ACTIVE'],
1415

1516
BUS_API_EVENT: {
1617
CONNECT: {

connect/notificationServices/email.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
BUS_API_EVENT,
1515
SCHEDULED_EVENT_PERIOD,
1616
SETTINGS_EMAIL_SERVICE_ID,
17-
SETTINGS_EMAIL_BUNDLING_SERVICE_ID
17+
ACTIVE_USER_STATUSES
1818
} = require('../constants');
1919
const { EVENTS, EVENT_BUNDLES } = require('../events-config');
2020
const helpers = require('../helpers');
@@ -200,12 +200,20 @@ function handler(topicName, messageJSON, notification) {
200200
}
201201

202202
const users = yield service.getUsersById([notification.userId]);
203-
logger.debug(`got users ${JSON.stringify(users)}`);
203+
logger.verbose(`got users ${JSON.stringify(users)}`);
204204

205-
const user = users[0];
206-
let userEmail = user.email;
205+
const user = users && users.length > 0 ? users[0] : null;
206+
let userEmail = _.get(user, 'email');
207207
if (!userEmail) {
208208
logger.error(`Email not received for user: ${user.id}`);
209+
return;
210+
}
211+
const userStatus = _.get(user, 'status');
212+
// don't send email notification for inactive users, ideally we should not have generated
213+
// notifications for inactive users, however, for now handling it here as safe gaurd
214+
if (userStatus && ACTIVE_USER_STATUSES.indexOf(userStatus) === -1) {
215+
logger.error(`Notification generated for inactive user, ignoring`);
216+
return;
209217
}
210218
if (config.ENABLE_DEV_MODE === 'true') {
211219
userEmail = config.DEV_MODE_EMAIL;

connect/service.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const getUsersById = (ids) => {
8989
})
9090
.then((token) => {
9191
return request
92-
.get(`${config.TC_API_V3_BASE_URL}/members/_search?fields=userId,email,handle,firstName,lastName,photoURL&query=${query}`)
92+
.get(`${config.TC_API_V3_BASE_URL}/members/_search?fields=userId,email,handle,firstName,lastName,photoURL,status&query=${query}`)
9393
.set('accept', 'application/json')
9494
.set('authorization', `Bearer ${token}`)
9595
.then((res) => {

0 commit comments

Comments
 (0)