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

Move Project enabled attributes restriction into the journable differ.

Dombi Attilae32336de7a0e
diff --git a/app/models/activities/fetcher.rb b/app/models/activities/fetcher.rb
index 6fc290487ac..2422359bb52 100644
--- a/app/models/activities/fetcher.rb
+++ b/app/models/activities/fetcher.rb
@@ -133,7 +133,6 @@ module Activities
.includes(:data, :customizable_journals, :attachable_journals, :bcf_comment)
.find(journal_ids)
.then { |journals| ::API::V3::Activities::ActivityEagerLoadingWrapper.wrap(journals) }
- .then { |journals| exclude_disabled_project_attribute_changes(journals) }
.index_by(&:id)
end
@@ -144,24 +143,5 @@ module Activities
def constantized_providers(event_type)
self.class.constantized_providers[event_type]
end
-
- def exclude_disabled_project_attribute_changes(journals)
- project_journals = journals.filter { |j| j.journable_type == "Project" }
- project_attribute_keys = project_attribute_keys_for(journals)
-
- project_journals.each do |p_j|
- allowed_keys = project_attribute_keys[p_j.journable_id] || []
- p_j.details.delete_if { |k| k.starts_with?("custom_fields_") && !k.in?(allowed_keys) }
- end
-
- journals
- end
-
- def project_attribute_keys_for(project_journals)
- ProjectCustomFieldProjectMapping
- .where(project: project_journals.map(&:journable_id))
- .group_by(&:project_id)
- .transform_values { |v| v.map { |o| "custom_fields_#{o.custom_field_id}" } }
- end
end
end
diff --git a/lib/api/v3/activities/activity_eager_loading_wrapper.rb b/lib/api/v3/activities/activity_eager_loading_wrapper.rb
index 5445a07b03c..d62b205fcdd 100644
--- a/lib/api/v3/activities/activity_eager_loading_wrapper.rb
+++ b/lib/api/v3/activities/activity_eager_loading_wrapper.rb
@@ -86,7 +86,7 @@ module API
end
def includes_for(journable_type)
- journable_type == "Project" ? [] : [:project]
+ journable_type == "Project" ? [:project_custom_field_project_mappings] : [:project]
end
def data_by_type_and_id(journals)
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
index 0d4571229df..23dbd38f865 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
@@ -82,7 +82,11 @@ module Acts::Journalized
def get_association_changes(original, changed, association, association_name, key, value)
new_journals = changed.send(association).map(&:attributes)
- old_journals = original ? original.send(association).map(&:attributes) : [];
+ old_journals = original&.send(association)&.map(&:attributes) || []
+
+ journable = changed.journable
+ new_journals = allowed_attributes(journable, new_journals, key)
+ old_journals = allowed_attributes(journable, old_journals, key)
changes_on_association(new_journals, old_journals, association_name, key, value)
end
@@ -97,6 +101,20 @@ module Acts::Journalized
to_changes_format(changes, association_name.to_s)
end
+ def allowed_attributes(journable, journals, key)
+ # Filter out Project attributes that are not enabled on the project
+ if journable.class.name == "Project" && key == :custom_field_id
+ allowed_custom_field_ids =
+ journable.project_custom_field_project_mappings.pluck(:custom_field_id)
+
+ journals.select! do |attributes|
+ attributes["custom_field_id"].in?(allowed_custom_field_ids)
+ end
+ end
+
+ journals
+ end
+
def added_references(merged_references)
merged_references
.select { |_, (old_value, new_value)| old_value.to_s.empty? && new_value.present? }