Commit 43a9d967 authored by jplang's avatar jplang
Browse files

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

git-svn-id: e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a5085088
......@@ -279,14 +279,7 @@ module QueriesHelper
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 = ?",]).
@sidebar_queries ||= IssueQuery.visible.global_or_on_project(@project).sorted.to_a
def query_links(title, queries)
......@@ -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,]))
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.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment