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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[15328] Use better messages for progress calculation adjustments
Christophe Bliardeedaafacee43
diff --git a/app/workers/work_packages/update_progress_job.rb b/app/workers/work_packages/update_progress_job.rbindex aee74fe0955..929f0df263d 100644--- a/app/workers/work_packages/update_progress_job.rb+++ b/app/workers/work_packages/update_progress_job.rb@@ -30,31 +30,16 @@class WorkPackages::UpdateProgressJob < ApplicationJobqueue_with_priority :default+ attr_reader :current_mode, :previous_mode+def perform(current_mode:, previous_mode:)- with_temporary_progress_table do- case current_mode- when "field"- unset_all_percent_complete_values if previous_mode == "disabled"- fix_remaining_work_set_with_100p_complete- fix_remaining_work_exceeding_work- fix_only_work_being_set- fix_only_remaining_work_being_set- derive_unset_remaining_work_from_work_and_p_complete- derive_unset_work_from_remaining_work_and_p_complete- derive_p_complete_from_work_and_remaining_work- when "status"- set_p_complete_from_status- fix_remaining_work_set_with_100p_complete- derive_unset_work_from_remaining_work_and_p_complete- derive_remaining_work_from_work_and_p_complete- else- raise "Unknown progress calculation mode: #{current_mode}, aborting."- end+ @current_mode = current_mode+ @previous_mode = previous_mode+ with_temporary_progress_table do+ adjust_progress_valuesupdate_totals-unset_total_p_complete-copy_progress_values_to_work_packages_and_update_journalsendend@@ -70,6 +55,27 @@ class WorkPackages::UpdateProgressJob < ApplicationJobendend+ def adjust_progress_values+ case current_mode+ when "field"+ unset_all_percent_complete_values if previous_mode == "disabled"+ fix_remaining_work_set_with_100p_complete+ fix_remaining_work_exceeding_work+ fix_only_work_being_set+ fix_only_remaining_work_being_set+ derive_unset_remaining_work_from_work_and_p_complete+ derive_unset_work_from_remaining_work_and_p_complete+ derive_p_complete_from_work_and_remaining_work+ when "status"+ set_p_complete_from_status+ fix_remaining_work_set_with_100p_complete+ derive_unset_work_from_remaining_work_and_p_complete+ derive_remaining_work_from_work_and_p_complete+ else+ raise "Unknown progress calculation mode: #{current_mode}, aborting."+ end+ end+def create_temporary_progress_tableexecute(<<~SQL)CREATE UNLOGGED TABLE temp_wp_progress_values@@ -290,10 +296,19 @@ class WorkPackages::UpdateProgressJob < ApplicationJobenddef create_journals_for_updated_work_packages(updated_work_package_ids)+ cause = { type: "system_update", feature: system_update_explanation }WorkPackage.where(id: updated_work_package_ids).find_each do |work_package|Journals::CreateService.new(work_package, system_user)- .call(cause: { type: "system_update", feature: "progress_calculation_changed" })+ .call(cause:)+ end+ end++ def system_update_explanation+ if previous_mode == "disabled"+ "progress_calculation_adjusted_from_disabled_mode"+ else+ "progress_calculation_adjusted"endenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex e0456db55de..a6e519a9eca 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1761,8 +1761,10 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}file_links_journal: >From now on, activity related to file links (files stored in external storages) will appear here in theActivity tab. The following represent activity concerning links that already existed:- progress_calculation_changed: >- Progress calculation updated.+ progress_calculation_adjusted_from_disabled_mode: >-+ Progress calculation automatically <a href="%{href}" target="_blank">set to work-based mode and adjusted with version update</a>.+ progress_calculation_adjusted: >-+ Progress calculation automatically <a href="%{href}" target="_blank">adjusted with version update</a>.links:configuration_guide: "Configuration guide"diff --git a/lib/open_project/journal_formatter/cause.rb b/lib/open_project/journal_formatter/cause.rbindex 88af8990230..85c9275bc79 100644--- a/lib/open_project/journal_formatter/cause.rb+++ b/lib/open_project/journal_formatter/cause.rb@@ -61,7 +61,7 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Basedef cause_description(cause, html)case cause["type"]when "system_update"- system_update_message(cause)+ system_update_message(cause, html)when "working_days_changed"working_days_changed_message(cause["changed_days"])when "status_p_complete_changed"@@ -73,8 +73,20 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Baseendend- def system_update_message(cause)- I18n.t("journals.cause_descriptions.system_update.#{cause['feature']}")+ def system_update_message(cause, html)+ feature = cause["feature"]+ feature = "progress_calculation_adjusted" if feature == "progress_calculation_changed"++ options =+ case feature+ when "progress_calculation_adjusted_from_disabled_mode",+ "progress_calculation_adjusted"+ { href: OpenProject::Static::Links.links[:blog_article_progress_changes][:href] }+ else+ {}+ end+ message = I18n.t("journals.cause_descriptions.system_update.#{feature}", **options)+ html ? message : Sanitize.fragment(message)enddef working_days_changed_message(changed_dates)diff --git a/lib/open_project/static/links.rb b/lib/open_project/static/links.rbindex 5bdddd6f1b5..30650d602d7 100644--- a/lib/open_project/static/links.rb+++ b/lib/open_project/static/links.rb@@ -169,6 +169,10 @@ module OpenProjecthref: "https://www.openproject.org/blog",label: "homescreen.links.blog"},+ blog_article_progress_changes: {+ href: "https://www.openproject.org/blog/changes-progress-work-estimates/",+ label: "Significant changes to progress and work estimates"+ },release_notes: {href: "https://www.openproject.org/docs/release-notes/",label: :label_release_notesdiff --git a/spec/lib/journal_formatter/cause_spec.rb b/spec/lib/journal_formatter/cause_spec.rbindex 1718a08d85a..8fc65d0cb15 100644--- a/spec/lib/journal_formatter/cause_spec.rb+++ b/spec/lib/journal_formatter/cause_spec.rb@@ -359,6 +359,77 @@ RSpec.describe OpenProject::JournalFormatter::Cause doendend+ context "when cause is a system update: change of progress calculation mode from disabled to work-based" do+ let(:cause) do+ {+ "type" => "system_update",+ "feature" => "progress_calculation_adjusted_from_disabled_mode"+ }+ end++ context "when rendering HTML variant" do+ let(:html) { true }++ it do+ href = OpenProject::Static::Links.links[:blog_article_progress_changes][:href]+ expect(subject).to eq "<strong>OpenProject system update:</strong> Progress calculation automatically " \+ "<a href=\"#{href}\">set to work-based mode and adjusted with version update</a>."+ end+ end++ context "when rendering raw variant" do+ let(:html) { false }++ it do+ expect(subject).to eq "OpenProject system update: Progress calculation automatically " \+ "set to work-based mode and adjusted with version update."+ end+ end+ end++ context "when cause is a system update: progress calculation adjusted" do+ let(:cause) do+ {+ "type" => "system_update",+ "feature" => "progress_calculation_adjusted"+ }+ end++ context "when rendering HTML variant" do+ let(:html) { true }++ it do+ href = OpenProject::Static::Links.links[:blog_article_progress_changes][:href]+ expect(subject).to eq "<strong>OpenProject system update:</strong> Progress calculation automatically " \+ "<a href=\"#{href}\">adjusted with version update</a>."+ end+ end++ context "when rendering raw variant" do+ let(:html) { false }++ it do+ expect(subject).to eq "OpenProject system update: Progress calculation automatically " \+ "adjusted with version update."+ end+ end++ context "with previous feature key 'progress_calculation_changed'" do+ let(:cause) do+ {+ "type" => "system_update",+ "feature" => "progress_calculation_changed"+ }+ end+ let(:html) { false }++ it "is rendered like 'progress_calculation_adjusted'" do+ expect(subject).to eq "OpenProject system update: Progress calculation automatically " \+ "adjusted with version update."+ end+ end+ end+context "when the change was caused by a system update" dolet(:cause) do{diff --git a/spec/migrations/update_progress_calculation_spec.rb b/spec/migrations/update_progress_calculation_spec.rbindex e5cccd2cb1f..f4d3a6df227 100644--- a/spec/migrations/update_progress_calculation_spec.rb+++ b/spec/migrations/update_progress_calculation_spec.rb@@ -91,7 +91,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doexpect(wp_parent_consistent.last_journal.get_changes).to include("derived_done_ratio" => [nil, 60],- "cause" => [nil, { "feature" => "progress_calculation_changed", "type" => "system_update" }])+ "cause" => [nil, { "feature" => "progress_calculation_adjusted", "type" => "system_update" }])endend@@ -163,7 +163,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp_only_pc_set = work_packages.firstexpect(wp_only_pc_set.last_journal.details).to include("done_ratio" => [60, nil])expect(wp_only_pc_set.last_journal.cause).to eq("type" => "system_update",- "feature" => "progress_calculation_changed")+ "feature" => "progress_calculation_adjusted_from_disabled_mode")endcontext "when all unset" do@@ -290,6 +290,26 @@ RSpec.describe UpdateProgressCalculation, type: :model doSetting.work_package_done_ratio = "field"end+ it "creates a journal entry for modified work packages to indicate that progress calculation was updated" do+ work_package_adjusted, work_package_not_adjusted = expect_migrates(+ from: <<~TABLE,+ subject | work | remaining work | % complete+ work package adjusted | 10h | |+ work package not adjusted | 10h | 10h | 0%+ TABLE+ to: <<~TABLE+ subject | work | remaining work | % complete+ work package adjusted | 10h | 10h | 0%+ work package not adjusted | 10h | 10h | 0%+ TABLE+ )+ expect(work_package_adjusted.journals.count).to eq(2)+ expect(work_package_adjusted.last_journal.cause)+ .to eq("type" => "system_update",+ "feature" => "progress_calculation_adjusted")+ expect(work_package_not_adjusted.journals.count).to eq(1)+ end+context "when all unset" doit "does nothing and everything is still unset" doexpect_migrates(@@ -528,6 +548,26 @@ RSpec.describe UpdateProgressCalculation, type: :model doSetting.work_package_done_ratio = "status"end+ it "creates a journal entry for modified work packages to indicate that progress calculation was updated" do+ wp_adjusted, wp_not_adjusted = expect_migrates(+ from: <<~TABLE,+ subject | status | work | remaining work | % complete+ wp adjusted | Done (100%) | 10h | |+ wp not adjusted | Done (100%) | 10h | 0h | 100%+ TABLE+ to: <<~TABLE+ subject | status | work | remaining work | % complete+ wp adjusted | Done (100%) | 10h | 0h | 100%+ wp not adjusted | Done (100%) | 10h | 0h | 100%+ TABLE+ )+ expect(wp_adjusted.journals.count).to eq(2)+ expect(wp_adjusted.last_journal.cause)+ .to eq("type" => "system_update",+ "feature" => "progress_calculation_adjusted")+ expect(wp_not_adjusted.journals.count).to eq(1)+ end+context "when only % Complete is set, and is the same as its status" doit "does nothing, the % Complete value is kept, work and remaining work are kept unset, and no journal is created" dowork_packages = expect_migrates(