Fixed alert notifications being sent out to non-active users

refs https://linear.app/tryghost/issue/CORE-63/restrict-update-service-notifications-to-active-admins

- It only makes sense to notify active users about a notification of 'alert' or any other type really.
This commit is contained in:
Naz 2021-10-06 22:31:06 +02:00
parent b29f519857
commit 20fc1649f4
2 changed files with 22 additions and 8 deletions

View File

@ -297,7 +297,8 @@ class UpdateCheckService {
debug(`creating custom notifications for ${notification.messages.length} notifications`);
const {users} = await this.api.users.browse(Object.assign({
limit: 'all',
include: ['roles']
include: ['roles'],
filter: 'status:active'
}, internal));
const adminEmails = users

View File

@ -209,6 +209,13 @@ describe('Update Check', function () {
};
const notificationsAPIAddStub = sinon.stub().resolves();
const usersBrowseStub = sinon.stub().resolves({
users: [{
roles: [{
name: 'Owner'
}]
}]
});
const updateCheckService = new UpdateCheckService({
api: {
@ -217,13 +224,7 @@ describe('Update Check', function () {
edit: settingsStub
},
users: {
browse: sinon.stub().resolves({
users: [{
roles: [{
name: 'Owner'
}]
}]
})
browse: usersBrowseStub
},
posts: {
browse: sinon.stub().resolves()
@ -254,6 +255,18 @@ describe('Update Check', function () {
targetNotification.top.should.eql(notification.messages[0].top);
targetNotification.type.should.eql('info');
targetNotification.message.should.eql(notification.messages[0].content);
usersBrowseStub.calledTwice.should.eql(true);
// Second (non statistical) call should be looking for admin users with an 'active' status only
usersBrowseStub.args[1][0].should.eql({
limit: 'all',
include: ['roles'],
filter: 'status:active',
context: {
internal: true
}
});
});
it('should send an email for critical notification', async function () {