summaryrefslogtreecommitdiffstats
path: root/app/controllers/queries_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-30 12:29:07 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-30 12:29:07 +0000
commit287d86e3632546b06aeb955db8b0e5eea139082b (patch)
tree38d14393e22d0a577e0bed0f733c17c092c49e1b /app/controllers/queries_controller.rb
parentfaf1f1e812b385dcf88591eac6fc898f86947c75 (diff)
downloadredmine-287d86e3632546b06aeb955db8b0e5eea139082b.tar.gz
redmine-287d86e3632546b06aeb955db8b0e5eea139082b.zip
Queries can be marked as 'For all projects'. Such queries will be available on all projects and on the global issue list (#897, closes #671).
Only admin users can create/edit queries that are public and for all projects. Note: this change does not allow to save a query from the global issue list. You have to be inside a project but then you can mark the query as 'For all projects'. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1311 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/queries_controller.rb')
-rw-r--r--app/controllers/queries_controller.rb34
1 files changed, 16 insertions, 18 deletions
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index 0a762eee0..194b1df57 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -18,19 +18,14 @@
class QueriesController < ApplicationController
layout 'base'
menu_item :issues
- before_filter :find_project, :authorize
-
- def index
- @queries = @project.queries.find(:all,
- :order => "name ASC",
- :conditions => ["is_public = ? or user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
- end
+ before_filter :find_query, :except => :new
+ before_filter :find_project, :authorize, :only => :new
def new
@query = Query.new(params[:query])
- @query.project = @project
+ @query.project = params[:query_is_for_all] ? nil : @project
@query.user = User.current
- @query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
+ @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
@query.column_names = nil if params[:default_columns]
params[:fields].each do |field|
@@ -52,7 +47,8 @@ class QueriesController < ApplicationController
@query.add_filter(field, params[:operators][field], params[:values][field])
end if params[:fields]
@query.attributes = params[:query]
- @query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
+ @query.project = nil if params[:query_is_for_all]
+ @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
@query.column_names = nil if params[:default_columns]
if @query.save
@@ -64,18 +60,20 @@ class QueriesController < ApplicationController
def destroy
@query.destroy if request.post?
- redirect_to :controller => 'queries', :project_id => @project
+ redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
end
private
+ def find_query
+ @query = Query.find(params[:id])
+ @project = @query.project
+ render_403 unless @query.editable_by?(User.current)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
def find_project
- if params[:id]
- @query = Query.find(params[:id])
- @project = @query.project
- render_403 unless @query.editable_by?(User.current)
- else
- @project = Project.find(params[:project_id])
- end
+ @project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end