Bug/58342 creating a project via template sends out mail notifications to all template users #20483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket
https://community.openproject.org/wp/58342
What are you trying to accomplish?
Prevent notifications from being sent sometimes when project is copied with «Send email notifications during the project copy» is unchecked. Why was the bug happening:
ActionMailer::Base.perform_deliveries
was set around call toProjects::CopyService
(usingwith_deliveries
)send_notifications
is used only byBaseContracted
to setJournal::NotificationConfiguration.active?
, for the duration ofperform
and attempts to providesend_notifications
to wrapped service calls are ignored and loggedMembers::CreateService
, assend_notifications
, if set, is also used to overrideJournal::NotificationConfiguration.active?
(Members::Concerns::NotificationSender#send_notifications?
)Members::CreateService
is called for every member fromProjects::Copy::MembersDependentService
and was receivingsend_notifications
explicitly set toActionMailer::Base.perform_deliveries
ActionMailer::Base.perform_deliveries
was set around call toProjects::CopyService
to the desired valueperform_deliveries
is a class attribute, so not thread local and it was set totrue
before every request and job run (bySetting::MailSettings#reload_mailer_settings!
), which was done to ensure email sending configuration is up to date if changed from adminperform_deliveries
was set aroundProjects::CopyService
and beforeProjects::Copy::MembersDependentService
finished,perform_deliveries
was reset totrue
andMembers::CreateService
was called withsend_notifications: true
forcing it to send notifications (andperform_deliveries = true
was allowing them to be sent)What approach did you choose and why?
Stop dynamically setting
perform_deliveries
in the app (as it is a class variable, so not thread local and is reset on every request and job run) and remove explicitly settingsend_notifications
in allProjects::CopyService
dependencies.Merge checklist