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

[49409] Update cause messages for status changes

Christophe Bliarde03d626897ce
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
index 691ee4bf271..c3b0e10784f 100644
--- a/app/controllers/statuses_controller.rb
+++ b/app/controllers/statuses_controller.rb
@@ -98,28 +98,15 @@ class StatusesController < ApplicationController
end
def recompute_progress_values
- apply_status_p_complete_change
- apply_status_excluded_from_totals_change
- end
-
- def apply_status_p_complete_change
- return unless WorkPackage.use_status_for_done_ratio?
- return unless @status.default_done_ratio_previously_changed?
-
- WorkPackages::Progress::ApplyStatusesChangeJob
- .perform_later(cause_type: "status_p_complete_changed",
- status_name: @status.name,
- status_id: @status.id,
- change: @status.default_done_ratio_previous_change)
- end
-
- def apply_status_excluded_from_totals_change
- return unless @status.excluded_from_totals_previously_changed?
+ attributes_triggering_recomputing = ["excluded_from_totals"]
+ attributes_triggering_recomputing << "default_done_ratio" if WorkPackage.use_status_for_done_ratio?
+ changes = @status.previous_changes.slice(*attributes_triggering_recomputing)
+ return if changes.empty?
WorkPackages::Progress::ApplyStatusesChangeJob
- .perform_later(cause_type: "status_excluded_from_totals_changed",
+ .perform_later(cause_type: "status_changed",
status_name: @status.name,
status_id: @status.id,
- change: @status.excluded_from_totals_previous_change)
+ changes:)
end
end
diff --git a/app/models/journal.rb b/app/models/journal.rb
index d5e07c2e275..1a9229a397a 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -71,15 +71,13 @@ class Journal < ApplicationRecord
changed_days
status_name
status_id
- status_excluded_from_totals_change
- status_p_complete_change
+ status_changes
],
prefix: true
VALID_CAUSE_TYPES = %w[
default_attribute_written
progress_mode_changed_to_status_based
- status_excluded_from_totals_changed
- status_p_complete_changed
+ status_changed
system_update
work_package_children_changed_times
work_package_parent_changed_times
diff --git a/app/models/journal/caused_by_status_p_complete_changed.rb b/app/models/journal/caused_by_status_changed.rb
similarity index 84%
rename from app/models/journal/caused_by_status_p_complete_changed.rb
rename to app/models/journal/caused_by_status_changed.rb
index da648aca57d..4e28458fbc7 100644
--- a/app/models/journal/caused_by_status_p_complete_changed.rb
+++ b/app/models/journal/caused_by_status_changed.rb
@@ -26,14 +26,14 @@
# See COPYRIGHT and LICENSE files for more details.
#++
#
-class Journal::CausedByStatusPCompleteChanged < CauseOfChange::Base
- def initialize(status_name:, status_id:, status_p_complete_change:)
+class Journal::CausedByStatusChanged < CauseOfChange::Base
+ def initialize(status_name:, status_id:, status_changes:)
additional = {
"status_name" => status_name,
"status_id" => status_id,
- "status_p_complete_change" => status_p_complete_change
+ "status_changes" => status_changes
}
- super("status_p_complete_changed", additional)
+ super("status_changed", additional)
end
end
diff --git a/app/models/journal/caused_by_status_excluded_from_totals_changed.rb b/app/models/journal/caused_by_status_excluded_from_totals_changed.rb
deleted file mode 100644
index e80b5b33bda..00000000000
--- a/app/models/journal/caused_by_status_excluded_from_totals_changed.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-class Journal::CausedByStatusExcludedFromTotalsChanged < CauseOfChange::Base
- def initialize(status_name:, status_id:, status_excluded_from_totals_change:)
- additional = {
- "status_name" => status_name,
- "status_id" => status_id,
- "status_excluded_from_totals_change" => status_excluded_from_totals_change
- }
-
- super("status_excluded_from_totals_changed", additional)
- end
-end
diff --git a/app/workers/work_packages/progress/apply_statuses_change_job.rb b/app/workers/work_packages/progress/apply_statuses_change_job.rb
index b5f52315c02..304a1ba2c79 100644
--- a/app/workers/work_packages/progress/apply_statuses_change_job.rb
+++ b/app/workers/work_packages/progress/apply_statuses_change_job.rb
@@ -31,31 +31,31 @@
class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::Job
VALID_CAUSE_TYPES = %w[
progress_mode_changed_to_status_based
- status_excluded_from_totals_changed
- status_p_complete_changed
+ status_changed
].freeze
- attr_reader :cause_type, :status_name, :status_id, :change
+ attr_reader :cause_type, :status_name, :status_id, :changes
# Updates % complete and remaining work of all work packages after a status %
# complete value has been changed or the progress calculation mode was set to
# status-based.
#
- # It creates a journal entry with the System user describing the change.
+ # It creates a journal entry with the System user describing the changes.
#
# @param status_name [String] The cause of the update to be put in the journal
# entry. Must be one of `VALID_CAUSE_TYPES`.
# @param status_name [String] The name of the status to apply.
# @param status_id [Integer] The ID of the status to apply. Not used
# currently, but here in case we need it in a later version.
- # @param change [Object] The change object containing an array of [old, new]
- # values of the change.
+ # @param changes [Object] The changes object containing an map of array of
+ # [old, new] values of the change, for instance
+ # `{"default_done_ratio" => [20, 40], "excluded_from_totals" => [false, true]}`.
# @return [void]
- def perform(cause_type:, status_name: nil, status_id: nil, change: nil)
+ def perform(cause_type:, status_name: nil, status_id: nil, changes: nil)
@cause_type = cause_type
@status_name = status_name
@status_id = status_id
- @change = change
+ @changes = changes
with_temporary_progress_table do
if WorkPackage.use_status_for_done_ratio?
@@ -77,19 +77,12 @@ class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::J
case cause_type
when "progress_mode_changed_to_status_based"
Journal::CausedByProgressModeChangedToStatusBased.new
- when "status_excluded_from_totals_changed"
+ when "status_changed"
assert_status_information_present!
- Journal::CausedByStatusExcludedFromTotalsChanged.new(
+ Journal::CausedByStatusChanged.new(
status_name:,
status_id:,
- status_excluded_from_totals_change: change
- )
- when "status_p_complete_changed"
- assert_status_information_present!
- Journal::CausedByStatusPCompleteChanged.new(
- status_name:,
- status_id:,
- status_p_complete_change: change
+ status_changes: changes
)
else
raise "Unable to handle cause type #{cause_type.inspect}"
@@ -112,8 +105,8 @@ class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::J
raise ArgumentError, "status_id must be provided"
end
- if change.nil?
- raise ArgumentError, "change must be provided"
+ if changes.nil?
+ raise ArgumentError, "changes must be provided"
end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c9402466916..dea895bac8a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1750,8 +1750,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
dates_changed: "Dates changed"
default_attribute_written: "Read-only attributes written"
progress_mode_changed_to_status_based: "Progress calculation updated"
- status_p_complete_changed: "Status % Complete changed"
- status_excluded_from_totals_changed: "Status Excluded from totals changed"
+ status_changed: "Status '%{status_name}'"
system_update: "OpenProject system update:"
cause_descriptions:
@@ -1769,12 +1768,9 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
working: "%{date} is now working"
non_working: "%{date} is now non-working"
progress_mode_changed_to_status_based: Progress calculation mode set to status-based
- status_excluded_from_totals_set_to_false_message: >-
- status '%{status_name}' was included in totals calculations
- status_excluded_from_totals_set_to_true_message: >-
- status '%{status_name}' was excluded from totals calculations
- status_p_complete_changed: >-
- % complete value for status '%{status_name}' changed from %{old_value}% to %{new_value}%
+ status_excluded_from_totals_set_to_false_message: now included in hierarchy totals
+ status_excluded_from_totals_set_to_true_message: now excluded from hierarchy totals
+ status_percent_complete_changed: "% complete changed from %{old_value}% to %{new_value}%"
system_update:
file_links_journal: >
From now on, activity related to file links (files stored in external storages) will appear here in the
diff --git a/db/migrate/20240522073759_fix_status_excluded_from_totals_changed_journal_cause.rb b/db/migrate/20240522073759_fix_status_excluded_from_totals_changed_journal_cause.rb
new file mode 100644
index 00000000000..33f181c2f12
--- /dev/null
+++ b/db/migrate/20240522073759_fix_status_excluded_from_totals_changed_journal_cause.rb
@@ -0,0 +1,48 @@
+# Update journal entries from this:
+#
+# {
+# "type" => "status_p_complete_changed",
+# "status_name" => status.name,
+# "status_id" => status.id,
+# "status_p_complete_change" => [20, 40]
+# }
+#
+# to this:
+#
+# {
+# "type" => "status_changed",
+# "status_name" => status.name,
+# "status_id" => status.id,
+# "status_changes" => { "default_done_ratio" => [20, 40] }
+# }
+#
+# structure needed to handle multiple changes in one cause
+class FixStatusExcludedFromTotalsChangedJournalCause < ActiveRecord::Migration[7.1]
+ def up
+ execute(<<~SQL.squish)
+ UPDATE journals
+ SET cause = json_object(
+ 'type': 'status_changed',
+ 'status_id': cause -> 'status_id',
+ 'status_name': cause -> 'status_name',
+ 'status_changes': json_object(
+ 'default_done_ratio': cause -> 'status_p_complete_change'
+ )
+ )
+ WHERE cause @> '{"type": "status_p_complete_changed"}';
+ SQL
+ end
+
+ def down
+ execute(<<~SQL.squish)
+ UPDATE journals
+ SET cause = json_object(
+ 'type': 'status_p_complete_changed',
+ 'status_id': cause -> 'status_id',
+ 'status_name': cause -> 'status_name',
+ 'status_p_complete_change': cause #> '{status_changes,default_done_ratio}'
+ )
+ WHERE cause @> '{"type": "status_changed", "status_changes":{"default_done_ratio":[]}}';
+ SQL
+ end
+end
diff --git a/lib/open_project/journal_formatter/cause.rb b/lib/open_project/journal_formatter/cause.rb
index 69bc85837de..ae0a8385f44 100644
--- a/lib/open_project/journal_formatter/cause.rb
+++ b/lib/open_project/journal_formatter/cause.rb
@@ -32,50 +32,57 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
include OpenProject::StaticRouting::UrlHelpers
include OpenProject::ObjectLinking
+ attr_reader :cause
+
def render(_key, values, options = { html: true })
- cause = values.last
+ @cause = values.last
+ @html = options[:html]
- if options[:html]
- "#{content_tag(:strong, cause_type_translation(cause['type']))} #{cause_description(cause, true)}"
- else
- "#{cause_type_translation(cause['type'])} #{cause_description(cause, false)}"
- end
+ "#{caused_change} #{cause_description}"
end
private
- def cause_type_translation(type)
- mapped_type = mapped_cause_type(type)
- I18n.t("journals.caused_changes.#{mapped_type}", default: mapped_type)
+ def html?
+ @html
+ end
+
+ def caused_change
+ caused_change_text = I18n.t("journals.caused_changes.#{mapped_cause_type}",
+ default: mapped_cause_type,
+ status_name: cause["status_name"])
+ if html?
+ content_tag(:strong, caused_change_text)
+ else
+ caused_change_text
+ end
end
- def mapped_cause_type(type)
- case type
+ def mapped_cause_type
+ case cause["type"]
when /changed_times/, "working_days_changed"
"dates_changed"
else
- type
+ cause["type"]
end
end
- def cause_description(cause, html)
+ def cause_description
case cause["type"]
when "system_update"
- system_update_message(cause, html)
+ system_update_message
when "working_days_changed"
working_days_changed_message(cause["changed_days"])
- when "status_excluded_from_totals_changed"
- status_excluded_from_totals_changed_message(cause, html)
- when "status_p_complete_changed"
- status_p_complete_changed_message(cause, html)
+ when "status_changed"
+ status_changed_message
when "progress_mode_changed_to_status_based"
progress_mode_changed_to_status_based_message
else
- related_work_package_changed_message(cause, html)
+ related_work_package_changed_message
end
end
- def system_update_message(cause, html)
+ def system_update_message
feature = cause["feature"]
feature = "progress_calculation_adjusted" if feature == "progress_calculation_changed"
@@ -90,7 +97,7 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
{}
end
message = I18n.t("journals.cause_descriptions.system_update.#{feature}", **options)
- html ? message : Sanitize.fragment(message)
+ html? ? message : Sanitize.fragment(message)
end
def working_days_changed_message(changed_dates)
@@ -114,35 +121,35 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
date: I18n.l(Date.parse(date)))
end
- def status_excluded_from_totals_changed_message(cause, html)
- cause.symbolize_keys => { status_name:, status_excluded_from_totals_change: change}
- status_name = html_escape(status_name) if html
-
- if change == [false, true]
- I18n.t("journals.cause_descriptions.status_excluded_from_totals_set_to_true_message", status_name:)
- elsif change == [true, false]
- I18n.t("journals.cause_descriptions.status_excluded_from_totals_set_to_false_message", status_name:)
- end
+ def status_changed_message
+ cause["status_changes"]
+ .sort
+ .map { |change| status_change_partial_message(change) }
+ .to_sentence
end
- def status_p_complete_changed_message(cause, html)
- cause.symbolize_keys => { status_name:, status_p_complete_change: [old_value, new_value]}
- status_name = html_escape(status_name) if html
-
- I18n.t("journals.cause_descriptions.status_p_complete_changed", status_name:, old_value:, new_value:)
+ def status_change_partial_message(change)
+ case change
+ in ["default_done_ratio", [old_value, new_value]]
+ I18n.t("journals.cause_descriptions.status_percent_complete_changed", old_value:, new_value:)
+ in ["excluded_from_totals", [true, false]]
+ I18n.t("journals.cause_descriptions.status_excluded_from_totals_set_to_false_message")
+ in ["excluded_from_totals", [false, true]]
+ I18n.t("journals.cause_descriptions.status_excluded_from_totals_set_to_true_message")
+ end
end
def progress_mode_changed_to_status_based_message
I18n.t("journals.cause_descriptions.progress_mode_changed_to_status_based")
end
- def related_work_package_changed_message(cause, html)
+ def related_work_package_changed_message
related_work_package = WorkPackage.includes(:project).visible(User.current).find_by(id: cause["work_package_id"])
if related_work_package
I18n.t(
"journals.cause_descriptions.#{cause['type']}",
- link: html ? link_to_work_package(related_work_package, all_link: true) : "##{related_work_package.id}"
+ link: html? ? link_to_work_package(related_work_package, all_link: true) : "##{related_work_package.id}"
)
else
diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb
index d3e446f269f..a4058d23a44 100644
--- a/spec/controllers/statuses_controller_spec.rb
+++ b/spec/controllers/statuses_controller_spec.rb
@@ -146,6 +146,45 @@ RSpec.describe StatusesController do
expect(WorkPackages::Progress::ApplyStatusesChangeJob)
.not_to have_been_enqueued
end
+
+ context "when also marking a status as excluded from totals calculations" do
+ before_all do
+ status.update_columns(name: "Rejected",
+ default_done_ratio: 70)
+ end
+
+ shared_let(:status_new) { create(:status, name: "New", default_done_ratio: "0") }
+ shared_let_work_packages(<<~TABLE)
+ hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | New | | | | 20h | 15h | 25%
+ child | Rejected | 10h | 5h | 50% | | |
+ other child | New | 10h | 10h | 0% | | |
+ TABLE
+
+ let(:status_params) do
+ { default_done_ratio: new_default_done_ratio,
+ excluded_from_totals: true }
+ end
+
+ it "starts a job to update totals of work packages having excluded children" do
+ expect(status.reload).to have_attributes(excluded_from_totals: true)
+ expect(WorkPackages::Progress::ApplyStatusesChangeJob)
+ .to have_been_enqueued.with(cause_type: "status_changed",
+ status_name: status.name,
+ status_id: status.id,
+ changes: { "excluded_from_totals" => [false, true] })
+
+ perform_enqueued_jobs
+
+ expect_work_packages([parent, child, other_child], <<~TABLE)
+ subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | New | | | | 10h | 10h | 0%
+ child | Rejected | 10h | 5h | 50% | | |
+ other child | New | 10h | 10h | 0% | | |
+ TABLE
+ expect(parent.last_journal.details["cause"].last).to include("type" => "status_changed")
+ end
+ end
end
context "when in status-based mode",
@@ -159,15 +198,15 @@ RSpec.describe StatusesController do
old_default_done_ratio = status.default_done_ratio
expect(status.reload).to have_attributes(default_done_ratio: new_default_done_ratio)
expect(WorkPackages::Progress::ApplyStatusesChangeJob)
- .to have_been_enqueued.with(cause_type: "status_p_complete_changed",
+ .to have_been_enqueued.with(cause_type: "status_changed",
status_name: status.name,
status_id: status.id,
- change: [old_default_done_ratio, new_default_done_ratio])
+ changes: { "default_done_ratio" => [old_default_done_ratio, new_default_done_ratio] })
perform_enqueued_jobs
expect(work_package.reload.read_attribute(:done_ratio)).to eq(new_default_done_ratio)
- expect(work_package.last_journal.details["cause"].last).to include("type" => "status_p_complete_changed")
+ expect(work_package.last_journal.details["cause"].last).to include("type" => "status_changed")
end
end
@@ -189,7 +228,7 @@ RSpec.describe StatusesController do
shared_let(:status_new) { create(:status, name: "New", default_done_ratio: "0") }
shared_let_work_packages(<<~TABLE)
hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | New | | | | 20h | 16h | 20%
+ parent | New | | | 0% | 20h | 16h | 20%
child | Rejected | 10h | 3h | 70% | | |
other child | New | 10h | 10h | 0% | | |
TABLE
@@ -199,17 +238,52 @@ RSpec.describe StatusesController do
it "starts a job to update totals of work packages having excluded children" do
expect(status.reload).to have_attributes(excluded_from_totals: true)
expect(WorkPackages::Progress::ApplyStatusesChangeJob)
- .to have_been_enqueued.with(cause_type: "status_excluded_from_totals_changed",
+ .to have_been_enqueued.with(cause_type: "status_changed",
status_name: status.name,
status_id: status.id,
- change: [false, true])
+ changes: { "excluded_from_totals" => [false, true] })
perform_enqueued_jobs
- expect(parent.reload.read_attribute(:derived_estimated_hours)).to eq(10)
- expect(parent.reload.read_attribute(:derived_remaining_hours)).to eq(10)
- expect(parent.reload.read_attribute(:derived_done_ratio)).to eq(0)
- expect(parent.last_journal.details["cause"].last).to include("type" => "status_excluded_from_totals_changed")
+ expect_work_packages([parent, child, other_child], <<~TABLE)
+ subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | New | | | 0% | 10h | 10h | 0%
+ child | Rejected | 10h | 3h | 70% | | |
+ other child | New | 10h | 10h | 0% | | |
+ TABLE
+ expect(parent.last_journal.details["cause"].last).to include("type" => "status_changed")
+ end
+
+ context "when also changing the default % complete of the status" do
+ let(:new_default_done_ratio) { 40 }
+ let(:status_params) { { excluded_from_totals: true, default_done_ratio: new_default_done_ratio } }
+
+ it "starts a job to update both total values and % complete of work packages" do
+ old_default_done_ratio = status.default_done_ratio
+ expect(status.reload).to have_attributes(default_done_ratio: new_default_done_ratio,
+ excluded_from_totals: true)
+ expect(WorkPackages::Progress::ApplyStatusesChangeJob)
+ .to have_been_enqueued.with(cause_type: "status_changed",
+ status_name: status.name,
+ status_id: status.id,
+ changes: { "default_done_ratio" => [old_default_done_ratio, new_default_done_ratio],
+ "excluded_from_totals" => [false, true] })
+
+ perform_enqueued_jobs
+
+ expect_work_packages([parent, child, other_child], <<~TABLE)
+ subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | New | | | 0% | 10h | 10h | 0%
+ child | Rejected | 10h | 6h | 40% | | |
+ other child | New | 10h | 10h | 0% | | |
+ TABLE
+
+ [parent, child].each do |work_package|
+ expect(work_package.journals.count).to eq(2)
+ expect(work_package.last_journal.details["cause"].last).to include("type" => "status_changed")
+ end
+ expect(other_child.journals.count).to eq(1) # this one should not have changed
+ end
end
end
diff --git a/spec/lib/journal_formatter/cause_spec.rb b/spec/lib/journal_formatter/cause_spec.rb
index b8c6995e808..1729d4e0b25 100644
--- a/spec/lib/journal_formatter/cause_spec.rb
+++ b/spec/lib/journal_formatter/cause_spec.rb
@@ -305,25 +305,20 @@ RSpec.describe OpenProject::JournalFormatter::Cause do
shared_let(:status) { create(:status, name: "In progress", default_done_ratio: 40) }
subject(:cause) do
{
- "type" => "status_p_complete_changed",
+ "type" => "status_changed",
"status_name" => status.name,
"status_id" => status.id,
- "status_p_complete_change" => [20, 40]
+ "status_changes" => { "default_done_ratio" => [20, 40] }
}
end
it do
- expect(cause).to render_html_variant(
- "<strong>#{I18n.t('journals.caused_changes.status_p_complete_changed')}</strong> " \
- "% complete value for status 'In progress' changed from 20% to 40%"
- )
+ expect(cause).to render_html_variant("<strong>Status &#39;In progress&#39;</strong> " \
+ "% complete changed from 20% to 40%")
end
it do
- expect(cause).to render_raw_variant(
- "#{I18n.t('journals.caused_changes.status_p_complete_changed')} " \
- "% complete value for status 'In progress' changed from 20% to 40%"
- )
+ expect(cause).to render_raw_variant("Status 'In progress' % complete changed from 20% to 40%")
end
it_behaves_like "XSS-proof rendering of status name"
@@ -333,24 +328,22 @@ RSpec.describe OpenProject::JournalFormatter::Cause do
shared_let(:status) { create(:status, name: "Rejected") }
subject(:cause) do
{
- "type" => "status_excluded_from_totals_changed",
+ "type" => "status_changed",
"status_name" => status.name,
"status_id" => status.id,
- "status_excluded_from_totals_change" => [false, true]
+ "status_changes" => { "excluded_from_totals" => [false, true] }
}
end
it do
expect(cause).to render_html_variant(
- "<strong>Status Excluded from totals changed</strong> " \
- "status 'Rejected' was excluded from totals calculations"
+ "<strong>Status &#39;Rejected&#39;</strong> now excluded from hierarchy totals"
)
end
it do
expect(cause).to render_raw_variant(
- "Status Excluded from totals changed " \
- "status 'Rejected' was excluded from totals calculations"
+ "Status 'Rejected' now excluded from hierarchy totals"
)
end
@@ -361,24 +354,22 @@ RSpec.describe OpenProject::JournalFormatter::Cause do
shared_let(:status) { create(:status, name: "Rejected") }
subject(:cause) do
{
- "type" => "status_excluded_from_totals_changed",
+ "type" => "status_changed",
"status_name" => status.name,
"status_id" => status.id,
- "status_excluded_from_totals_change" => [true, false]
+ "status_changes" => { "excluded_from_totals" => [true, false] }
}
end
it do
expect(cause).to render_html_variant(
- "<strong>Status Excluded from totals changed</strong> " \
- "status 'Rejected' was included in totals calculations"
+ "<strong>Status &#39;Rejected&#39;</strong> now included in hierarchy totals"
)
end
it do
expect(cause).to render_raw_variant(
- "Status Excluded from totals changed " \
- "status 'Rejected' was included in totals calculations"
+ "Status 'Rejected' now included in hierarchy totals"
)
end
@@ -407,6 +398,31 @@ RSpec.describe OpenProject::JournalFormatter::Cause do
end
end
+ context "when both a change of status % complete and excluded from totals is the cause" do
+ shared_let(:status) { create(:status, name: "In progress", default_done_ratio: 40) }
+ subject(:cause) do
+ {
+ "type" => "status_changed",
+ "status_name" => status.name,
+ "status_id" => status.id,
+ "status_changes" => { "default_done_ratio" => [20, 40],
+ "excluded_from_totals" => [false, true] }
+ }
+ end
+
+ it do
+ expect(cause).to render_html_variant("<strong>Status &#39;In progress&#39;</strong> " \
+ "% complete changed from 20% to 40% and now excluded from hierarchy totals")
+ end
+
+ it do
+ expect(cause).to render_raw_variant("Status 'In progress' " \
+ "% complete changed from 20% to 40% and now excluded from hierarchy totals")
+ end
+
+ it_behaves_like "XSS-proof rendering of status name"
+ end
+
context "when cause is a system update: change of progress calculation mode from disabled to work-based" do
subject(:cause) do
{
diff --git a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
index bb7b4ec8266..b6db280169d 100644
--- a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
+++ b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
@@ -57,13 +57,13 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
subject(:job) { described_class }
def expect_performing_job_changes(from:, to:,
- cause_type: "status_p_complete_changed",
- status_name: "New",
+ cause_type: "status_changed",
+ status_name: "Some status name",
status_id: 99,
- change: [33, 66])
+ changes: { "default_done_ratio" => [33, 66] })
table = create_table(from)
- job.perform_now(cause_type:, status_name:, status_id:, change:)
+ job.perform_now(cause_type:, status_name:, status_id:, changes:)
table.work_packages.map(&:reload)
expect_work_packages(table.work_packages, to)
@@ -107,10 +107,10 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
before do
job.perform_now(
- cause_type: "status_excluded_from_totals_changed",
+ cause_type: "status_changed",
status_name: status_excluded.name,
status_id: status_excluded.id,
- change: [false, true]
+ changes: { "excluded_from_totals" => [false, true] }
)
table_work_packages.map(&:reload)
end
@@ -132,10 +132,10 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
expect(work_package.journals.count).to eq(2), "expected #{work_package} to have a new journal"
last_journal = work_package.last_journal
expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_excluded_from_totals_changed")
+ expect(last_journal.cause_type).to eq("status_changed")
expect(last_journal.cause_status_name).to eq("Excluded")
expect(last_journal.cause_status_id).to eq(status_excluded.id)
- expect(last_journal.cause_status_excluded_from_totals_change).to eq([false, true])
+ expect(last_journal.cause_status_changes).to eq({ "excluded_from_totals" => [false, true] })
end
unchanged_work_packages = table_work_packages - changed_worked_packages
@@ -227,10 +227,10 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
before do
job.perform_now(
- cause_type: "status_excluded_from_totals_changed",
+ cause_type: "status_changed",
status_name: status_excluded.name,
status_id: status_excluded.id,
- change: [false, true]
+ changes: { "excluded_from_totals" => [false, true] }
)
table_work_packages.map(&:reload)
end
@@ -252,10 +252,10 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
expect(work_package.journals.count).to eq(2), "expected #{work_package} to have a new journal"
last_journal = work_package.last_journal
expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_excluded_from_totals_changed")
+ expect(last_journal.cause_type).to eq("status_changed")
expect(last_journal.cause_status_name).to eq("Excluded")
expect(last_journal.cause_status_id).to eq(status_excluded.id)
- expect(last_journal.cause_status_excluded_from_totals_change).to eq([false, true])
+ expect(last_journal.cause_status_changes).to eq({ "excluded_from_totals" => [false, true] })
end
unchanged_work_packages = table_work_packages - changed_worked_packages
@@ -281,19 +281,19 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
child 1 | Doing (40%) | 10h | 6h | 40% | | |
child 2 | Done (100%) | 10h | 0h | 100% | | |
TABLE
- cause_type: "status_p_complete_changed",
+ cause_type: "status_changed",
status_name: status_40p_doing.name,
status_id: status_40p_doing.id,
- change: [20, 40]
+ changes: { "default_done_ratio" => [20, 40] }
)
[parent, child1].each do |work_package|
expect(work_package.journals.count).to eq 2
last_journal = work_package.last_journal
expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_p_complete_changed")
+ expect(last_journal.cause_type).to eq("status_changed")
expect(last_journal.cause_status_name).to eq("Doing (40%)")
expect(last_journal.cause_status_id).to eq(status_40p_doing.id)
- expect(last_journal.cause_status_p_complete_change).to eq([20, 40])
+ expect(last_journal.cause_status_changes).to eq({ "default_done_ratio" => [20, 40] })
end
# unchanged => no new journals
@@ -351,10 +351,10 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
.and_return(nil)
begin
- job.perform_now(cause_type: "status_p_complete_changed",
+ job.perform_now(cause_type: "status_changed",
status_name: "New",
status_id: 99,
- change: [33, 66])
+ changes: { "default_done_ratio" => [33, 66] })
rescue StandardError
end
end