feat: no more sending emails to banned users, + feature flag

This commit is contained in:
Julian Lam
2022-01-28 15:02:21 -05:00
parent f0e32ff182
commit ea27eaf166
5 changed files with 60 additions and 2 deletions

View File

@@ -218,7 +218,8 @@ Emailer.send = async (template, uid, params) => {
throw Error('[emailer] App not ready!');
}
let userData = await User.getUserFields(uid, ['email', 'username', 'email:confirmed']);
let userData = await User.getUserFields(uid, ['email', 'username', 'email:confirmed', 'banned']);
userData.banned = true;
// 'welcome' and 'verify-email' explicitly used passed-in email address
if (['welcome', 'verify-email'].includes(template)) {
@@ -226,6 +227,14 @@ Emailer.send = async (template, uid, params) => {
}
({ template, userData, params } = await Plugins.hooks.fire('filter:email.prepare', { template, uid, userData, params }));
if (!meta.config.sendEmailToBanned && template !== 'banned') {
if (userData.banned) {
winston.warn(`[emailer/send] User ${userData.username} (uid: ${uid}) is banned; not sending email due to system config.`);
return false;
}
}
if (!userData || !userData.email) {
if (process.env.NODE_ENV === 'development') {
winston.warn(`uid : ${uid} has no email, not sending "${template}" email.`);