##// END OF EJS Templates
Merged r3611 from trunk....
Jean-Philippe Lang -
r3546:390eb7849ca9
parent child
Show More
@@ -1,81 +1,81
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class QueriesController < ApplicationController
19 19 menu_item :issues
20 20 before_filter :find_query, :except => :new
21 21 before_filter :find_optional_project, :only => :new
22 22
23 23 def new
24 24 @query = Query.new(params[:query])
25 25 @query.project = params[:query_is_for_all] ? nil : @project
26 26 @query.user = User.current
27 27 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
28 28 @query.column_names = nil if params[:default_columns]
29 29
30 30 params[:fields].each do |field|
31 31 @query.add_filter(field, params[:operators][field], params[:values][field])
32 32 end if params[:fields]
33 33 @query.group_by ||= params[:group_by]
34 34
35 35 if request.post? && params[:confirm] && @query.save
36 36 flash[:notice] = l(:notice_successful_create)
37 37 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
38 38 return
39 39 end
40 40 render :layout => false if request.xhr?
41 41 end
42 42
43 43 def edit
44 44 if request.post?
45 45 @query.filters = {}
46 46 params[:fields].each do |field|
47 47 @query.add_filter(field, params[:operators][field], params[:values][field])
48 48 end if params[:fields]
49 49 @query.attributes = params[:query]
50 50 @query.project = nil if params[:query_is_for_all]
51 51 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
52 52 @query.column_names = nil if params[:default_columns]
53 53
54 54 if @query.save
55 55 flash[:notice] = l(:notice_successful_update)
56 56 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
57 57 end
58 58 end
59 59 end
60 60
61 61 def destroy
62 62 @query.destroy if request.post?
63 63 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
64 64 end
65 65
66 66 private
67 67 def find_query
68 68 @query = Query.find(params[:id])
69 69 @project = @query.project
70 70 render_403 unless @query.editable_by?(User.current)
71 71 rescue ActiveRecord::RecordNotFound
72 72 render_404
73 73 end
74 74
75 75 def find_optional_project
76 76 @project = Project.find(params[:project_id]) if params[:project_id]
77 User.current.allowed_to?(:save_queries, @project, :global => true)
77 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
78 78 rescue ActiveRecord::RecordNotFound
79 79 render_404
80 80 end
81 81 end
General Comments 0
You need to be logged in to leave comments. Login now