comparison .svn/pristine/f5/f567519f5d8f3ccd15069929ebb16c826537f452.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class QueriesController < ApplicationController
19 menu_item :issues
20 before_filter :find_query, :except => [:new, :create, :index]
21 before_filter :find_optional_project, :only => [:new, :create]
22
23 accept_api_auth :index
24
25 include QueriesHelper
26
27 def index
28 case params[:format]
29 when 'xml', 'json'
30 @offset, @limit = api_offset_and_limit
31 else
32 @limit = per_page_option
33 end
34
35 @query_count = IssueQuery.visible.count
36 @query_pages = Paginator.new @query_count, @limit, params['page']
37 @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name")
38
39 respond_to do |format|
40 format.api
41 end
42 end
43
44 def new
45 @query = IssueQuery.new
46 @query.user = User.current
47 @query.project = @project
48 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
49 @query.build_from_params(params)
50 end
51
52 def create
53 @query = IssueQuery.new(params[:query])
54 @query.user = User.current
55 @query.project = params[:query_is_for_all] ? nil : @project
56 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
57 @query.build_from_params(params)
58 @query.column_names = nil if params[:default_columns]
59
60 if @query.save
61 flash[:notice] = l(:notice_successful_create)
62 redirect_to _project_issues_path(@project, :query_id => @query)
63 else
64 render :action => 'new', :layout => !request.xhr?
65 end
66 end
67
68 def edit
69 end
70
71 def update
72 @query.attributes = params[:query]
73 @query.project = nil if params[:query_is_for_all]
74 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
75 @query.build_from_params(params)
76 @query.column_names = nil if params[:default_columns]
77
78 if @query.save
79 flash[:notice] = l(:notice_successful_update)
80 redirect_to _project_issues_path(@project, :query_id => @query)
81 else
82 render :action => 'edit'
83 end
84 end
85
86 def destroy
87 @query.destroy
88 redirect_to _project_issues_path(@project, :set_filter => 1)
89 end
90
91 private
92 def find_query
93 @query = IssueQuery.find(params[:id])
94 @project = @query.project
95 render_403 unless @query.editable_by?(User.current)
96 rescue ActiveRecord::RecordNotFound
97 render_404
98 end
99
100 def find_optional_project
101 @project = Project.find(params[:project_id]) if params[:project_id]
102 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
103 rescue ActiveRecord::RecordNotFound
104 render_404
105 end
106 end