@@ -48,17 +48,14 class QueriesController < ApplicationController | |||
|
48 | 48 | @query = IssueQuery.new |
|
49 | 49 | @query.user = User.current |
|
50 | 50 | @query.project = @project |
|
51 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
52 | 51 | @query.build_from_params(params) |
|
53 | 52 | end |
|
54 | 53 | |
|
55 | 54 | def create |
|
56 |
@query = IssueQuery.new |
|
|
55 | @query = IssueQuery.new | |
|
57 | 56 | @query.user = User.current |
|
58 |
@query.project = |
|
|
59 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
60 | @query.build_from_params(params) | |
|
61 | @query.column_names = nil if params[:default_columns] | |
|
57 | @query.project = @project | |
|
58 | update_query_from_params | |
|
62 | 59 | |
|
63 | 60 | if @query.save |
|
64 | 61 | flash[:notice] = l(:notice_successful_create) |
@@ -72,11 +69,7 class QueriesController < ApplicationController | |||
|
72 | 69 | end |
|
73 | 70 | |
|
74 | 71 | def update |
|
75 | @query.attributes = params[:query] | |
|
76 | @query.project = nil if params[:query_is_for_all] | |
|
77 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
78 | @query.build_from_params(params) | |
|
79 | @query.column_names = nil if params[:default_columns] | |
|
72 | update_query_from_params | |
|
80 | 73 | |
|
81 | 74 | if @query.save |
|
82 | 75 | flash[:notice] = l(:notice_successful_update) |
@@ -107,6 +100,20 private | |||
|
107 | 100 | render_404 |
|
108 | 101 | end |
|
109 | 102 | |
|
103 | def update_query_from_params | |
|
104 | @query.project = params[:query_is_for_all] ? nil : @project | |
|
105 | @query.build_from_params(params) | |
|
106 | @query.column_names = nil if params[:default_columns] | |
|
107 | @query.sort_criteria = params[:query] && params[:query][:sort_criteria] | |
|
108 | @query.name = params[:query] && params[:query][:name] | |
|
109 | if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? | |
|
110 | @query.visibility = (params[:query] && params[:query][:visibility]) || IssueQuery::VISIBILITY_PRIVATE | |
|
111 | else | |
|
112 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE | |
|
113 | end | |
|
114 | @query | |
|
115 | end | |
|
116 | ||
|
110 | 117 | def redirect_to_issues(options) |
|
111 | 118 | if params[:gantt] |
|
112 | 119 | if @project |
@@ -487,7 +487,9 class Query < ActiveRecord::Base | |||
|
487 | 487 | if arg.is_a?(Hash) |
|
488 | 488 | arg = arg.keys.sort.collect {|k| arg[k]} |
|
489 | 489 | end |
|
490 | c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, (o == 'desc' || o == false) ? 'desc' : 'asc']} | |
|
490 | if arg | |
|
491 | c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, (o == 'desc' || o == false) ? 'desc' : 'asc']} | |
|
492 | end | |
|
491 | 493 | write_attribute(:sort_criteria, c) |
|
492 | 494 | end |
|
493 | 495 |
@@ -7,21 +7,20 | |||
|
7 | 7 | <p><label for="query_name"><%=l(:field_name)%></label> |
|
8 | 8 | <%= text_field 'query', 'name', :size => 80 %></p> |
|
9 | 9 | |
|
10 | <% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %> | |
|
10 | <% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @query.project) %> | |
|
11 | 11 | <p><label><%=l(:field_visible)%></label> |
|
12 | 12 | <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PRIVATE %> <%= l(:label_visibility_private) %></label> |
|
13 | <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PUBLIC %> <%= l(:label_visibility_public) %></label> | |
|
13 | 14 | <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_ROLES %> <%= l(:label_visibility_roles) %>:</label> |
|
14 | 15 | <% Role.givable.sorted.each do |role| %> |
|
15 | 16 | <label class="block role-visibility"><%= check_box_tag 'query[role_ids][]', role.id, @query.roles.include?(role), :id => nil %> <%= role.name %></label> |
|
16 | 17 | <% end %> |
|
17 | <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PUBLIC %> <%= l(:label_visibility_public) %></label> | |
|
18 | 18 | <%= hidden_field_tag 'query[role_ids][]', '' %> |
|
19 | 19 | </p> |
|
20 | 20 | <% end %> |
|
21 | 21 | |
|
22 | 22 | <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label> |
|
23 | <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, | |
|
24 | :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %></p> | |
|
23 | <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :class => (User.current.admin? ? '' : 'disable-unless-private') %></p> | |
|
25 | 24 | |
|
26 | 25 | <% unless params[:gantt] %> |
|
27 | 26 | <fieldset><legend><%= l(:label_options) %></legend> |
@@ -80,8 +79,11 | |||
|
80 | 79 | <%= javascript_tag do %> |
|
81 | 80 | $(document).ready(function(){ |
|
82 | 81 | $("input[name='query[visibility]']").change(function(){ |
|
83 | var checked = $('#query_visibility_1').is(':checked'); | |
|
84 | $("input[name='query[role_ids][]'][type=checkbox]").attr('disabled', !checked); | |
|
82 | var roles_checked = $('#query_visibility_1').is(':checked'); | |
|
83 | var private_checked = $('#query_visibility_0').is(':checked'); | |
|
84 | $("input[name='query[role_ids][]'][type=checkbox]").attr('disabled', !roles_checked); | |
|
85 | if (!private_checked) $("input.disable-unless-private").attr('checked', false); | |
|
86 | $("input.disable-unless-private").attr('disabled', !private_checked); | |
|
85 | 87 | }).trigger('change'); |
|
86 | 88 | }); |
|
87 | 89 | <% end %> |
@@ -83,7 +83,7 class QueriesControllerTest < ActionController::TestCase | |||
|
83 | 83 | :fields => ["status_id", "assigned_to_id"], |
|
84 | 84 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
85 | 85 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
86 |
:query => {"name" => "test_new_project_private_query", "visibility" => " |
|
|
86 | :query => {"name" => "test_new_project_private_query", "visibility" => "0"} | |
|
87 | 87 | |
|
88 | 88 | q = Query.find_by_name('test_new_project_private_query') |
|
89 | 89 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
@@ -98,7 +98,7 class QueriesControllerTest < ActionController::TestCase | |||
|
98 | 98 | :fields => ["status_id", "assigned_to_id"], |
|
99 | 99 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
100 | 100 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
101 |
:query => {"name" => "test_new_global_private_query", "visibility" => " |
|
|
101 | :query => {"name" => "test_new_global_private_query", "visibility" => "0"}, | |
|
102 | 102 | :c => ["", "tracker", "subject", "priority", "category"] |
|
103 | 103 | |
|
104 | 104 | q = Query.find_by_name('test_new_global_private_query') |
@@ -119,6 +119,7 class QueriesControllerTest < ActionController::TestCase | |||
|
119 | 119 | |
|
120 | 120 | q = Query.find_by_name('test_new_global_query') |
|
121 | 121 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
122 | assert !q.is_public? | |
|
122 | 123 | assert !q.has_filter?(:status_id) |
|
123 | 124 | assert_equal ['assigned_to_id'], q.filters.keys |
|
124 | 125 | assert q.valid? |
@@ -186,13 +187,73 class QueriesControllerTest < ActionController::TestCase | |||
|
186 | 187 | assert_equal false, query.draw_progress_line |
|
187 | 188 | end |
|
188 | 189 | |
|
190 | def test_create_project_public_query_should_force_private_without_manage_public_queries_permission | |
|
191 | @request.session[:user_id] = 3 | |
|
192 | query = new_record(Query) do | |
|
193 | post :create, | |
|
194 | :project_id => 'ecookbook', | |
|
195 | :query => {"name" => "name", "visibility" => "2"} | |
|
196 | assert_response 302 | |
|
197 | end | |
|
198 | assert_not_nil query.project | |
|
199 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
|
200 | end | |
|
201 | ||
|
202 | def test_create_global_public_query_should_force_private_without_manage_public_queries_permission | |
|
203 | @request.session[:user_id] = 3 | |
|
204 | query = new_record(Query) do | |
|
205 | post :create, | |
|
206 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
|
207 | :query => {"name" => "name", "visibility" => "2"} | |
|
208 | assert_response 302 | |
|
209 | end | |
|
210 | assert_nil query.project | |
|
211 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
|
212 | end | |
|
213 | ||
|
214 | def test_create_project_public_query_with_manage_public_queries_permission | |
|
215 | @request.session[:user_id] = 2 | |
|
216 | query = new_record(Query) do | |
|
217 | post :create, | |
|
218 | :project_id => 'ecookbook', | |
|
219 | :query => {"name" => "name", "visibility" => "2"} | |
|
220 | assert_response 302 | |
|
221 | end | |
|
222 | assert_not_nil query.project | |
|
223 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility | |
|
224 | end | |
|
225 | ||
|
226 | def test_create_global_public_query_should_force_private_with_manage_public_queries_permission | |
|
227 | @request.session[:user_id] = 2 | |
|
228 | query = new_record(Query) do | |
|
229 | post :create, | |
|
230 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
|
231 | :query => {"name" => "name", "visibility" => "2"} | |
|
232 | assert_response 302 | |
|
233 | end | |
|
234 | assert_nil query.project | |
|
235 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
|
236 | end | |
|
237 | ||
|
238 | def test_create_global_public_query_by_admin | |
|
239 | @request.session[:user_id] = 1 | |
|
240 | query = new_record(Query) do | |
|
241 | post :create, | |
|
242 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
|
243 | :query => {"name" => "name", "visibility" => "2"} | |
|
244 | assert_response 302 | |
|
245 | end | |
|
246 | assert_nil query.project | |
|
247 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility | |
|
248 | end | |
|
249 | ||
|
189 | 250 | def test_edit_global_public_query |
|
190 | 251 | @request.session[:user_id] = 1 |
|
191 | 252 | get :edit, :id => 4 |
|
192 | 253 | assert_response :success |
|
193 | 254 | assert_template 'edit' |
|
194 | 255 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
195 |
assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked] |
|
|
256 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' | |
|
196 | 257 | end |
|
197 | 258 | |
|
198 | 259 | def test_edit_global_private_query |
@@ -201,7 +262,7 class QueriesControllerTest < ActionController::TestCase | |||
|
201 | 262 | assert_response :success |
|
202 | 263 | assert_template 'edit' |
|
203 | 264 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
204 |
assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked] |
|
|
265 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' | |
|
205 | 266 | end |
|
206 | 267 | |
|
207 | 268 | def test_edit_project_private_query |
@@ -210,7 +271,7 class QueriesControllerTest < ActionController::TestCase | |||
|
210 | 271 | assert_response :success |
|
211 | 272 | assert_template 'edit' |
|
212 | 273 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
213 |
assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]) |
|
|
274 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' | |
|
214 | 275 | end |
|
215 | 276 | |
|
216 | 277 | def test_edit_project_public_query |
@@ -219,7 +280,7 class QueriesControllerTest < ActionController::TestCase | |||
|
219 | 280 | assert_response :success |
|
220 | 281 | assert_template 'edit' |
|
221 | 282 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
222 |
assert_select 'input[name=query_is_for_all][type=checkbox] |
|
|
283 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' | |
|
223 | 284 | end |
|
224 | 285 | |
|
225 | 286 | def test_edit_sort_criteria |
@@ -180,6 +180,15 class ActiveSupport::TestCase | |||
|
180 | 180 | ActiveRecord::Base.connection.quoted_date(date) |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | # Asserts that a new record for the given class is created | |
|
184 | # and returns it | |
|
185 | def new_record(klass, &block) | |
|
186 | assert_difference "#{klass}.count" do | |
|
187 | yield | |
|
188 | end | |
|
189 | klass.order(:id => :desc).first | |
|
190 | end | |
|
191 | ||
|
183 | 192 | def assert_save(object) |
|
184 | 193 | saved = object.save |
|
185 | 194 | message = "#{object.class} could not be saved" |
General Comments 0
You need to be logged in to leave comments.
Login now