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

enable default notifications on project copy

ulfertse6e5f9caab6c
diff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rb
index cb37d14c4e1..7f6dba38dff 100644
--- a/app/services/base_services/copy.rb
+++ b/app/services/base_services/copy.rb
@@ -91,12 +91,6 @@ module BaseServices
protected
- ##
- # Disabling sending regular notifications
- def service_context(*, &)
- in_context(model, send_notifications: false, &)
- end
-
##
# Should the dependency be skipped for this service run?
def skip_dependency?(_params, _dependency_cls)
diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb
index 53583a4dd97..75aae3cc35a 100644
--- a/app/workers/copy_project_job.rb
+++ b/app/workers/copy_project_job.rb
@@ -154,7 +154,7 @@ class CopyProjectJob < ApplicationJob
end
def copy_project_params
- params = { target_project_params: }
+ params = { target_project_params:, send_notifications: send_mails }
params[:only] = associations_to_copy if associations_to_copy.present?
params
diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb
index 1a2271fd46d..4855330662e 100644
--- a/spec/services/projects/copy_service_integration_spec.rb
+++ b/spec/services/projects/copy_service_integration_spec.rb
@@ -609,8 +609,14 @@ describe Projects::CopyService, 'integration', type: :model do
end
describe 'assigned_to' do
+ let(:assigned_user) do
+ create(:user,
+ member_in_project: source,
+ member_through_role: role)
+ end
+
before do
- work_package.update_column(:assigned_to_id, current_user.id)
+ work_package.update_column(:assigned_to_id, assigned_user.id)
end
context 'with the members being copied' do
@@ -618,9 +624,13 @@ describe Projects::CopyService, 'integration', type: :model do
it 'copies the assigned_to' do
expect(subject).to be_success
- expect(project_copy.users).to include current_user
expect(project_copy.work_packages[0].assigned_to)
- .to eql current_user
+ .to eql assigned_user
+ # The assignee of the new work package receives a notification
+ expect { perform_enqueued_jobs }
+ .to change(Notification.where(recipient: assigned_user), :count)
+ .from(0)
+ .to(1)
end
end
@@ -631,13 +641,22 @@ describe Projects::CopyService, 'integration', type: :model do
expect(subject).to be_success
expect(project_copy.work_packages[0].assigned_to)
.to be_nil
+ # No notification is sent out
+ expect { perform_enqueued_jobs }
+ .not_to change(Notification.where(recipient: assigned_user), :count)
end
end
end
describe 'responsible' do
+ let(:responsible_user) do
+ create(:user,
+ member_in_project: source,
+ member_through_role: role)
+ end
+
before do
- work_package.update_column(:responsible_id, current_user.id)
+ work_package.update_column(:responsible_id, responsible_user.id)
end
context 'with the members being copied' do
@@ -645,9 +664,13 @@ describe Projects::CopyService, 'integration', type: :model do
it 'copies the responsible' do
expect(subject).to be_success
- expect(project_copy.users).to include current_user
expect(project_copy.work_packages[0].responsible)
- .to eql current_user
+ .to eql responsible_user
+ # The responsible of the new work package receives a notification
+ expect { perform_enqueued_jobs }
+ .to change(Notification.where(recipient: responsible_user), :count)
+ .from(0)
+ .to(1)
end
end
@@ -658,6 +681,9 @@ describe Projects::CopyService, 'integration', type: :model do
expect(subject).to be_success
expect(project_copy.work_packages[0].responsible)
.to be_nil
+ # No notification is sent out
+ expect { perform_enqueued_jobs }
+ .not_to change(Notification.where(recipient: responsible_user), :count)
end
end
end