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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[34001] Ensure filters always receive the query context
Oliver Günthere1a88a9a404b
diff --git a/app/models/query.rb b/app/models/query.rbindex 036fc19fd1e..935ea8884f6 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -77,22 +77,15 @@ class Query < ApplicationRecordendend- after_initialize :set_context- # For some reasons the filters loose their context- # between the after_save and the after_commit callback.- after_commit :set_context-- def set_context- # We need to set the project for each filter if a project- # is present because the information is not available when- # deserializing the filters from the db.-- # Allow to use AR's select(...) without- # the filters attribute- return unless respond_to?(:filters)-- filters.each do |filter|- filter.context = self+ ##+ # Ensure the filters receive+ # the query context as this appears to be lost+ # whenever the field is reloaded from the serialized value+ def filters+ super.tap do |filters|+ filters.each do |filter|+ filter.context = self+ endendenddiff --git a/app/services/queries/copy_service.rb b/app/services/queries/copy_service.rbindex 95641cbd611..5b1acb0539d 100644--- a/app/services/queries/copy_service.rb+++ b/app/services/queries/copy_service.rb@@ -43,7 +43,6 @@ module Queriesnew_query = ::Query.new source.attributes.dup.except(*skipped_attributes)new_query.sort_criteria = source.sort_criteria if source.sort_criterianew_query.project = state.project || source.project- new_query.set_contextServiceResult.new(success: new_query.save, result: new_query)enddiff --git a/app/workers/work_packages/exports/export_job.rb b/app/workers/work_packages/exports/export_job.rbindex 0442293291f..56b6858bcfe 100644--- a/app/workers/work_packages/exports/export_job.rb+++ b/app/workers/work_packages/exports/export_job.rb@@ -50,7 +50,6 @@ module WorkPackagesquery.tap do |q|q.attributes = query_attributesq.filters = filters- q.set_contextendenddiff --git a/lib/api/v3/work_packages/schema/form_configurations/query_representer.rb b/lib/api/v3/work_packages/schema/form_configurations/query_representer.rbindex ec9ab8cdac8..13b2c68acda 100644--- a/lib/api/v3/work_packages/schema/form_configurations/query_representer.rb+++ b/lib/api/v3/work_packages/schema/form_configurations/query_representer.rb@@ -50,9 +50,6 @@ module APIgetter: ->(*) donext unless embed_links- # For some reason, the context (query) of the filters- # are lost. We therefore set it anew:- query.set_context::API::V3::Queries::QueryRepresenter.new(query, current_user: current_user)end