From 9fb339c4e21b65a01e98032b1d5f349428934b17 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 11 Jul 2016 17:41:46 +0000 Subject: [PATCH] Makes QueriesController able to handle other Query subclasses. git-svn-id: http://svn.redmine.org/redmine/trunk@15635 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/queries_controller.rb | 24 ++++++++++++++++-------- app/models/query.rb | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 9b14d44eb..961b75dcc 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -31,9 +31,10 @@ class QueriesController < ApplicationController else @limit = per_page_option end - @query_count = IssueQuery.visible.count + scope = query_class.visible + @query_count = scope.count @query_pages = Paginator.new @query_count, @limit, params['page'] - @queries = IssueQuery.visible. + @queries = scope. order("#{Query.table_name}.name"). limit(@limit). offset(@offset). @@ -45,14 +46,14 @@ class QueriesController < ApplicationController end def new - @query = IssueQuery.new + @query = query_class.new @query.user = User.current @query.project = @project @query.build_from_params(params) end def create - @query = IssueQuery.new + @query = query_class.new @query.user = User.current @query.project = @project update_query_from_params @@ -84,9 +85,10 @@ class QueriesController < ApplicationController redirect_to_issues(:set_filter => 1) end -private + private + def find_query - @query = IssueQuery.find(params[:id]) + @query = Query.find(params[:id]) @project = @query.project render_403 unless @query.editable_by?(User.current) rescue ActiveRecord::RecordNotFound @@ -107,10 +109,10 @@ private @query.sort_criteria = params[:query] && params[:query][:sort_criteria] @query.name = params[:query] && params[:query][:name] if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? - @query.visibility = (params[:query] && params[:query][:visibility]) || IssueQuery::VISIBILITY_PRIVATE + @query.visibility = (params[:query] && params[:query][:visibility]) || Query::VISIBILITY_PRIVATE @query.role_ids = params[:query] && params[:query][:role_ids] else - @query.visibility = IssueQuery::VISIBILITY_PRIVATE + @query.visibility = Query::VISIBILITY_PRIVATE end @query end @@ -126,4 +128,10 @@ private redirect_to _project_issues_path(@project, options) end end + + # Returns the Query subclass, IssueQuery by default + # for compatibility with previous behaviour + def query_class + Query.get_subclass(params[:type] || 'IssueQuery') + end end diff --git a/app/models/query.rb b/app/models/query.rb index 8fab46669..33962e319 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -144,6 +144,8 @@ class Query < ActiveRecord::Base class StatementInvalid < ::ActiveRecord::StatementInvalid end + include Redmine::SubclassFactory + VISIBILITY_PRIVATE = 0 VISIBILITY_ROLES = 1 VISIBILITY_PUBLIC = 2 -- 2.39.5