comparison app/controllers/queries_controller.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 class QueriesController < ApplicationController 18 class QueriesController < ApplicationController
19 menu_item :issues 19 menu_item :issues
20 before_filter :find_query, :except => :new 20 before_filter :find_query, :except => [:new, :create, :index]
21 before_filter :find_optional_project, :only => :new 21 before_filter :find_optional_project, :only => [:new, :create]
22 22
23 def new 23 accept_api_auth :index
24 @query = Query.new(params[:query]) 24
25 @query.project = params[:query_is_for_all] ? nil : @project 25 include QueriesHelper
26 @query.user = User.current 26
27 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? 27 def index
28 28 case params[:format]
29 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] 29 when 'xml', 'json'
30 @query.group_by ||= params[:group_by] 30 @offset, @limit = api_offset_and_limit
31 @query.column_names = params[:c] if params[:c] 31 else
32 @query.column_names = nil if params[:default_columns] 32 @limit = per_page_option
33
34 if request.post? && params[:confirm] && @query.save
35 flash[:notice] = l(:notice_successful_create)
36 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
37 return
38 end 33 end
39 render :layout => false if request.xhr? 34
40 end 35 @query_count = Query.visible.count
41 36 @query_pages = Paginator.new self, @query_count, @limit, params['page']
42 def edit 37 @queries = Query.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name")
43 if request.post? 38
44 @query.filters = {} 39 respond_to do |format|
45 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] 40 format.html { render :nothing => true }
46 @query.attributes = params[:query] 41 format.api
47 @query.project = nil if params[:query_is_for_all]
48 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
49 @query.group_by ||= params[:group_by]
50 @query.column_names = params[:c] if params[:c]
51 @query.column_names = nil if params[:default_columns]
52
53 if @query.save
54 flash[:notice] = l(:notice_successful_update)
55 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
56 end
57 end 42 end
58 end 43 end
59 44
45 def new
46 @query = Query.new
47 @query.user = User.current
48 @query.project = @project
49 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
50 build_query_from_params
51 end
52
53 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
54 def create
55 @query = Query.new(params[:query])
56 @query.user = User.current
57 @query.project = params[:query_is_for_all] ? nil : @project
58 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
59 build_query_from_params
60 @query.column_names = nil if params[:default_columns]
61
62 if @query.save
63 flash[:notice] = l(:notice_successful_create)
64 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
65 else
66 render :action => 'new', :layout => !request.xhr?
67 end
68 end
69
70 def edit
71 end
72
73 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
74 def update
75 @query.attributes = params[:query]
76 @query.project = nil if params[:query_is_for_all]
77 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
78 build_query_from_params
79 @query.column_names = nil if params[:default_columns]
80
81 if @query.save
82 flash[:notice] = l(:notice_successful_update)
83 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
84 else
85 render :action => 'edit'
86 end
87 end
88
89 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
60 def destroy 90 def destroy
61 @query.destroy if request.post? 91 @query.destroy
62 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 92 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
63 end 93 end
64 94
65 private 95 private
66 def find_query 96 def find_query
67 @query = Query.find(params[:id]) 97 @query = Query.find(params[:id])
68 @project = @query.project 98 @project = @query.project
69 render_403 unless @query.editable_by?(User.current) 99 render_403 unless @query.editable_by?(User.current)
70 rescue ActiveRecord::RecordNotFound 100 rescue ActiveRecord::RecordNotFound
71 render_404 101 render_404
72 end 102 end
73 103
74 def find_optional_project 104 def find_optional_project
75 @project = Project.find(params[:project_id]) if params[:project_id] 105 @project = Project.find(params[:project_id]) if params[:project_id]
76 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) 106 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
77 rescue ActiveRecord::RecordNotFound 107 rescue ActiveRecord::RecordNotFound
78 render_404 108 render_404