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

Add project journal attribute for parent

Mir Bhatia8df683ed4405
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 2ea1b284f01..0a147171a43 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -42,6 +42,7 @@ class Journal < ApplicationRecord
register_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatus
register_journal_formatter :template, OpenProject::JournalFormatter::Template
register_journal_formatter :visibility, OpenProject::JournalFormatter::Visibility
+ register_journal_formatter :parent, OpenProject::JournalFormatter::Parent
# Make sure each journaled model instance only has unique version ids
diff --git a/app/models/project.rb b/app/models/project.rb
index c625ff742a8..77b4fe74fc7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -110,6 +110,7 @@ class Project < ApplicationRecord
register_on_journal_formatter(:plaintext, 'name')
register_on_journal_formatter(:diff, 'description')
register_on_journal_formatter(:visibility, 'public')
+ register_on_journal_formatter(:parent, 'parent_id')
has_paper_trail
diff --git a/lib/open_project/journal_formatter/parent.rb b/lib/open_project/journal_formatter/parent.rb
new file mode 100644
index 00000000000..597290d3771
--- /dev/null
+++ b/lib/open_project/journal_formatter/parent.rb
@@ -0,0 +1,47 @@
+#-- 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.
+#++
+
+# Need to correct rubocop issues
+
+# class OpenProject::JournalFormatter::Parent < JournalFormatter::Base
+# def render(_key, values, options = { html: true })
+
+# projects = Project.find(values).sort! { |a, b| values.index(a.id) <=> values.index(b.id) }
+# label_text = options[:html] ? content_tag('strong', "Parent") : "Parent"
+# if values.first.nil?
+# activated_text = options[:html] ? "set to #{content_tag('i', projects.last.name)}" \
+# : "set to #{projects.last.name}"
+# else
+# activated_text = options[:html] ? "changed from #{content_tag('i', projects.first.name)} \
+# to #{content_tag('i', projects.last.name)}" \
+# : "changed from #{projects.first.name} to #{projects.last.name}"
+# end
+
+# I18n.t(:text_journal_label_value, label: label_text, value: activated_text)
+# end
+# end
diff --git a/spec/lib/journal_formatter/parent_spec.rb b/spec/lib/journal_formatter/parent_spec.rb
new file mode 100644
index 00000000000..e72bae6c7b1
--- /dev/null
+++ b/spec/lib/journal_formatter/parent_spec.rb
@@ -0,0 +1,51 @@
+#-- 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.
+#++
+
+require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper.rb")
+
+describe OpenProject::JournalFormatter::Parent do
+ let(:instance) { described_class.new(build(:journal)) }
+ let(:project1) { create(:project, id: 100) }
+ let(:project2) { create(:project, id: 42) }
+
+ it "renders correctly when setting new parent" do
+ html = instance.render("parent", [nil, project1.id], html: true)
+ expect(html).to eq("<strong>Parent</strong> set to <i>#{project1.name}</i>")
+
+ html = instance.render("parent", [nil, project1.id], html: false)
+ expect(html).to eq("Parent set to #{project1.name}")
+ end
+
+ it "renders correctly when changing parents" do
+ html = instance.render("parent", [project1.id, project2.id], html: true)
+ expect(html).to eq("<strong>Parent</strong> changed from <i>#{project1.name}</i> to <i>#{project2.name}</i>")
+
+ html = instance.render("parent", [project1.id, project2.id], html: false)
+ expect(html).to eq("Parent changed from #{project1.name} to #{project2.name}")
+ end
+end