1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-04 22:59:47 +00:00

Adds scopes for retrieving the appropriate queries (#14790).

git-svn-id: http://svn.redmine.org/redmine/trunk@15641 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2016-07-12 17:45:39 +00:00
parent b5d2ddedfa
commit 275bd514cd
2 changed files with 8 additions and 8 deletions

View File

@ -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)

View File

@ -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.