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

Render parent field in Project activity details

Christophe Bliard5570e2cb2d9a
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 0a147171a43..16310513694 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -42,8 +42,6 @@ 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
validates :version, uniqueness: { scope: %i[journable_id journable_type] }
diff --git a/app/models/project.rb b/app/models/project.rb
index 2f1619fe851..6c28d86f1a1 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -110,7 +110,7 @@ class Project < ApplicationRecord
register_journal_formatted_fields(:plaintext, 'name')
register_journal_formatted_fields(:diff, 'description')
register_journal_formatted_fields(:visibility, 'public')
- register_journal_formatted_fields(:parent, 'parent_id')
+ register_journal_formatted_fields(:named_association, 'parent_id')
register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)
has_paper_trail
diff --git a/lib/open_project/journal_formatter/parent.rb b/lib/open_project/journal_formatter/parent.rb
deleted file mode 100644
index c46455e7f92..00000000000
--- a/lib/open_project/journal_formatter/parent.rb
+++ /dev/null
@@ -1,47 +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.
-#++
-
-# Need to fix 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/features/activities/project_attributes_activity_spec.rb b/spec/features/activities/project_attributes_activity_spec.rb
index 48c2d53dc86..a40c00377d2 100644
--- a/spec/features/activities/project_attributes_activity_spec.rb
+++ b/spec/features/activities/project_attributes_activity_spec.rb
@@ -36,8 +36,8 @@ describe 'Project attributes activities' do
edit_wiki_pages
view_wiki_edits])
end
- let(:project) { create(:project, parent: create(:project), active: false, enabled_module_names: %w[activity]) }
- # more factories available in spec/factories/custom_field_factory.rb
+ let(:parent_project) { create(:project, name: 'parent') }
+ let(:project) { create(:project, parent: parent_project, active: false, enabled_module_names: %w[activity]) }
let!(:list_project_custom_field) { create(:list_project_custom_field) }
let!(:version_project_custom_field) { create(:version_project_custom_field) }
let!(:bool_project_custom_field) { create(:bool_project_custom_field) }
@@ -85,15 +85,17 @@ describe 'Project attributes activities' do
expect(page)
.to have_link("Project: #{project.name}")
+ # own fields
expect(page).to have_selector('li', text: "Name changed from #{previous_project_attributes['name']} to #{project.name}")
expect(page).to have_selector('li', text: 'Description set (Details)')
expect(page).to have_selector('li', text: 'Visibility set to public')
- # expect(page).to have_selector('li', text: 'Project parent changed to (new parent)')
+ expect(page).to have_selector('li', text: "Subproject of deleted (#{parent_project.name})")
expect(page).to have_selector('li', text: 'Project unarchived')
expect(page).to have_selector('li', text: "Identifier changed from #{previous_project_attributes['identifier']} " \
"to #{project.identifier}")
expect(page).to have_selector('li', text: 'Template: Project marked as template')
+ # custom fields
expect(page).to have_selector('li', text: "#{list_project_custom_field.name} " \
"set to #{project.send(list_project_custom_field.attribute_getter)}")
expect(page).to have_selector('li', text: "#{version_project_custom_field.name} set to #{next_version.name}")
diff --git a/spec/lib/journal_formatter/parent_spec.rb b/spec/lib/journal_formatter/parent_spec.rb
deleted file mode 100644
index e72bae6c7b1..00000000000
--- a/spec/lib/journal_formatter/parent_spec.rb
+++ /dev/null
@@ -1,51 +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.
-#++
-
-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
diff --git a/spec/models/journal/project_journal_spec.rb b/spec/models/journal/project_journal_spec.rb
index 9028fcaca82..e8e94108a49 100644
--- a/spec/models/journal/project_journal_spec.rb
+++ b/spec/models/journal/project_journal_spec.rb
@@ -64,5 +64,30 @@ RSpec.describe Journal::ProjectJournal do
html = journal.render_detail(['name', ['Old Project Name', 'New Project Name']], html: false)
expect(html).to eq('Name changed from Old Project Name to New Project Name')
end
+
+ it 'renders parent field correctly' do
+ parent = create(:project)
+
+ # Set
+ expect(journal.render_detail(['parent_id', [nil, parent.id]], html: true))
+ .to eq("<strong>Subproject of</strong> set to <i>#{parent.name}</i>")
+ expect(journal.render_detail(['parent_id', [nil, parent.id]], html: false))
+ .to eq("Subproject of set to #{parent.name}")
+
+ previous_parent = create(:project)
+
+ # Change
+ expect(journal.render_detail(['parent_id', [previous_parent.id, parent.id]], html: true))
+ .to eq('<strong>Subproject of</strong> changed ' \
+ "from <i>#{previous_parent.name}</i> <strong>to</strong> <i>#{parent.name}</i>")
+ expect(journal.render_detail(['parent_id', [previous_parent.id, parent.id]], html: false))
+ .to eq("Subproject of changed from #{previous_parent.name} to #{parent.name}")
+
+ # Delete
+ expect(journal.render_detail(['parent_id', [parent.id, nil]], html: true))
+ .to eq("<strong>Subproject of</strong> deleted (<strike><i>#{parent.name}</i></strike>)")
+ expect(journal.render_detail(['parent_id', [parent.id, nil]], html: false))
+ .to eq("Subproject of deleted (#{parent.name})")
+ end
end
end