mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: no more sending emails to banned users, + feature flag
This commit is contained in:
@@ -141,6 +141,7 @@
|
||||
"sendValidationEmail": 1,
|
||||
"includeUnverifiedEmails": 0,
|
||||
"emailPrompt": 1,
|
||||
"sendEmailToBanned": 0,
|
||||
"requireEmailAddress": 0,
|
||||
"inviteExpiration": 7,
|
||||
"dailyDigestFreq": "off",
|
||||
|
||||
@@ -43,5 +43,6 @@
|
||||
"include-unverified-emails": "Send emails to recipients who have not explicitly confirmed their emails",
|
||||
"include-unverified-warning": "By default, users with emails associated with their account have already been verified, but there are situations where this is not the case (e.g. SSO logins, grandfathered users, etc). <strong>Enable this setting at your own risk</strong> – sending emails to unverified addresses may be a violation of regional anti-spam laws.",
|
||||
"prompt": "Prompt users to enter or confirm their emails",
|
||||
"prompt-help": "If a user does not have an email set, or their email is not confirmed, a warning will be shown on screen."
|
||||
"prompt-help": "If a user does not have an email set, or their email is not confirmed, a warning will be shown on screen.",
|
||||
"sendEmailToBanned": "Send emails to users even if they have been banned"
|
||||
}
|
||||
|
||||
@@ -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.`);
|
||||
|
||||
@@ -51,6 +51,13 @@
|
||||
</div>
|
||||
<p class="help-block">[[admin/settings/email:prompt-help]]</p>
|
||||
|
||||
<div class="checkbox">
|
||||
<label for="sendEmailToBanned" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" id="sendEmailToBanned" data-field="sendEmailToBanned" name="sendEmailToBanned" />
|
||||
<span class="mdl-switch__label">[[admin/settings/email:sendEmailToBanned]]</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label for="removeEmailNotificationImages" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" id="removeEmailNotificationImages" data-field="removeEmailNotificationImages" name="removeEmailNotificationImages" />
|
||||
|
||||
@@ -8,6 +8,8 @@ const path = require('path');
|
||||
const db = require('./mocks/databasemock');
|
||||
const Plugins = require('../src/plugins');
|
||||
const Emailer = require('../src/emailer');
|
||||
const user = require('../src/user');
|
||||
const meta = require('../src/meta');
|
||||
const Meta = require('../src/meta');
|
||||
|
||||
describe('emailer', () => {
|
||||
@@ -138,4 +140,42 @@ describe('emailer', () => {
|
||||
'email:custom:test': '',
|
||||
}, done);
|
||||
});
|
||||
|
||||
describe('emailer.send()', () => {
|
||||
let senderUid;
|
||||
let recipientUid;
|
||||
|
||||
before(async () => {
|
||||
Plugins.hooks.register('emailer-test', {
|
||||
hook: 'filter:email.send',
|
||||
method: async () => {}, // noop
|
||||
});
|
||||
|
||||
senderUid = await user.create({ username: 'sender' });
|
||||
recipientUid = await user.create({ username: 'recipient', email: 'test@example.org' });
|
||||
await user.email.confirmByUid(recipientUid);
|
||||
});
|
||||
|
||||
it('should return false on attempted email send to a banned user', async () => {
|
||||
await user.bans.ban(recipientUid);
|
||||
const success = await Emailer.send('test', recipientUid, {});
|
||||
assert.strictEqual(success, false);
|
||||
});
|
||||
|
||||
it('should return true if the template is "banned"', async () => {
|
||||
const success = await Emailer.send('banned', recipientUid, {});
|
||||
assert.strictEqual(success, true);
|
||||
});
|
||||
|
||||
it('should return true if system settings allow sending to banned users', async () => {
|
||||
meta.config.sendEmailToBanned = 1;
|
||||
const success = await Emailer.send('test', recipientUid, {});
|
||||
assert.strictEqual(success, true);
|
||||
meta.config.sendEmailToBanned = 0;
|
||||
});
|
||||
|
||||
after(() => {
|
||||
Plugins.hooks.unregister('emailer-test', 'filter:email.send');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user