FIX: Do not send system emails to suspended users (#10192)

This commit is contained in:
Penar Musaraj 2020-07-08 13:30:32 -04:00 committed by GitHub
parent 90512d723c
commit 67582e7d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -220,7 +220,7 @@ module Jobs
return SkippedEmailLog.reason_types[:user_email_post_deleted]
end
if user.suspended? && !post.user&.staff?
if user.suspended? && (!post.user&.staff? || !post.user&.human?)
return SkippedEmailLog.reason_types[:user_email_user_suspended]
end

View File

@ -326,6 +326,26 @@ describe Jobs::UserEmail do
suspended.email
)
end
it "doesn't send PM from system user" do
pm_from_system = SystemMessage.create(suspended, :unsilenced)
system_pm_notification = Fabricate(:notification,
user: suspended,
topic: pm_from_system.topic,
post_number: pm_from_system.post_number,
data: { original_post_id: pm_from_system.id }.to_json
)
Jobs::UserEmail.new.execute(
type: :user_private_message,
user_id: suspended.id,
post_id: pm_from_system.id,
notification_id: system_pm_notification.id
)
expect(ActionMailer::Base.deliveries).to eq([])
end
end
context 'user is anonymous' do