Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

include member mails when disabling notifications on project copy

ulferts19d1175d03f3
diff --git a/app/services/members/create_service.rb b/app/services/members/create_service.rb
index 50874021579..efe43ad9e1c 100644
--- a/app/services/members/create_service.rb
+++ b/app/services/members/create_service.rb
@@ -47,7 +47,8 @@ class Members::CreateService < ::BaseServices::Create
def send_notification(member)
OpenProject::Notifications.send(OpenProject::Events::MEMBER_CREATED,
member: member,
- message: params[:notification_message])
+ message: params[:notification_message],
+ send_notifications: params.fetch(:send_notifications, true))
end
def add_group_memberships(member)
@@ -59,6 +60,6 @@ class Members::CreateService < ::BaseServices::Create
end
def set_attributes_params(params)
- super.except(:notification_message)
+ super.except(:notification_message, :send_notifications)
end
end
diff --git a/app/services/projects/copy/members_dependent_service.rb b/app/services/projects/copy/members_dependent_service.rb
index 23badb79091..c7e690a60c1 100644
--- a/app/services/projects/copy/members_dependent_service.rb
+++ b/app/services/projects/copy/members_dependent_service.rb
@@ -57,7 +57,11 @@ module Projects::Copy
attributes = member
.attributes.dup.except('id', 'project_id', 'created_at', 'updated_at')
- .merge(role_ids: role_ids, project: target)
+ .merge(role_ids: role_ids,
+ project: target,
+ # This is magic for now. The settings has been set before in the Projects::CopyService
+ # It would be better if this was not sneaked in but rather passed in as a parameter.
+ send_notifications: ActionMailer::Base.perform_deliveries)
Members::CreateService
.new(user: User.current, contract_class: EmptyContract)
diff --git a/config/initializers/subscribe_listeners.rb b/config/initializers/subscribe_listeners.rb
index 9152de761a4..9a6e6cecc76 100644
--- a/config/initializers/subscribe_listeners.rb
+++ b/config/initializers/subscribe_listeners.rb
@@ -57,6 +57,8 @@ OpenProject::Notifications.subscribe(OpenProject::Events::WATCHER_REMOVED) do |p
end
OpenProject::Notifications.subscribe(OpenProject::Events::MEMBER_CREATED) do |payload|
+ next unless payload[:send_notifications]
+
Mails::MemberCreatedJob
.perform_later(current_user: User.current,
member: payload[:member],
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index 77e0515fd2f..1f743a0bd2a 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -142,6 +142,10 @@ describe 'Projects copy',
editor = ::Components::WysiwygEditor.new "[data-qa-field-name='customField#{project_custom_field.id}']"
editor.expect_value 'some text cf'
+ # Deactivate sending of mails during copying
+ click_on 'Copy options'
+ uncheck 'Send email notifications during the project copy'
+
click_button 'Save'
expect(page).to have_text 'The job has been queued and will be processed shortly.'
@@ -155,7 +159,7 @@ describe 'Projects copy',
.to be_present
# Will redirect to the new project automatically once the copy process is done
- expect(page).to have_current_path("#{project_path(copied_project)}/")
+ expect(page).to have_current_path(Regexp.new("#{project_path(copied_project)}/?"))
copied_settings_page = Pages::Projects::Settings.new(copied_project)
copied_settings_page.visit!
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb
index 127ddeff204..2ef203d2e78 100644
--- a/spec/services/members/create_service_spec.rb
+++ b/spec/services/members/create_service_spec.rb
@@ -34,7 +34,13 @@ require 'services/base_services/behaves_like_create_service'
describe Members::CreateService, type: :model do
it_behaves_like 'BaseServices create service' do
let(:call_attributes) do
- { project_id: "1", user_id: "2", role_ids: ["2"], notification_message: "Wish you where **here**." }
+ {
+ project_id: "1",
+ user_id: "2",
+ role_ids: ["2"],
+ notification_message: "Wish you where **here**.",
+ send_notifications: true
+ }
end
let!(:allow_notification_call) do
@@ -48,7 +54,8 @@ describe Members::CreateService, type: :model do
.to receive(:send)
.with(OpenProject::Events::MEMBER_CREATED,
member: model_instance,
- message: call_attributes[:notification_message])
+ message: call_attributes[:notification_message],
+ send_notifications: true)
subject
end