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

displaying project life cycle step change

Ivan Kuchin09e5c3db943f
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 2863987eb6f..7c88ba7a4c0 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -50,6 +50,7 @@ class Journal < ApplicationRecord
register_journal_formatter OpenProject::JournalFormatter::MeetingStartTime
register_journal_formatter OpenProject::JournalFormatter::MeetingState
register_journal_formatter OpenProject::JournalFormatter::MeetingWorkPackageId
+ register_journal_formatter OpenProject::JournalFormatter::ProjectLifeCycleStep
register_journal_formatter OpenProject::JournalFormatter::ProjectStatusCode
register_journal_formatter OpenProject::JournalFormatter::ScheduleManually
register_journal_formatter OpenProject::JournalFormatter::SubprojectNamedAssociation
diff --git a/app/models/journal/project_life_cycle_step_journal.rb b/app/models/journal/project_life_cycle_step_journal.rb
index 8e3200ce706..a907dc46886 100644
--- a/app/models/journal/project_life_cycle_step_journal.rb
+++ b/app/models/journal/project_life_cycle_step_journal.rb
@@ -32,4 +32,10 @@ class Journal::ProjectLifeCycleStepJournal < Journal::AssociatedJournal
self.table_name = "project_life_cycle_step_journals"
belongs_to :life_cycle_step, class_name: "Project::LifeCycleStep"
+
+ alias_attribute :date, :start_date
+
+ def date_range
+ start_date..end_date if start_date || end_date
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index cd4bf2b4a0e..63df3d59377 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -146,6 +146,7 @@ class Project < ApplicationRecord
register_journal_formatted_fields "public", formatter_key: :visibility
register_journal_formatted_fields "parent_id", formatter_key: :subproject_named_association
register_journal_formatted_fields /custom_fields_\d+/, formatter_key: :custom_field
+ register_journal_formatted_fields /^project_life_cycle_step_\d+$/, formatter_key: :project_life_cycle_step
has_paper_trail
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 11ea147b113..de3080a1044 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1666,6 +1666,12 @@ en:
time_entry: "Spent time"
wiki_edit: "Wiki"
work_package: "Work packages"
+ project_life_cycle_step:
+ activated: "activated"
+ deactivated: "deactivated"
+ added_date: "set to %{date}"
+ changed_date: "changed from %{from} to %{to}"
+ removed_date: "date deleted %{date}"
# common attributes of all models
attributes:
diff --git a/lib/open_project/journal_formatter/project_life_cycle_step.rb b/lib/open_project/journal_formatter/project_life_cycle_step.rb
new file mode 100644
index 00000000000..ba7205f1577
--- /dev/null
+++ b/lib/open_project/journal_formatter/project_life_cycle_step.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 OpenProject::JournalFormatter::ProjectLifeCycleStep < JournalFormatter::Base
+ def render(key, values, options = { html: true })
+ step = Project::LifeCycleStep.find(key[/\d+/])
+
+ name = step.definition.name
+ label = options[:html] ? content_tag(:strong, name) : name
+
+ messages = [
+ activation_message(values:),
+ date_change_message(values:, step:, options:)
+ ]
+
+ "#{label} #{messages.compact.to_sentence}"
+ end
+
+ private
+
+ def activation_message(values:)
+ if values[:active]&.any?
+ if values[:active][1]
+ I18n.t("activity.project_life_cycle_step.activated")
+ else
+ I18n.t("activity.project_life_cycle_step.deactivated")
+ end
+ end
+ end
+
+ def date_change_message(values:, step:, options:)
+ case step
+ when Project::Gate
+ if values[:date]
+ from, to = values[:date].map { format_date(_1) }
+
+ format_date_change(from:, to:, options:)
+ end
+ when Project::Stage
+ if values[:date_range]
+ from, to = values[:date_range].map { format_date_range(_1) }
+
+ format_date_change(from:, to:, options:)
+ end
+ end
+ end
+
+ def format_date_range(date_range)
+ "#{format_date(date_range.begin)} - #{format_date(date_range.end)}" if date_range
+ end
+
+ def format_date_change(from:, to:, options:)
+ if from && to
+ I18n.t("activity.project_life_cycle_step.changed_date", from:, to:)
+ elsif to
+ I18n.t("activity.project_life_cycle_step.added_date", date: to)
+ elsif from
+ date = options[:html] ? content_tag("del", from) : from
+
+ I18n.t("activity.project_life_cycle_step.removed_date", date:)
+ end
+ end
+end
diff --git a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
index d6baf7393c0..b2c52921f95 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
@@ -103,7 +103,7 @@ module JournalChanges
association: :project_life_cycle_step_journals,
id_attribute: :life_cycle_step_id
).attributes_changes(
- %i[start_date end_date active],
+ %i[active date date_range],
key_prefix: "project_life_cycle_step",
grouped: true
)
diff --git a/spec/lib/journal_formatter/project_life_cycle_step_spec.rb b/spec/lib/journal_formatter/project_life_cycle_step_spec.rb
new file mode 100644
index 00000000000..05451fc94fd
--- /dev/null
+++ b/spec/lib/journal_formatter/project_life_cycle_step_spec.rb
@@ -0,0 +1,165 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+#++
+
+require "spec_helper"
+
+RSpec.describe OpenProject::JournalFormatter::ProjectLifeCycleStep do
+ describe "#render" do
+ let(:key) { "project_life_cycle_step_#{step.id}" }
+
+ subject(:result) { described_class.new(nil).render(key, values, html:) }
+
+ before do
+ allow(Project::LifeCycleStep).to receive(:find).with(step.id.to_s).and_return(step)
+ end
+
+ def date(day) = Date.new(2025, 1, day)
+
+ shared_examples "test result" do
+ context "with html output" do
+ let(:html) { true }
+
+ it { is_expected.to eq html_result }
+ end
+
+ context "with plain output" do
+ let(:html) { false }
+
+ it { is_expected.to eq plain_result }
+ end
+ end
+
+ describe "for gate changes" do
+ let(:step) { build_stubbed(:project_gate, definition:) }
+ let(:definition) { build_stubbed(:project_gate_definition, name: "The Gate") }
+
+ context "when activated" do
+ let(:values) { { active: [false, true] } }
+ let(:plain_result) { "The Gate activated" }
+ let(:html_result) { "<strong>The Gate</strong> activated" }
+
+ include_examples "test result"
+ end
+
+ context "when deactivated" do
+ let(:values) { { active: [true, false] } }
+ let(:plain_result) { "The Gate deactivated" }
+ let(:html_result) { "<strong>The Gate</strong> deactivated" }
+
+ include_examples "test result"
+ end
+
+ context "when date added" do
+ let(:values) { { date: [nil, date(28)] } }
+ let(:plain_result) { "The Gate set to 01/28/2025" }
+ let(:html_result) { "<strong>The Gate</strong> set to 01/28/2025" }
+
+ include_examples "test result"
+ end
+
+ context "when date changed" do
+ let(:values) { { date: [date(28), date(29)] } }
+ let(:plain_result) { "The Gate changed from 01/28/2025 to 01/29/2025" }
+ let(:html_result) { "<strong>The Gate</strong> changed from 01/28/2025 to 01/29/2025" }
+
+ include_examples "test result"
+ end
+
+ context "when date removed" do
+ let(:values) { { date: [date(28), nil] } }
+ let(:plain_result) { "The Gate date deleted 01/28/2025" }
+ let(:html_result) { "<strong>The Gate</strong> date deleted <del>01/28/2025</del>" }
+
+ include_examples "test result"
+ end
+
+ context "when activated and date added" do
+ let(:values) { { active: [false, true], date: [nil, date(28)] } }
+ let(:plain_result) { "The Gate activated and set to 01/28/2025" }
+ let(:html_result) { "<strong>The Gate</strong> activated and set to 01/28/2025" }
+
+ include_examples "test result"
+ end
+ end
+
+ describe "for stage changes" do
+ let(:step) { build_stubbed(:project_stage, definition:) }
+ let(:definition) { build_stubbed(:project_stage_definition, name: "The Stage") }
+
+ context "when activated" do
+ let(:values) { { active: [false, true] } }
+ let(:plain_result) { "The Stage activated" }
+ let(:html_result) { "<strong>The Stage</strong> activated" }
+
+ include_examples "test result"
+ end
+
+ context "when deactivated" do
+ let(:values) { { active: [true, false] } }
+ let(:plain_result) { "The Stage deactivated" }
+ let(:html_result) { "<strong>The Stage</strong> deactivated" }
+
+ include_examples "test result"
+ end
+
+ context "when date range added" do
+ let(:values) { { date_range: [nil, date(28)..date(29)] } }
+ let(:plain_result) { "The Stage set to 01/28/2025 - 01/29/2025" }
+ let(:html_result) { "<strong>The Stage</strong> set to 01/28/2025 - 01/29/2025" }
+
+ include_examples "test result"
+ end
+
+ context "when date range changed" do
+ let(:values) { { date_range: [date(28)..date(29), date(28)..date(30)] } }
+ let(:plain_result) { "The Stage changed from 01/28/2025 - 01/29/2025 to 01/28/2025 - 01/30/2025" }
+ let(:html_result) { "<strong>The Stage</strong> changed from 01/28/2025 - 01/29/2025 to 01/28/2025 - 01/30/2025" }
+
+ include_examples "test result"
+ end
+
+ context "when date range removed" do
+ let(:values) { { date_range: [date(28)..date(29), nil] } }
+ let(:plain_result) { "The Stage date deleted 01/28/2025 - 01/29/2025" }
+ let(:html_result) { "<strong>The Stage</strong> date deleted <del>01/28/2025 - 01/29/2025</del>" }
+
+ include_examples "test result"
+ end
+
+ context "when activated and date range added" do
+ let(:values) { { active: [false, true], date_range: [nil, date(28)..date(29)] } }
+ let(:plain_result) { "The Stage activated and set to 01/28/2025 - 01/29/2025" }
+ let(:html_result) { "<strong>The Stage</strong> activated and set to 01/28/2025 - 01/29/2025" }
+
+ include_examples "test result"
+ end
+ end
+ end
+end