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 wiki_diff journal formatter for wiki diffs

Mir Bhatia19bf00a7b342
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index c8ab4b4d08e..692c304faed 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -105,6 +105,7 @@ class JournalsController < ApplicationController
# Is this a valid field for diff'ing?
def valid_field?
field_param == 'description'
+ end
def journals_index_title
subject = @project ? @project.name : Setting.app_title
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 419d48f9c38..da6ed7ae568 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -44,6 +44,7 @@ class Journal < ApplicationRecord
register_journal_formatter :template, OpenProject::JournalFormatter::Template
register_journal_formatter :visibility, OpenProject::JournalFormatter::Visibility
register_journal_formatter :subproject_named_association, OpenProject::JournalFormatter::SubprojectNamedAssociation
+ register_journal_formatter :wiki_diff, OpenProject::JournalFormatter::WikiDiff
# 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/wiki_content.rb b/app/models/wiki_content.rb
index 0b373d83374..f7746a10adc 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -35,7 +35,7 @@ class WikiContent < ApplicationRecord
acts_as_journalized
- register_journal_formatted_fields(:diff, 'text')
+ register_journal_formatted_fields(:wiki_diff, 'text')
acts_as_event type: 'wiki-page',
title: Proc.new { |o|
diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb
index f15a6c14d21..ead7e0e19d3 100644
--- a/lib/open_project/journal_formatter/diff.rb
+++ b/lib/open_project/journal_formatter/diff.rb
@@ -81,26 +81,13 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
end
def url_attr(key, options)
- journable = @journal.journable
- version = @journal.version
-
- if key.to_s == 'description'
- default_attributes(options)
- .merge(controller: '/journals',
- action: 'diff',
- id: @journal.id,
- field: key.downcase,
- activity_page: options[:activity_page])
- else
- default_attributes(options)
- .merge(controller: '/wiki',
- action: 'diff',
- project_id: journable.project.identifier,
- id: journable.page.slug,
- version: version - 1,
- version_from: version)
- end
- .compact
+ default_attributes(options)
+ .merge(controller: '/journals',
+ action: 'diff',
+ id: @journal.id,
+ field: key.downcase,
+ activity_page: options[:activity_page])
+ .compact
end
def default_attributes(options)
diff --git a/lib/open_project/journal_formatter/wiki_diff.rb b/lib/open_project/journal_formatter/wiki_diff.rb
new file mode 100644
index 00000000000..1c0945a82de
--- /dev/null
+++ b/lib/open_project/journal_formatter/wiki_diff.rb
@@ -0,0 +1,45 @@
+#-- 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::WikiDiff < OpenProject::JournalFormatter::Diff
+ private
+
+ def url_attr(_key, options)
+ journable = @journal.journable
+ version = @journal.version
+
+ default_attributes(options)
+ .merge(controller: '/wiki',
+ action: 'diff',
+ project_id: journable.project.identifier,
+ id: journable.page.slug,
+ version: version - 1,
+ version_from: version)
+ .compact
+ end
+end