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
[#36559] always pass `current_user` to a query
Tobias Dillmann19e9f1bba8c1
diff --git a/app/models/query.rb b/app/models/query.rbindex 3d5ab4097e0..0d7ac379e64 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -51,6 +51,8 @@ class Query < ApplicationRecordserialize :column_names, type: Arrayserialize :sort_criteria, type: Array+ attr_accessor :current_user+validates :include_subprojects,inclusion: [true, false]@@ -67,8 +69,9 @@ class Query < ApplicationRecordscope(:global, -> { where(project_id: nil) })- def self.new_default(attributes = nil)+ def self.new_default(attributes = nil, current_user = nil)new(attributes).tap do |query|+ query.current_user = current_userquery.add_default_filterquery.set_default_sortquery.show_hierarchies = true@@ -218,7 +221,7 @@ class Query < ApplicationRecordend@available_columns_project = project&.cache_key || 0- @available_columns = ::Query.available_columns(project, user)+ @available_columns = ::Query.available_columns(project, current_user)enddef self.available_columns(project = nil, current_user = nil)@@ -331,10 +334,11 @@ class Query < ApplicationRecorddef sort_criteria_columnssort_criteria- .map do |attribute, direction|+ .filter_map do |attribute, direction|attribute = attribute.to_sym+ col = sort_criteria_column(attribute)- [sort_criteria_column(attribute), direction]+ [col, direction] if colendenddiff --git a/lib/api/v3/queries/create_form_api.rb b/lib/api/v3/queries/create_form_api.rbindex 35a737940fd..050632724ff 100644--- a/lib/api/v3/queries/create_form_api.rb+++ b/lib/api/v3/queries/create_form_api.rb@@ -38,8 +38,7 @@ module APIhelpers ::API::V3::Queries::QueryHelperpost do- # TODO: is it wrong to pass the user here? A query belongs to a user, but that is the user that created the query?- create_or_update_query_form Query.new_default(user: current_user), ::Queries::CreateContract, CreateFormRepresenter+ create_or_update_query_form Query.new_default({}, current_user), ::Queries::CreateContract, CreateFormRepresenterendendenddiff --git a/lib/api/v3/queries/update_form_api.rb b/lib/api/v3/queries/update_form_api.rbindex af04dd5af45..ac3c5d0c3a6 100644--- a/lib/api/v3/queries/update_form_api.rb+++ b/lib/api/v3/queries/update_form_api.rb@@ -36,6 +36,8 @@ module APIhelpers ::API::V3::Queries::QueryHelperpost do+ @query.current_user = current_user+# We try to ignore invalid aspects of the query as the user# might not even be able to fix them (public query)# and because they might only be invalid in his context