| 
									
										
										
										
											2008-09-11 17:03:26 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2012-05-05 12:56:53 +00:00
										 |  |  | # Copyright (C) 2006-2012  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class IssuesController < ApplicationController | 
					
						
							| 
									
										
										
										
											2010-04-30 10:48:19 +00:00
										 |  |  |   menu_item :new_issue, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2009-10-21 17:07:18 +00:00
										 |  |  |   default_search_scope :issues | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-16 16:25:04 +00:00
										 |  |  |   before_filter :find_issue, :only => [:show, :edit, :update] | 
					
						
							| 
									
										
										
										
											2012-02-23 15:23:03 +00:00
										 |  |  |   before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |   before_filter :find_project, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2010-08-23 15:04:36 +00:00
										 |  |  |   before_filter :authorize, :except => [:index] | 
					
						
							|  |  |  |   before_filter :find_optional_project, :only => [:index] | 
					
						
							| 
									
										
										
										
											2010-04-26 15:08:06 +00:00
										 |  |  |   before_filter :check_for_default_issue_status, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   before_filter :build_new_issue_from_params, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   accept_rss_auth :index, :show | 
					
						
							|  |  |  |   accept_api_auth :index, :show, :create, :update, :destroy | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-28 10:29:48 +00:00
										 |  |  |   rescue_from Query::StatementInvalid, :with => :query_statement_invalid | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  |   helper :journals | 
					
						
							| 
									
										
										
										
											2007-06-12 23:07:00 +00:00
										 |  |  |   helper :projects | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  |   include ProjectsHelper | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   helper :custom_fields | 
					
						
							|  |  |  |   include CustomFieldsHelper | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |   helper :issue_relations | 
					
						
							|  |  |  |   include IssueRelationsHelper | 
					
						
							| 
									
										
										
										
											2007-05-13 19:43:35 +00:00
										 |  |  |   helper :watchers | 
					
						
							|  |  |  |   include WatchersHelper | 
					
						
							| 
									
										
										
										
											2007-05-26 15:42:37 +00:00
										 |  |  |   helper :attachments | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   include AttachmentsHelper | 
					
						
							|  |  |  |   helper :queries | 
					
						
							| 
									
										
										
										
											2010-01-18 18:00:27 +00:00
										 |  |  |   include QueriesHelper | 
					
						
							| 
									
										
										
										
											2011-01-08 00:19:51 +00:00
										 |  |  |   helper :repositories | 
					
						
							|  |  |  |   include RepositoriesHelper | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   helper :sort | 
					
						
							|  |  |  |   include SortHelper | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |   include IssuesHelper | 
					
						
							| 
									
										
										
										
											2008-06-29 12:01:20 +00:00
										 |  |  |   helper :timelog | 
					
						
							| 
									
										
										
										
											2009-01-04 12:03:39 +00:00
										 |  |  |   include Redmine::Export::PDF | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   def index | 
					
						
							|  |  |  |     retrieve_query | 
					
						
							| 
									
										
										
										
											2009-03-12 18:06:54 +00:00
										 |  |  |     sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | 
					
						
							| 
									
										
										
										
											2010-03-19 15:42:03 +00:00
										 |  |  |     sort_update(@query.sortable_columns) | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |     if @query.valid? | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |       case params[:format] | 
					
						
							| 
									
										
										
										
											2010-02-04 19:58:42 +00:00
										 |  |  |       when 'csv', 'pdf' | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |         @limit = Setting.issues_export_limit.to_i | 
					
						
							| 
									
										
										
										
											2010-02-04 19:58:42 +00:00
										 |  |  |       when 'atom' | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |         @limit = Setting.feeds_limit.to_i | 
					
						
							|  |  |  |       when 'xml', 'json' | 
					
						
							|  |  |  |         @offset, @limit = api_offset_and_limit | 
					
						
							| 
									
										
										
										
											2010-02-04 19:58:42 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |         @limit = per_page_option | 
					
						
							| 
									
										
										
										
											2008-03-05 08:25:22 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-28 10:08:29 +00:00
										 |  |  |       @issue_count = @query.issue_count | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |       @issue_pages = Paginator.new self, @issue_count, @limit, params['page'] | 
					
						
							|  |  |  |       @offset ||= @issue_pages.current.offset | 
					
						
							| 
									
										
										
										
											2009-11-28 10:08:29 +00:00
										 |  |  |       @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  |                               :order => sort_clause, | 
					
						
							|  |  |  |                               :offset => @offset, | 
					
						
							| 
									
										
										
										
											2010-12-11 13:13:49 +00:00
										 |  |  |                               :limit => @limit) | 
					
						
							| 
									
										
										
										
											2009-11-28 10:08:29 +00:00
										 |  |  |       @issue_count_by_group = @query.issue_count_by_group | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2011-09-01 16:30:27 +00:00
										 |  |  |         format.html { render :template => 'issues/index', :layout => !request.xhr? } | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:56 +00:00
										 |  |  |         format.api  { | 
					
						
							| 
									
										
										
										
											2011-07-24 15:34:41 +00:00
										 |  |  |           Issue.load_relations(@issues) if include_in_api_response?('relations') | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-07-06 13:47:59 +00:00
										 |  |  |         format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | 
					
						
							| 
									
										
										
										
											2011-11-20 13:23:20 +00:00
										 |  |  |         format.csv  { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } | 
					
						
							| 
									
										
										
										
											2009-04-26 13:09:14 +00:00
										 |  |  |         format.pdf  { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-07-23 19:45:23 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2011-09-01 23:40:59 +00:00
										 |  |  |         format.html { render(:template => 'issues/index', :layout => !request.xhr?) } | 
					
						
							|  |  |  |         format.any(:atom, :csv, :pdf) { render(:nothing => true) } | 
					
						
							| 
									
										
										
										
											2011-07-23 19:45:23 +00:00
										 |  |  |         format.api { render_validation_errors(@query) } | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2008-03-30 12:29:07 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  |   def show | 
					
						
							| 
									
										
										
										
											2007-08-14 09:02:40 +00:00
										 |  |  |     @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | 
					
						
							| 
									
										
										
										
											2008-03-05 15:41:54 +00:00
										 |  |  |     @journals.each_with_index {|j,i| j.indice = i+1} | 
					
						
							| 
									
										
										
										
											2011-04-12 19:50:48 +00:00
										 |  |  |     @journals.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 17:43:36 +00:00
										 |  |  |     @changesets = @issue.changesets.visible.all | 
					
						
							|  |  |  |     @changesets.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-22 13:28:20 +00:00
										 |  |  |     @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | 
					
						
							| 
									
										
										
										
											2008-02-09 16:11:18 +00:00
										 |  |  |     @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 
					
						
							|  |  |  |     @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | 
					
						
							| 
									
										
										
										
											2011-06-13 19:43:40 +00:00
										 |  |  |     @priorities = IssuePriority.active | 
					
						
							| 
									
										
										
										
											2011-04-01 14:00:31 +00:00
										 |  |  |     @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |       format.html { | 
					
						
							|  |  |  |         retrieve_previous_and_next_issue_ids | 
					
						
							|  |  |  |         render :template => 'issues/show' | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-12-04 17:43:39 +00:00
										 |  |  |       format.api | 
					
						
							| 
									
										
										
										
											2010-08-23 15:04:36 +00:00
										 |  |  |       format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } | 
					
						
							| 
									
										
										
										
											2009-01-04 12:03:39 +00:00
										 |  |  |       format.pdf  { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | 
					
						
							| 
									
										
										
										
											2007-10-05 23:17:49 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |   # Add a new issue | 
					
						
							|  |  |  |   # The new issue will be created from an existing one if copy_from parameter is given | 
					
						
							|  |  |  |   def new | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { render :action => 'new', :layout => !request.xhr? } | 
					
						
							| 
									
										
										
										
											2012-07-19 17:54:26 +00:00
										 |  |  |       format.js { render :partial => 'update_form' } | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | 
					
						
							| 
									
										
										
										
											2012-02-23 10:01:16 +00:00
										 |  |  |     @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |     if @issue.save | 
					
						
							|  |  |  |       call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | 
					
						
							|  |  |  |       respond_to do |format| | 
					
						
							|  |  |  |         format.html { | 
					
						
							| 
									
										
										
										
											2011-07-09 19:23:50 +00:00
										 |  |  |           render_attachment_warning_if_needed(@issue) | 
					
						
							| 
									
										
										
										
											2012-08-13 14:04:00 +00:00
										 |  |  |           flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) | 
					
						
							| 
									
										
										
										
											2012-01-08 11:16:54 +00:00
										 |  |  |           redirect_to(params[:continue] ?  { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |                       { :action => 'show', :id => @issue }) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-04 17:43:39 +00:00
										 |  |  |         format.api  { render :action => 'show', :status => :created, :location => issue_url(@issue) } | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       respond_to do |format| | 
					
						
							|  |  |  |         format.html { render :action => 'new' } | 
					
						
							| 
									
										
										
										
											2010-12-03 13:52:07 +00:00
										 |  |  |         format.api  { render_validation_errors(@issue) } | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     return unless update_issue_from_params | 
					
						
							| 
									
										
										
										
											2008-02-10 13:17:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:05 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { } | 
					
						
							|  |  |  |       format.xml  { } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     return unless update_issue_from_params | 
					
						
							| 
									
										
										
										
											2012-02-23 10:01:16 +00:00
										 |  |  |     @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     saved = false | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       saved = @issue.save_issue_with_child_records(params, @time_entry) | 
					
						
							|  |  |  |     rescue ActiveRecord::StaleObjectError | 
					
						
							|  |  |  |       @conflict = true | 
					
						
							|  |  |  |       if params[:last_journal_id] | 
					
						
							| 
									
										
										
										
											2012-08-08 21:28:07 +00:00
										 |  |  |         @conflict_journals = @issue.journals_after(params[:last_journal_id]).all | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     if saved | 
					
						
							| 
									
										
										
										
											2010-03-05 17:11:50 +00:00
										 |  |  |       render_attachment_warning_if_needed(@issue) | 
					
						
							| 
									
										
										
										
											2010-03-05 17:25:51 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | 
					
						
							| 
									
										
										
										
											2010-03-05 17:11:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 16:16:18 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							|  |  |  |         format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |         format.api  { render_api_ok } | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-02-26 16:16:18 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2010-01-13 19:29:19 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2010-02-24 17:21:41 +00:00
										 |  |  |         format.html { render :action => 'edit' } | 
					
						
							| 
									
										
										
										
											2010-12-03 13:52:07 +00:00
										 |  |  |         format.api  { render_validation_errors(@issue) } | 
					
						
							| 
									
										
										
										
											2010-01-13 19:29:19 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2008-01-06 17:06:14 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |   # Bulk edit/copy a set of issues | 
					
						
							| 
									
										
										
										
											2008-02-10 13:17:41 +00:00
										 |  |  |   def bulk_edit | 
					
						
							| 
									
										
										
										
											2010-03-13 14:56:49 +00:00
										 |  |  |     @issues.sort! | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |     @copy = params[:copy].present? | 
					
						
							|  |  |  |     @notes = params[:notes] | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if User.current.allowed_to?(:move_issues, @projects) | 
					
						
							|  |  |  |       @allowed_projects = Issue.allowed_target_projects_on_move | 
					
						
							|  |  |  |       if params[:issue] | 
					
						
							| 
									
										
										
										
											2012-03-01 20:22:08 +00:00
										 |  |  |         @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |         if @target_project | 
					
						
							|  |  |  |           target_projects = [@target_project] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     target_projects ||= @projects | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-14 05:45:16 +00:00
										 |  |  |     if @copy | 
					
						
							|  |  |  |       @available_statuses = [IssueStatus.default] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-02-09 20:06:36 +00:00
										 |  |  |     @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) | 
					
						
							|  |  |  |     @assignables = target_projects.map(&:assignable_users).reduce(:&) | 
					
						
							|  |  |  |     @trackers = target_projects.map(&:trackers).reduce(:&) | 
					
						
							| 
									
										
										
										
											2012-03-01 20:22:08 +00:00
										 |  |  |     @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) | 
					
						
							|  |  |  |     @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) | 
					
						
							| 
									
										
										
										
											2012-04-14 06:21:03 +00:00
										 |  |  |     if @copy | 
					
						
							|  |  |  |       @attachments_present = @issues.detect {|i| i.attachments.any?}.present? | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 20:06:36 +00:00
										 |  |  |     @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |     render :layout => false if request.xhr? | 
					
						
							| 
									
										
										
										
											2008-02-10 13:17:41 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def bulk_update | 
					
						
							|  |  |  |     @issues.sort! | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |     @copy = params[:copy].present? | 
					
						
							| 
									
										
										
										
											2010-08-25 14:59:16 +00:00
										 |  |  |     attributes = parse_params_for_bulk_issue_attributes(params) | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     unsaved_issue_ids = [] | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |     moved_issues = [] | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  |     @issues.each do |issue| | 
					
						
							|  |  |  |       issue.reload | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |       if @copy | 
					
						
							| 
									
										
										
										
											2012-04-14 06:21:03 +00:00
										 |  |  |         issue = issue.copy({}, :attachments => params[:copy_attachments].present?) | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  |       journal = issue.init_journal(User.current, params[:notes]) | 
					
						
							|  |  |  |       issue.safe_attributes = attributes | 
					
						
							|  |  |  |       call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |       if issue.save | 
					
						
							|  |  |  |         moved_issues << issue | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  |         # Keep unsaved issue ids to display them in flash error | 
					
						
							|  |  |  |         unsaved_issue_ids << issue.id | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if params[:follow] | 
					
						
							|  |  |  |       if @issues.size == 1 && moved_issues.size == 1
 | 
					
						
							|  |  |  |         redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first | 
					
						
							|  |  |  |       elsif moved_issues.map(&:project).uniq.size == 1
 | 
					
						
							|  |  |  |         redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |     @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | 
					
						
							|  |  |  |     if @hours > 0
 | 
					
						
							|  |  |  |       case params[:todo] | 
					
						
							|  |  |  |       when 'destroy' | 
					
						
							|  |  |  |         # nothing to do | 
					
						
							|  |  |  |       when 'nullify' | 
					
						
							|  |  |  |         TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | 
					
						
							|  |  |  |       when 'reassign' | 
					
						
							|  |  |  |         reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | 
					
						
							|  |  |  |         if reassign_to.nil? | 
					
						
							|  |  |  |           flash.now[:error] = l(:error_issue_not_found_in_project) | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2010-12-03 13:52:07 +00:00
										 |  |  |         # display the destroy form if it's a user request | 
					
						
							|  |  |  |         return unless api_request? | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-04-01 16:26:53 +00:00
										 |  |  |     @issues.each do |issue| | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         issue.reload.destroy | 
					
						
							|  |  |  |       rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists | 
					
						
							|  |  |  |         # nothing to do, issue was already deleted (eg. by a parent) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-01-13 19:29:19 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2010-10-07 05:11:28 +00:00
										 |  |  |       format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +00:00
										 |  |  |       format.api  { render_api_ok } | 
					
						
							| 
									
										
										
										
											2010-01-13 19:29:19 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |   def find_issue | 
					
						
							| 
									
										
										
										
											2011-04-11 17:53:15 +00:00
										 |  |  |     # Issue.visible.find(...) can not be used to redirect user to the login form | 
					
						
							|  |  |  |     # if the issue actually exists but requires authentication | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | 
					
						
							| 
									
										
										
										
											2011-04-11 17:53:15 +00:00
										 |  |  |     unless @issue.visible? | 
					
						
							|  |  |  |       deny_access | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     @project = @issue.project | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |   def find_project | 
					
						
							| 
									
										
										
										
											2012-01-07 12:34:52 +00:00
										 |  |  |     project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) | 
					
						
							| 
									
										
										
										
											2010-01-13 19:29:19 +00:00
										 |  |  |     @project = Project.find(project_id) | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |   def retrieve_previous_and_next_issue_ids | 
					
						
							|  |  |  |     retrieve_query_from_session | 
					
						
							|  |  |  |     if @query | 
					
						
							|  |  |  |       sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | 
					
						
							|  |  |  |       sort_update(@query.sortable_columns, 'issues_index_sort') | 
					
						
							|  |  |  |       limit = 500
 | 
					
						
							| 
									
										
										
										
											2012-01-08 18:21:00 +00:00
										 |  |  |       issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) | 
					
						
							| 
									
										
										
										
											2012-01-03 21:35:00 +00:00
										 |  |  |       if (idx = issue_ids.index(@issue.id)) && idx < limit | 
					
						
							| 
									
										
										
										
											2012-01-16 18:24:59 +00:00
										 |  |  |         if issue_ids.size < 500
 | 
					
						
							|  |  |  |           @issue_position = idx + 1
 | 
					
						
							|  |  |  |           @issue_count = issue_ids.size | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-01-03 21:35:00 +00:00
										 |  |  |         @prev_issue_id = issue_ids[idx - 1] if idx > 0
 | 
					
						
							|  |  |  |         @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:10 +00:00
										 |  |  |   # Used by #edit and #update to set some common instance variables | 
					
						
							|  |  |  |   # from the params | 
					
						
							|  |  |  |   # TODO: Refactor, not everything in here is needed by #edit | 
					
						
							|  |  |  |   def update_issue_from_params | 
					
						
							|  |  |  |     @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | 
					
						
							| 
									
										
										
										
											2011-04-01 14:00:31 +00:00
										 |  |  |     @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | 
					
						
							| 
									
										
										
										
											2010-11-17 18:27:38 +00:00
										 |  |  |     @time_entry.attributes = params[:time_entry] | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-27 20:08:59 +00:00
										 |  |  |     @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) | 
					
						
							| 
									
										
										
										
											2010-03-04 16:18:51 +00:00
										 |  |  |     @issue.init_journal(User.current, @notes) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     issue_attributes = params[:issue] | 
					
						
							|  |  |  |     if issue_attributes && params[:conflict_resolution] | 
					
						
							|  |  |  |       case params[:conflict_resolution] | 
					
						
							|  |  |  |       when 'overwrite' | 
					
						
							|  |  |  |         issue_attributes = issue_attributes.dup | 
					
						
							|  |  |  |         issue_attributes.delete(:lock_version) | 
					
						
							|  |  |  |       when 'add_notes' | 
					
						
							|  |  |  |         issue_attributes = {} | 
					
						
							|  |  |  |       when 'cancel' | 
					
						
							|  |  |  |         redirect_to issue_path(@issue) | 
					
						
							|  |  |  |         return false | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     @issue.safe_attributes = issue_attributes | 
					
						
							| 
									
										
										
										
											2012-04-09 09:39:27 +00:00
										 |  |  |     @priorities = IssuePriority.active | 
					
						
							|  |  |  |     @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     true | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:10 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-03-11 16:34:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   # TODO: Refactor, lots of extra code in here | 
					
						
							| 
									
										
										
										
											2010-09-26 13:52:25 +00:00
										 |  |  |   # TODO: Changing tracker on an existing issue should not trigger this | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   def build_new_issue_from_params | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     if params[:id].blank? | 
					
						
							|  |  |  |       @issue = Issue.new | 
					
						
							| 
									
										
										
										
											2012-01-20 18:22:43 +00:00
										 |  |  |       if params[:copy_from] | 
					
						
							|  |  |  |         begin | 
					
						
							|  |  |  |           @copy_from = Issue.visible.find(params[:copy_from]) | 
					
						
							|  |  |  |           @copy_attachments = params[:copy_attachments].present? || request.get? | 
					
						
							|  |  |  |           @issue.copy_from(@copy_from, :attachments => @copy_attachments) | 
					
						
							|  |  |  |         rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |           render_404 | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-01-17 20:20:59 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |       @issue.project = @project | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @issue = @project.issues.visible.find(params[:id]) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |     @issue.project = @project | 
					
						
							| 
									
										
										
										
											2011-06-01 17:16:38 +00:00
										 |  |  |     @issue.author = User.current | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |     # Tracker must be set before custom field values | 
					
						
							|  |  |  |     @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | 
					
						
							|  |  |  |     if @issue.tracker.nil? | 
					
						
							|  |  |  |       render_error l(:error_no_tracker_in_project) | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-11-05 18:40:33 +00:00
										 |  |  |     @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? | 
					
						
							| 
									
										
										
										
											2011-12-13 19:50:44 +00:00
										 |  |  |     @issue.safe_attributes = params[:issue] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 19:43:40 +00:00
										 |  |  |     @priorities = IssuePriority.active | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |     @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | 
					
						
							| 
									
										
										
										
											2012-03-24 12:57:28 +00:00
										 |  |  |     @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-26 15:08:06 +00:00
										 |  |  |   def check_for_default_issue_status | 
					
						
							|  |  |  |     if IssueStatus.default.nil? | 
					
						
							|  |  |  |       render_error l(:error_no_default_issue_status) | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-08-25 14:59:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def parse_params_for_bulk_issue_attributes(params) | 
					
						
							|  |  |  |     attributes = (params[:issue] || {}).reject {|k,v| v.blank?} | 
					
						
							|  |  |  |     attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | 
					
						
							| 
									
										
										
										
											2012-04-06 11:56:30 +00:00
										 |  |  |     if custom = attributes[:custom_field_values] | 
					
						
							|  |  |  |       custom.reject! {|k,v| v.blank?} | 
					
						
							|  |  |  |       custom.keys.each do |k| | 
					
						
							|  |  |  |         if custom[k].is_a?(Array) | 
					
						
							|  |  |  |           custom[k] << '' if custom[k].delete('__none__') | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           custom[k] = '' if custom[k] == '__none__' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-08-25 14:59:16 +00:00
										 |  |  |     attributes | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |