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

rename CustomField to CustomField::Plain

Ivan Kuchin57e870c4907b
diff --git a/lib/open_project/journal_formatter/custom_field.rb b/lib/open_project/journal_formatter/custom_field/plain.rb
similarity index 85%
rename from lib/open_project/journal_formatter/custom_field.rb
rename to lib/open_project/journal_formatter/custom_field/plain.rb
index 2f579b0bfe2..a988d2d2b3a 100644
--- a/lib/open_project/journal_formatter/custom_field.rb
+++ b/lib/open_project/journal_formatter/custom_field/plain.rb
@@ -26,22 +26,22 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class OpenProject::JournalFormatter::CustomField < JournalFormatter::Base
+class OpenProject::JournalFormatter::CustomField::Plain < JournalFormatter::Base
include CustomFieldsHelper
+ include OpenProject::JournalFormatter::CustomField::SharedMethods
private
def format_details(key, values)
- custom_field = ::CustomField.find_by(id: key.to_s.sub("custom_fields_", "").to_i)
+ custom_field = custom_field_for_key(key)
- if custom_field
- label = custom_field.name
- old_value, value = get_formatted_values custom_field, values
- else
- label = I18n.t(:label_deleted_custom_field)
- old_value = values.first
- value = values.last
- end
+ label = label_for_custom_field(custom_field)
+
+ old_value, value = if custom_field
+ get_formatted_values(custom_field, values)
+ else
+ [values.first, values.last]
+ end
[label, old_value, value]
end
@@ -78,8 +78,7 @@ class OpenProject::JournalFormatter::CustomField < JournalFormatter::Base
ids = value.split(",").map(&:to_i)
# Lookup any visible user we can find
- user_lookup =
- Principal
+ user_lookup = Principal
.in_visible_project_or_me(User.current)
.where(id: ids)
.index_by(&:id)
@@ -105,8 +104,7 @@ class OpenProject::JournalFormatter::CustomField < JournalFormatter::Base
ids = value.split(",").map(&:to_i)
# Lookup visible versions we can find
- version_lookup =
- Version
+ version_lookup = Version
.visible(User.current)
.where(id: ids)
.index_by(&:id)
diff --git a/lib/open_project/journal_formatter/custom_field/shared_methods.rb b/lib/open_project/journal_formatter/custom_field/shared_methods.rb
new file mode 100644
index 00000000000..ddcfb1cae4c
--- /dev/null
+++ b/lib/open_project/journal_formatter/custom_field/shared_methods.rb
@@ -0,0 +1,45 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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.
+#++
+
+module OpenProject::JournalFormatter::CustomField::SharedMethods
+ private
+
+ def custom_field_for_key(key)
+ id = key.to_s.delete_prefix("custom_fields_").to_i
+
+ ::CustomField.find_by(id:)
+ end
+
+ def label_for_custom_field(custom_field)
+ if custom_field
+ custom_field.name
+ else
+ I18n.t(:label_deleted_custom_field)
+ end
+ end
+end