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

prevent author watcher on work package copy

ulfertsf4d01e37aa7e
diff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rb
index 119a55ae204..f6a2c840ecd 100644
--- a/app/services/work_packages/copy_service.rb
+++ b/app/services/work_packages/copy_service.rb
@@ -56,6 +56,7 @@ class WorkPackages::CopyService
copied = create(attributes, send_notifications)
if copied.success?
+ remove_author_watcher(copied.result)
copy_watchers(copied.result)
end
@@ -84,6 +85,10 @@ class WorkPackages::CopyService
instantiate_contract(wp, user).writable_attributes
end
+ def remove_author_watcher(copied)
+ copied.remove_watcher(copied.author)
+ end
+
def copy_watchers(copied)
work_package.watcher_users.each do |user|
copied.add_watcher(user) if user.active?
diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb
index 32ff5f17d35..70b0b0d602d 100644
--- a/spec/services/projects/copy_service_integration_spec.rb
+++ b/spec/services/projects/copy_service_integration_spec.rb
@@ -482,10 +482,10 @@ describe Projects::CopyService, 'integration', type: :model do
source.work_packages << wp
end
- it 'does copy active watchers' do
+ it 'does copy active watchers but does not add the copying user as a watcher' do
expect(subject).to be_success
expect(project_copy.work_packages[0].watcher_users)
- .to match_array([current_user, watcher])
+ .to match_array([watcher])
end
end
@@ -501,9 +501,9 @@ describe Projects::CopyService, 'integration', type: :model do
source.work_packages << wp
end
- it 'does not copy locked watchers but adds the copying user as a watcher' do
+ it 'does not copy locked watchers and does not add the copying user as a watcher' do
expect(subject).to be_success
- expect(project_copy.work_packages[0].watcher_users).to eq([current_user])
+ expect(project_copy.work_packages[0].watcher_users).to be_empty
end
end
diff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rb
index bfa8c2a5101..291b2600946 100644
--- a/spec/services/work_packages/copy_service_integration_spec.rb
+++ b/spec/services/work_packages/copy_service_integration_spec.rb
@@ -84,14 +84,31 @@ describe WorkPackages::CopyService, 'integration', type: :model do
it { is_expected.not_to eq(work_package.id) }
end
- describe 'to the same project' do
+ context 'with the same project' do
it_behaves_like 'copied work package'
- context 'project' do
+ describe '#project' do
subject { copy.project }
it { is_expected.to eq(source_project) }
end
+
+ describe 'copied watchers' do
+ let(:watcher_user) do
+ FactoryBot.create(:user,
+ member_in_project: source_project,
+ member_with_permissions: %i(view_work_packages))
+ end
+
+ before do
+ work_package.add_watcher(watcher_user)
+ end
+
+ it 'copies the watcher and does not add the copying user as a watcher' do
+ expect(copy.watcher_users)
+ .to match_array([watcher_user])
+ end
+ end
end
describe 'to a different project' do