@@ -1,81 +1,81 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | |
21 | before_filter :find_optional_project, :only => :new |
|
21 | before_filter :find_optional_project, :only => :new | |
22 |
|
22 | |||
23 | def new |
|
23 | def new | |
24 | @query = Query.new(params[:query]) |
|
24 | @query = Query.new(params[:query]) | |
25 | @query.project = params[:query_is_for_all] ? nil : @project |
|
25 | @query.project = params[:query_is_for_all] ? nil : @project | |
26 | @query.user = User.current |
|
26 | @query.user = User.current | |
27 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
27 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
28 | @query.column_names = nil if params[:default_columns] |
|
28 | @query.column_names = nil if params[:default_columns] | |
29 |
|
29 | |||
30 | params[:fields].each do |field| |
|
30 | params[:fields].each do |field| | |
31 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
31 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
32 | end if params[:fields] |
|
32 | end if params[:fields] | |
33 | @query.group_by ||= params[:group_by] |
|
33 | @query.group_by ||= params[:group_by] | |
34 |
|
34 | |||
35 | if request.post? && params[:confirm] && @query.save |
|
35 | if request.post? && params[:confirm] && @query.save | |
36 | flash[:notice] = l(:notice_successful_create) |
|
36 | flash[:notice] = l(:notice_successful_create) | |
37 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
|
37 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
38 | return |
|
38 | return | |
39 | end |
|
39 | end | |
40 | render :layout => false if request.xhr? |
|
40 | render :layout => false if request.xhr? | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def edit |
|
43 | def edit | |
44 | if request.post? |
|
44 | if request.post? | |
45 | @query.filters = {} |
|
45 | @query.filters = {} | |
46 | params[:fields].each do |field| |
|
46 | params[:fields].each do |field| | |
47 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
47 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
48 | end if params[:fields] |
|
48 | end if params[:fields] | |
49 | @query.attributes = params[:query] |
|
49 | @query.attributes = params[:query] | |
50 | @query.project = nil if params[:query_is_for_all] |
|
50 | @query.project = nil if params[:query_is_for_all] | |
51 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
51 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
52 | @query.column_names = nil if params[:default_columns] |
|
52 | @query.column_names = nil if params[:default_columns] | |
53 |
|
53 | |||
54 | if @query.save |
|
54 | if @query.save | |
55 | flash[:notice] = l(:notice_successful_update) |
|
55 | flash[:notice] = l(:notice_successful_update) | |
56 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
|
56 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
57 | end |
|
57 | end | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def destroy |
|
61 | def destroy | |
62 | @query.destroy if request.post? |
|
62 | @query.destroy if request.post? | |
63 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 |
|
63 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | private |
|
66 | private | |
67 | def find_query |
|
67 | def find_query | |
68 | @query = Query.find(params[:id]) |
|
68 | @query = Query.find(params[:id]) | |
69 | @project = @query.project |
|
69 | @project = @query.project | |
70 | render_403 unless @query.editable_by?(User.current) |
|
70 | render_403 unless @query.editable_by?(User.current) | |
71 | rescue ActiveRecord::RecordNotFound |
|
71 | rescue ActiveRecord::RecordNotFound | |
72 | render_404 |
|
72 | render_404 | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def find_optional_project |
|
75 | def find_optional_project | |
76 | @project = Project.find(params[:project_id]) if 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 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) | |
78 | rescue ActiveRecord::RecordNotFound |
|
78 | rescue ActiveRecord::RecordNotFound | |
79 | render_404 |
|
79 | render_404 | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end |
General Comments 0
You need to be logged in to leave comments.
Login now