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

Makes querying associations optional based on the journable

Marcello Rochad225c3502d1f
diff --git a/app/models/journal.rb b/app/models/journal.rb
index a242b38f787..81f24baf5a9 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -151,6 +151,10 @@ class Journal < ApplicationRecord
private
+ def has_file_links?
+ journable.respond_to?(:file_links)
+ end
+
def predecessor
@predecessor ||= if initial?
nil
diff --git a/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index 7ebbeb3578d..8819b057529 100644
--- a/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -190,6 +190,10 @@ module Redmine
(persisted? && allowed_to_on_attachment?(user, self.class.attachable_options[:add_on_persisted_permission]))
end
+ def attachable?
+ true
+ end
+
private
def allowed_to_on_attachment?(user, permissions)
@@ -243,6 +247,10 @@ module Redmine
end
end
end
+
+ def attachable?
+ false
+ end
end
end
end
diff --git a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index a946d02cb7d..ae2108a35d9 100644
--- a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -64,6 +64,10 @@ module Redmine
base.extend HumanAttributeName
end
+ def customizable?
+ true
+ end
+
def available_custom_fields
self.class.available_custom_fields(self)
end
@@ -409,6 +413,10 @@ module Redmine
end
end
end
+
+ def customizable?
+ false
+ end
end
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 20784d1649e..174ce19eb59 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
@@ -39,9 +39,35 @@ module JournalChanges
@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.merge!(get_association_changes(predecessor, 'storable', 'file_links', :file_link_id, :link_name))
+ if journable.attachable?
+ @changes.merge!(get_association_changes(
+ predecessor,
+ 'attachable',
+ 'attachments',
+ :attachment_id,
+ :filename
+ ))
+ end
+
+ if journable.customizable?
+ @changes.merge!(get_association_changes(
+ predecessor,
+ 'customizable',
+ 'custom_fields',
+ :custom_field_id,
+ :value
+ ))
+ end
+
+ if has_file_links?
+ @changes.merge!(get_association_changes(
+ predecessor,
+ 'storable',
+ 'file_links',
+ :file_link_id,
+ :link_name
+ ))
+ end
@changes
end