From 275bd514cd2197e1536fcee68459961ebf1e955f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 12 Jul 2016 17:45:39 +0000 Subject: [PATCH] Adds scopes for retrieving the appropriate queries (#14790). git-svn-id: http://svn.redmine.org/redmine/trunk@15641 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/queries_helper.rb | 9 +-------- app/models/query.rb | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 76d42bae5..52da20e84 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -279,14 +279,7 @@ module QueriesHelper end def sidebar_queries - unless @sidebar_queries - @sidebar_queries = IssueQuery.visible. - order("#{Query.table_name}.name ASC"). - # Project specific queries and global queries - where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). - to_a - end - @sidebar_queries + @sidebar_queries ||= IssueQuery.visible.global_or_on_project(@project).sorted.to_a end def query_links(title, queries) diff --git a/app/models/query.rb b/app/models/query.rb index 0a7546cf2..22f1fd898 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -234,6 +234,13 @@ class Query < ActiveRecord::Base # Permission required to view the queries, set on subclasses. class_attribute :view_permission + # Scope of queries that are global or on the given project + scope :global_or_on_project, lambda {|project| + where(:project_id => (project.nil? ? nil : [nil, project.id])) + } + + scope :sorted, lambda {order(:name, :id)} + # Scope of visible queries, can be used from subclasses only. # Unlike other visible scopes, a class methods is used as it # let handle inheritance more nicely than scope DSL. -- 2.39.5