FIX: Don’t assume post is available in UserEmail job (#21054)
Currently, we’re performing a check when a user is suspended in the `UserEmail` job and we’re assuming a `post` is always available, which is not the case. The code indeed breaks when the job is called with the `account_suspended` type option. This patch fixes this issue by making the check use the safe navigation operator, thus making it working when `post` is not provided.
This commit is contained in:
parent
dfce983fc7
commit
d151f4ee9d
|
@ -113,7 +113,7 @@ module Jobs
|
|||
if user.suspended?
|
||||
if !type.in?(%w[user_private_message account_suspended])
|
||||
return skip_message(SkippedEmailLog.reason_types[:user_email_user_suspended_not_pm])
|
||||
elsif post.topic.group_pm?
|
||||
elsif post&.topic&.group_pm?
|
||||
return skip_message(SkippedEmailLog.reason_types[:user_email_user_suspended])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -930,5 +930,24 @@ RSpec.describe Jobs::UserEmail do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without post" do
|
||||
context "when user is suspended" do
|
||||
subject(:send_email) do
|
||||
described_class.new.execute(
|
||||
type: :account_suspended,
|
||||
user_id: suspended.id,
|
||||
user_history_id: user_history.id,
|
||||
)
|
||||
end
|
||||
|
||||
let(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:suspend_user]) }
|
||||
|
||||
it "does send an email" do
|
||||
send_email
|
||||
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(suspended.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue