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

Filter project activities and exclude disabled project attributes from the results.

Dombi Attila54e7fdecc062
diff --git a/app/models/activities/fetcher.rb b/app/models/activities/fetcher.rb
index 2422359bb52..6fc290487ac 100644
--- a/app/models/activities/fetcher.rb
+++ b/app/models/activities/fetcher.rb
@@ -133,6 +133,7 @@ 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
@@ -143,5 +144,24 @@ 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/app/models/activities/project_activity_provider.rb b/app/models/activities/project_activity_provider.rb
index ef78f2db16a..78ea63de55b 100644
--- a/app/models/activities/project_activity_provider.rb
+++ b/app/models/activities/project_activity_provider.rb
@@ -40,43 +40,6 @@ class Activities::ProjectActivityProvider < Activities::BaseActivityProvider
protected
- # rubocop:disable Metrics/AbcSize
- def extend_event_query(query)
- enabled_custom_fields = ProjectCustomFieldProjectMapping
- .where(custom_field_mapping_table[:project_id].eq(projects_table[:id]))
- .select(:custom_field_id)
- .arel
-
- enabled_customizable_journals = Journal::CustomizableJournal
- .where(
- customizable_journals_table[:journal_id].eq(journals_table[:id])
- .and(customizable_journals_table[:custom_field_id].in(enabled_custom_fields))
- )
- .arel
- .exists
-
- no_customizable_journals = Journal::CustomizableJournal
- .where(customizable_journals_table[:journal_id].eq(journals_table[:id]))
- .arel
- .exists.not
-
- # Filter out the journals that contain only disabled custom field changes,
- # journals with no custom fields or with enabled custom fields changes are returned.
- # This filtering is necessary for 2 reasons:
- # 1. The disabled fields will be filtered out in the ActivityEagerLoadingWrapper, which can
- # lead to displaying empty journals, if only a disabled custom field change is journaled.
- # 2. The empty journals cannot be dropped in the ActivityEagerLoadingWrapper, because
- # that would lead to not respecting the limit parameter. For example, if the results
- # are limited to 10 journals and 1 empty journal is dropped, then the number of
- # returned journals would be 9 instead of 10.
- # To avoid this issue, the journals that have only disabled custom field changes
- # should be excluded from the query.
- #
- # TODO: Handle the case when the project title is changed alongside a disabled custom field.
- query.where(enabled_customizable_journals.or(no_customizable_journals))
- end
- # rubocop:enable Metrics/AbcSize
-
def projects_reference_table
journals_table
end