mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
get rid of with_deliveries method
It was setting ActionMailer::Base.perform_deliveries for the duration of the block, but perform_deliveries is a class attribute, so not thread local and doesn't work as expected in combination with setting perform_deliveries to true when calling Setting::MailSettings#reload_mailer_settings! at the start of every request and every job run
This commit is contained in:
@@ -45,15 +45,6 @@ class ApplicationMailer < ActionMailer::Base
|
||||
default from: Proc.new { Setting.mail_from }
|
||||
|
||||
class << self
|
||||
# Activates/deactivates email deliveries during +block+
|
||||
def with_deliveries(temporary_state = true, &)
|
||||
old_state = ActionMailer::Base.perform_deliveries
|
||||
ActionMailer::Base.perform_deliveries = temporary_state
|
||||
yield
|
||||
ensure
|
||||
ActionMailer::Base.perform_deliveries = old_state
|
||||
end
|
||||
|
||||
def host
|
||||
if OpenProject::Configuration.rails_relative_url_root.blank?
|
||||
Setting.host_name
|
||||
|
||||
@@ -112,20 +112,16 @@ class CopyProjectJob < ApplicationJob
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# Most of the cost is from handling errors, we need to check what can be moved around / removed
|
||||
def create_project_copy(target_project_params, associations_to_copy, send_mails)
|
||||
errors = []
|
||||
service_result = copy_project(target_project_params, associations_to_copy, send_mails)
|
||||
target_project = service_result.result
|
||||
errors = service_result.errors.full_messages
|
||||
|
||||
ProjectMailer.with_deliveries(send_mails) do
|
||||
service_result = copy_project(target_project_params, associations_to_copy, send_mails)
|
||||
target_project = service_result.result
|
||||
errors = service_result.errors.full_messages
|
||||
|
||||
# We assume the copying worked "successfully" if the project was saved
|
||||
if target_project&.persisted?
|
||||
return target_project, errors
|
||||
else
|
||||
logger.error("Copying project fails with validation errors: #{errors.join("\n")}")
|
||||
return nil, errors
|
||||
end
|
||||
# We assume the copying worked "successfully" if the project was saved
|
||||
if target_project&.persisted?
|
||||
[target_project, errors]
|
||||
else
|
||||
logger.error("Copying project fails with validation errors: #{errors.join("\n")}")
|
||||
[nil, errors]
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
logger.error("Entity missing: #{e.message} #{e.backtrace.join("\n")}")
|
||||
|
||||
@@ -69,40 +69,6 @@ RSpec.describe UserMailer do
|
||||
allow(Setting).to receive(:default_language).and_return("en")
|
||||
end
|
||||
|
||||
describe "#with_deliveries" do
|
||||
context "with false" do
|
||||
before do
|
||||
described_class.with_deliveries(false) do
|
||||
described_class.test_mail(recipient).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "mail is not sent"
|
||||
end
|
||||
|
||||
context "with true" do
|
||||
before do
|
||||
described_class.with_deliveries(true) do
|
||||
described_class.test_mail(recipient).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "mail is sent"
|
||||
end
|
||||
|
||||
context "with true but user is locked" do
|
||||
let(:recipient) { build_stubbed(:user, status: Principal.statuses[:locked]) }
|
||||
|
||||
before do
|
||||
described_class.with_deliveries(true) do
|
||||
described_class.test_mail(recipient).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "mail is not sent"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#test_mail" do
|
||||
let(:test_email) { "bob.bobbi@example.com" }
|
||||
let(:recipient) { build_stubbed(:user, firstname: "Bob", lastname: "Bobbi", mail: test_email) }
|
||||
|
||||
Reference in New Issue
Block a user