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

Start formatting cause

Klaus Zanders849d7eb70d07
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 1f82ef75c99..2015cc923f7 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -50,6 +50,7 @@ class Journal < ApplicationRecord
register_journal_formatter :time_entry_hours, OpenProject::JournalFormatter::TimeEntryHours
register_journal_formatter :wiki_diff, OpenProject::JournalFormatter::WikiDiff
register_journal_formatter :time_entry_named_association, OpenProject::JournalFormatter::TimeEntryNamedAssociation
+ register_journal_formatter :cause, OpenProject::JournalFormatter::Cause
# Attributes related to the cause are stored in a JSONB column so we can easily add new relations and related
# attributes without a heavy database migration. Fields will be prefixed with `cause_` but are stored in the JSONB
diff --git a/app/models/work_package/journalized.rb b/app/models/work_package/journalized.rb
index 189fc8b61f7..6e1f4c624c9 100644
--- a/app/models/work_package/journalized.rb
+++ b/app/models/work_package/journalized.rb
@@ -85,6 +85,7 @@ module WorkPackage::Journalized
register_journal_formatted_fields(:attachment, /attachments_?\d+/)
register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)
register_journal_formatted_fields(:ignore_non_working_days, 'ignore_non_working_days')
+ register_journal_formatted_fields(:cause, 'cause')
# Joined
register_journal_formatted_fields :named_association, :parent_id, :project_id,
diff --git a/lib/open_project/journal_formatter/cause.rb b/lib/open_project/journal_formatter/cause.rb
new file mode 100644
index 00000000000..d11b17ad775
--- /dev/null
+++ b/lib/open_project/journal_formatter/cause.rb
@@ -0,0 +1,37 @@
+#-- 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 OpenProject::JournalFormatter::Cause < JournalFormatter::Base
+ include ApplicationHelper
+ include OpenProject::StaticRouting::UrlHelpers
+ include OpenProject::ObjectLinking
+
+ def render(_key, values, _options = { html: true })
+ content_tag(:pre, values.last)
+ 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 7d31af740a2..ed42cd93b76 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
@@ -31,14 +31,18 @@ module JournalChanges
return @changes if @changes
return {} if data.nil?
- @changes = if predecessor.nil?
- initial_journal_data_changes
- else
- subsequent_journal_data_changes
- end
+ @changes = cause.present? ? { cause: [nil, cause] } : {}
+
+ if predecessor.nil?
+ @changes.merge!(initial_journal_data_changes)
+ else
+ @changes.merge!(subsequent_journal_data_changes)
+ end
@changes.merge!(get_association_changes(predecessor, 'attachable', 'attachments', :attachment_id, :filename))
@changes.merge!(get_association_changes(predecessor, 'customizable', 'custom_fields', :custom_field_id, :value))
+
+ @changes
end
private