annotate app/controllers/queries_controller.rb @ 1516:b450a9d58aed redmine-2.4

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