##// END OF EJS Templates
Global queries can be saved from the global issue list (follows r1311 and closes #897)....
Jean-Philippe Lang -
r1297:da641f4122f7
parent child
Show More
@@ -19,7 +19,7 class QueriesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :issues
20 menu_item :issues
21 before_filter :find_query, :except => :new
21 before_filter :find_query, :except => :new
22 before_filter :find_project, :authorize, :only => :new
22 before_filter :find_optional_project, :only => :new
23
23
24 def new
24 def new
25 @query = Query.new(params[:query])
25 @query = Query.new(params[:query])
@@ -72,8 +72,9 private
72 render_404
72 render_404
73 end
73 end
74
74
75 def find_project
75 def find_optional_project
76 @project = Project.find(params[:project_id])
76 @project = Project.find(params[:project_id]) if params[:project_id]
77 User.current.allowed_to?(:save_queries, @project, :global => true)
77 rescue ActiveRecord::RecordNotFound
78 rescue ActiveRecord::RecordNotFound
78 render_404
79 render_404
79 end
80 end
@@ -222,17 +222,26 class User < ActiveRecord::Base
222 # action can be:
222 # action can be:
223 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
223 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
224 # * a permission Symbol (eg. :edit_project)
224 # * a permission Symbol (eg. :edit_project)
225 def allowed_to?(action, project)
225 def allowed_to?(action, project, options={})
226 # No action allowed on archived projects
226 if project
227 return false unless project.active?
227 # No action allowed on archived projects
228 # No action allowed on disabled modules
228 return false unless project.active?
229 return false unless project.allows_to?(action)
229 # No action allowed on disabled modules
230 # Admin users are authorized for anything else
230 return false unless project.allows_to?(action)
231 return true if admin?
231 # Admin users are authorized for anything else
232
232 return true if admin?
233 role = role_for_project(project)
233
234 return false unless role
234 role = role_for_project(project)
235 role.allowed_to?(action) && (project.is_public? || role.member?)
235 return false unless role
236 role.allowed_to?(action) && (project.is_public? || role.member?)
237
238 elsif options[:global]
239 # authorize if user has at least one role that has this permission
240 roles = memberships.collect {|m| m.role}.uniq
241 roles.detect {|r| r.allowed_to?(action)}
242 else
243 false
244 end
236 end
245 end
237
246
238 def self.current=(user)
247 def self.current=(user)
@@ -1,6 +1,6
1 <% if @project %>
2 <h3><%= l(:label_issue_plural) %></h3>
1 <h3><%= l(:label_issue_plural) %></h3>
3 <%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %><br />
2 <%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %><br />
3 <% if @project %>
4 <%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %><br />
4 <%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %><br />
5 <%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %>
5 <%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %>
6 <% end %>
6 <% end %>
@@ -18,7 +18,7
18 :update => "content",
18 :update => "content",
19 }, :class => 'icon icon-reload' %>
19 }, :class => 'icon icon-reload' %>
20
20
21 <% if current_role && current_role.allowed_to?(:save_queries) %>
21 <% if User.current.allowed_to?(:save_queries, @project, :global => true) %>
22 <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
22 <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
23 <% end %>
23 <% end %>
24 </p>
24 </p>
@@ -31,7 +31,7 class QueriesControllerTest < Test::Unit::TestCase
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_get_new
34 def test_get_new_project_query
35 @request.session[:user_id] = 2
35 @request.session[:user_id] = 2
36 get :new, :project_id => 1
36 get :new, :project_id => 1
37 assert_response :success
37 assert_response :success
@@ -45,6 +45,19 class QueriesControllerTest < Test::Unit::TestCase
45 :disabled => nil }
45 :disabled => nil }
46 end
46 end
47
47
48 def test_get_new_global_query
49 @request.session[:user_id] = 2
50 get :new
51 assert_response :success
52 assert_template 'new'
53 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
54 :name => 'query[is_public]' }
55 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
56 :name => 'query_is_for_all',
57 :checked => 'checked',
58 :disabled => nil }
59 end
60
48 def test_new_project_public_query
61 def test_new_project_public_query
49 @request.session[:user_id] = 2
62 @request.session[:user_id] = 2
50 post :new,
63 post :new,
@@ -54,8 +67,7 class QueriesControllerTest < Test::Unit::TestCase
54 :fields => ["status_id", "assigned_to_id"],
67 :fields => ["status_id", "assigned_to_id"],
55 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
68 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
56 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
69 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
57 :query => {"name" => "test_new_project_public_query", "is_public" => "1"},
70 :query => {"name" => "test_new_project_public_query", "is_public" => "1"}
58 :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"]
59
71
60 q = Query.find_by_name('test_new_project_public_query')
72 q = Query.find_by_name('test_new_project_public_query')
61 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
73 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
@@ -73,8 +85,7 class QueriesControllerTest < Test::Unit::TestCase
73 :fields => ["status_id", "assigned_to_id"],
85 :fields => ["status_id", "assigned_to_id"],
74 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
86 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
75 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
87 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
76 :query => {"name" => "test_new_project_private_query", "is_public" => "1"},
88 :query => {"name" => "test_new_project_private_query", "is_public" => "1"}
77 :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"]
78
89
79 q = Query.find_by_name('test_new_project_private_query')
90 q = Query.find_by_name('test_new_project_private_query')
80 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
91 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
@@ -83,6 +94,23 class QueriesControllerTest < Test::Unit::TestCase
83 assert q.valid?
94 assert q.valid?
84 end
95 end
85
96
97 def test_new_global_private_query_with_custom_columns
98 @request.session[:user_id] = 3
99 post :new,
100 :confirm => '1',
101 :fields => ["status_id", "assigned_to_id"],
102 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
103 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
104 :query => {"name" => "test_new_global_private_query", "is_public" => "1", "column_names" => ["", "tracker", "subject", "priority", "category"]}
105
106 q = Query.find_by_name('test_new_global_private_query')
107 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q
108 assert !q.is_public?
109 assert !q.has_default_columns?
110 assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
111 assert q.valid?
112 end
113
86 def test_get_edit_global_public_query
114 def test_get_edit_global_public_query
87 @request.session[:user_id] = 1
115 @request.session[:user_id] = 1
88 get :edit, :id => 4
116 get :edit, :id => 4
@@ -106,8 +134,7 class QueriesControllerTest < Test::Unit::TestCase
106 :fields => ["status_id", "assigned_to_id"],
134 :fields => ["status_id", "assigned_to_id"],
107 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
135 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
108 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
136 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
109 :query => {"name" => "test_edit_global_public_query", "is_public" => "1"},
137 :query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
110 :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"]
111
138
112 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
139 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
113 q = Query.find_by_name('test_edit_global_public_query')
140 q = Query.find_by_name('test_edit_global_public_query')
@@ -138,8 +165,7 class QueriesControllerTest < Test::Unit::TestCase
138 :fields => ["status_id", "assigned_to_id"],
165 :fields => ["status_id", "assigned_to_id"],
139 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
166 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
140 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
167 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
141 :query => {"name" => "test_edit_global_private_query", "is_public" => "1"},
168 :query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
142 :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"]
143
169
144 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
170 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
145 q = Query.find_by_name('test_edit_global_private_query')
171 q = Query.find_by_name('test_edit_global_private_query')
General Comments 0
You need to be logged in to leave comments. Login now