diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index 1197499c417..20edc252c92 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -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 diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index e6def350b2f..0c228776ec1 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -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