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