@@ -31,9 +31,10 class QueriesController < ApplicationController | |||||
31 | else |
|
31 | else | |
32 | @limit = per_page_option |
|
32 | @limit = per_page_option | |
33 | end |
|
33 | end | |
34 | @query_count = IssueQuery.visible.count |
|
34 | scope = query_class.visible | |
|
35 | @query_count = scope.count | |||
35 | @query_pages = Paginator.new @query_count, @limit, params['page'] |
|
36 | @query_pages = Paginator.new @query_count, @limit, params['page'] | |
36 |
@queries = |
|
37 | @queries = scope. | |
37 | order("#{Query.table_name}.name"). |
|
38 | order("#{Query.table_name}.name"). | |
38 | limit(@limit). |
|
39 | limit(@limit). | |
39 | offset(@offset). |
|
40 | offset(@offset). | |
@@ -45,14 +46,14 class QueriesController < ApplicationController | |||||
45 | end |
|
46 | end | |
46 |
|
47 | |||
47 | def new |
|
48 | def new | |
48 |
@query = |
|
49 | @query = query_class.new | |
49 | @query.user = User.current |
|
50 | @query.user = User.current | |
50 | @query.project = @project |
|
51 | @query.project = @project | |
51 | @query.build_from_params(params) |
|
52 | @query.build_from_params(params) | |
52 | end |
|
53 | end | |
53 |
|
54 | |||
54 | def create |
|
55 | def create | |
55 |
@query = |
|
56 | @query = query_class.new | |
56 | @query.user = User.current |
|
57 | @query.user = User.current | |
57 | @query.project = @project |
|
58 | @query.project = @project | |
58 | update_query_from_params |
|
59 | update_query_from_params | |
@@ -84,9 +85,10 class QueriesController < ApplicationController | |||||
84 | redirect_to_issues(:set_filter => 1) |
|
85 | redirect_to_issues(:set_filter => 1) | |
85 | end |
|
86 | end | |
86 |
|
87 | |||
87 | private |
|
88 | private | |
|
89 | ||||
88 | def find_query |
|
90 | def find_query | |
89 |
@query = |
|
91 | @query = Query.find(params[:id]) | |
90 | @project = @query.project |
|
92 | @project = @query.project | |
91 | render_403 unless @query.editable_by?(User.current) |
|
93 | render_403 unless @query.editable_by?(User.current) | |
92 | rescue ActiveRecord::RecordNotFound |
|
94 | rescue ActiveRecord::RecordNotFound | |
@@ -107,10 +109,10 private | |||||
107 | @query.sort_criteria = params[:query] && params[:query][:sort_criteria] |
|
109 | @query.sort_criteria = params[:query] && params[:query][:sort_criteria] | |
108 | @query.name = params[:query] && params[:query][:name] |
|
110 | @query.name = params[:query] && params[:query][:name] | |
109 | if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? |
|
111 | if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? | |
110 |
@query.visibility = (params[:query] && params[:query][:visibility]) || |
|
112 | @query.visibility = (params[:query] && params[:query][:visibility]) || Query::VISIBILITY_PRIVATE | |
111 | @query.role_ids = params[:query] && params[:query][:role_ids] |
|
113 | @query.role_ids = params[:query] && params[:query][:role_ids] | |
112 | else |
|
114 | else | |
113 |
@query.visibility = |
|
115 | @query.visibility = Query::VISIBILITY_PRIVATE | |
114 | end |
|
116 | end | |
115 | @query |
|
117 | @query | |
116 | end |
|
118 | end | |
@@ -126,4 +128,10 private | |||||
126 | redirect_to _project_issues_path(@project, options) |
|
128 | redirect_to _project_issues_path(@project, options) | |
127 | end |
|
129 | end | |
128 | end |
|
130 | end | |
|
131 | ||||
|
132 | # Returns the Query subclass, IssueQuery by default | |||
|
133 | # for compatibility with previous behaviour | |||
|
134 | def query_class | |||
|
135 | Query.get_subclass(params[:type] || 'IssueQuery') | |||
|
136 | end | |||
129 | end |
|
137 | end |
@@ -144,6 +144,8 class Query < ActiveRecord::Base | |||||
144 | class StatementInvalid < ::ActiveRecord::StatementInvalid |
|
144 | class StatementInvalid < ::ActiveRecord::StatementInvalid | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
|
147 | include Redmine::SubclassFactory | |||
|
148 | ||||
147 | VISIBILITY_PRIVATE = 0 |
|
149 | VISIBILITY_PRIVATE = 0 | |
148 | VISIBILITY_ROLES = 1 |
|
150 | VISIBILITY_ROLES = 1 | |
149 | VISIBILITY_PUBLIC = 2 |
|
151 | VISIBILITY_PUBLIC = 2 |
General Comments 0
You need to be logged in to leave comments.
Login now