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

write journal entry on wps changed because of working day changes

ulfertsa7e3727c9e26
diff --git a/app/workers/work_packages/apply_working_days_change_job.rb b/app/workers/work_packages/apply_working_days_change_job.rb
index 4af64c4f761..5b78169e10a 100644
--- a/app/workers/work_packages/apply_working_days_change_job.rb
+++ b/app/workers/work_packages/apply_working_days_change_job.rb
@@ -32,11 +32,17 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob
def perform(user_id:, previous_working_days:)
user = User.find(user_id)
- each_applicable_work_package(previous_working_days) do |work_package|
- apply_change_to_work_package(user, work_package)
- end
- each_applicable_follows_relation do |relation|
- apply_change_to_relation(user, relation)
+ User.execute_as user do
+ updated_work_packages = []
+
+ each_applicable_work_package(previous_working_days) do |work_package|
+ updated_work_packages += apply_change_to_work_package(user, work_package).all_results
+ end
+ each_applicable_follows_relation do |relation|
+ updated_work_packages += apply_change_to_relation(user, relation)
+ end
+
+ set_journal_notice(updated_work_packages, previous_working_days)
end
end
@@ -55,9 +61,11 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob
.call
# The SetScheduleService does not save. It has to be done by the caller.
- schedule_result.dependent_results.each do |dependent_result|
+ schedule_result.dependent_results.map do |dependent_result|
work_package = dependent_result.result
work_package.save
+
+ work_package
end
end
@@ -90,4 +98,19 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob
yield Relation.find(id)
end
end
+
+ def set_journal_notice(updated_work_packages, previous_working_days)
+ day_changes = changed_days(previous_working_days).index_with { |day| Setting.working_days.include?(day) }
+
+ updated_work_packages.uniq.each do |work_package|
+ changes = day_changes.collect { |day, working| working_day_change_message(day, working) }
+
+ work_package.journal_notes = "Working days changed (#{changes.join(', ')})."
+ work_package.save
+ end
+ end
+
+ def working_day_change_message(day, working)
+ "#{I18n.t('date.day_names')[day]} is now #{working ? 'working' : 'non-working'}"
+ end
end
diff --git a/spec/features/admin/working_days_spec.rb b/spec/features/admin/working_days_spec.rb
index 05744b66587..12d2d933802 100644
--- a/spec/features/admin/working_days_spec.rb
+++ b/spec/features/admin/working_days_spec.rb
@@ -29,6 +29,8 @@
require 'spec_helper'
describe 'Working Days', type: :feature, js: true do
+ create_shared_association_defaults_for_work_package_factory
+
shared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }
shared_let(:admin) { create :admin }
let_schedule(<<~CHART)
@@ -117,12 +119,14 @@ describe 'Working Days', type: :feature, js: true do
[earliest_work_package,
second_work_package,
follower].each do |work_package|
+ expect(work_package.journals.count)
+ .to eq 2
expect(work_package.journals.last.notes)
- .to include("Working days changed")
+ .to include("Working days changed (Monday is now non-working, Friday is now non-working).")
end
end
- it 'shows error when non working days are set' do
+ it 'shows error when non working days are all unset' do
uncheck 'Monday'
uncheck 'Tuesday'
uncheck 'Wednesday'
diff --git a/spec/workers/work_packages/apply_working_days_change_job_spec.rb b/spec/workers/work_packages/apply_working_days_change_job_spec.rb
index c05cc161655..87bd0789b86 100644
--- a/spec/workers/work_packages/apply_working_days_change_job_spec.rb
+++ b/spec/workers/work_packages/apply_working_days_change_job_spec.rb
@@ -39,6 +39,28 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
# This must run before any working days are changed, hence the `let!` form
let!(:previous_working_days) { work_week }
+ shared_examples_for 'journal updates with note' do
+ let(:changed_work_packages) { [] }
+ let(:unchanged_work_packages) { [] }
+ let(:journal_notice) { raise 'need to specify note' }
+
+ it 'adds journal entries to changed work packages' do
+ job.perform_now(user_id: user.id, previous_working_days:)
+
+ changed_work_packages.each do |work_package|
+ expect(work_package.journals.count)
+ .to eq 2
+ expect(work_package.journals.last.notes)
+ .to include(journal_notice)
+ end
+
+ unchanged_work_packages.each do |work_package|
+ expect(work_package.journals.count)
+ .to eq 1
+ end
+ end
+ end
+
context 'when a work package includes a date that is now a non-working day' do
let_schedule(<<~CHART)
days | MTWTFSS |
@@ -65,6 +87,17 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
wp_due_only | ░] ░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [work_package,
+ work_package_on_start,
+ work_package_on_due,
+ wp_start_only,
+ wp_due_only]
+ end
+ let(:journal_notice) { "Working days changed (Wednesday is now non-working)." }
+ end
end
context 'when a work package was scheduled to start on a date that is now a non-working day' do
@@ -85,6 +118,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
work_package | ░XX░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [work_package]
+ end
+ let(:journal_notice) { "Working days changed (Wednesday is now non-working)." }
+ end
end
context 'when a work package includes a date that is no more a non-working day' do
@@ -104,6 +144,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
work_package | XX▓X ░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [work_package]
+ end
+ let(:journal_notice) { "Working days changed (Saturday is now working)." }
+ end
end
context 'when a follower has a predecessor with dates covering a day that is now a non-working day' do
@@ -125,6 +172,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
follower | ░ XXX | working days include weekends
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [predecessor, follower]
+ end
+ let(:journal_notice) { "Working days changed (Wednesday is now non-working)." }
+ end
end
context 'when a follower has a predecessor with delay covering a day that is now a non-working day' do
@@ -146,6 +200,16 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
follower | ░ X░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [follower]
+ end
+ let(:unchanged_work_packages) do
+ [predecessor]
+ end
+ let(:journal_notice) { "Working days changed (Wednesday is now non-working)." }
+ end
end
context 'with work packages without dates following each other with delay' do
@@ -167,6 +231,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
follower | ░ ░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:unchanged_work_packages) do
+ [predecessor, follower]
+ end
+ end
end
context 'when a follower has a predecessor with delay covering multiple days with different working changes' do
@@ -184,19 +254,25 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
it 'correctly handles the changes' do
job.perform_now(user_id: user.id, previous_working_days:)
- expect(WorkPackage.all).to match_schedule(<<~CHART)
+ expect_schedule(WorkPackage.all, <<~CHART)
days | MTWTFSS |
predecessor | X░ ░░ |
follower | ░ X░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:unchanged_work_packages) do
+ [predecessor, follower]
+ end
+ end
end
context 'when a follower has a predecessor with dates covering a day that is now a working day' do
let_schedule(<<~CHART)
- days | MTWTFSS |
- predecessor | X▓X ░░ | working days work week
- follower | ░ XXX | working days include weekends, follows predecessor
+ days | MTWTFSS |
+ predecessor | X▓X ░░ | working days work week
+ follower | ░ XXX | working days include weekends, follows predecessor
CHART
let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }
@@ -206,6 +282,22 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
it 'does not move the follower backwards' do
job.perform_now(user_id: user.id, previous_working_days:)
+
+ expect_schedule(WorkPackage.all, <<~CHART)
+ days | MTWTFSS |
+ predecessor | XX ░░ |
+ follower | XXX |
+ CHART
+ end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [predecessor]
+ end
+ let(:unchanged_work_packages) do
+ [follower]
+ end
+ let(:journal_notice) { "Working days changed (Wednesday is now working)." }
end
end
@@ -229,6 +321,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
follower | XX░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:unchanged_work_packages) do
+ [predecessor, follower]
+ end
+ end
end
context 'when a work package has working days include weekends, and includes a date that is now a non-working day' do
@@ -248,6 +346,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
work_package | XXXX ░░ | working days include weekends
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:unchanged_work_packages) do
+ [work_package]
+ end
+ end
end
context 'when a work package only has a duration' do
@@ -264,6 +368,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
job.perform_now(user_id: user.id, previous_working_days:)
expect(work_package.duration).to eq(3)
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:unchanged_work_packages) do
+ [work_package]
+ end
+ end
end
context 'when having multiple work packages following each other, and having days becoming non working days' do
@@ -290,6 +400,15 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [wp1, wp2, wp3]
+ end
+ let(:journal_notice) do
+ "Working days changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."
+ end
+ end
end
context 'with multiple predecessors for same follower' do
@@ -324,6 +443,15 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
wp3 | ░░ ░░░ ░░X |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [wp1, wp2, wp3]
+ end
+ let(:journal_notice) do
+ "Working days changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."
+ end
+ end
end
context 'when having multiple work packages following each other, and having days becoming working days' do
@@ -350,6 +478,18 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
CHART
expect(WorkPackage.pluck(:lock_version)).to all(be <= 1)
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [wp1, wp3]
+ end
+ let(:unchanged_work_packages) do
+ [wp2]
+ end
+ let(:journal_notice) do
+ "Working days changed (Tuesday is now working, Wednesday is now working, Friday is now working)."
+ end
+ end
end
context 'when having multiple work packages following each other and first one only has a due date' do
@@ -376,5 +516,14 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
wp3 | ░░]░░░ ░░ ░░░ ░░ ░░░ |
CHART
end
+
+ it_behaves_like 'journal updates with note' do
+ let(:changed_work_packages) do
+ [wp1, wp2, wp3]
+ end
+ let(:journal_notice) do
+ "Working days changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."
+ end
+ end
end
end