| 
									
										
										
										
											2019-03-16 09:37:35 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2019-03-15 01:32:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-11 17:03:26 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2022-01-02 05:29:10 +00:00
										 |  |  | # Copyright (C) 2006-2022  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 | 
					
						
							| 
									
										
										
										
											2009-10-21 17:07:18 +00:00
										 |  |  |   default_search_scope :issues | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |   before_action :find_issue, :only => [:show, :edit, :update, :issue_tab] | 
					
						
							| 
									
										
										
										
											2016-07-14 07:27:31 +00:00
										 |  |  |   before_action :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] | 
					
						
							|  |  |  |   before_action :authorize, :except => [:index, :new, :create] | 
					
						
							|  |  |  |   before_action :find_optional_project, :only => [:index, :new, :create] | 
					
						
							|  |  |  |   before_action :build_new_issue_from_params, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2022-03-19 09:56:46 +00:00
										 |  |  |   accept_atom_auth :index, :show | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2021-05-28 03:58:01 +00:00
										 |  |  |   rescue_from Query::QueryError, :with => :query_error | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   helper :custom_fields | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |   helper :issue_relations | 
					
						
							| 
									
										
										
										
											2007-05-13 19:43:35 +00:00
										 |  |  |   helper :watchers | 
					
						
							| 
									
										
										
										
											2007-05-26 15:42:37 +00:00
										 |  |  |   helper :attachments | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   helper :queries | 
					
						
							| 
									
										
										
										
											2010-01-18 18:00:27 +00:00
										 |  |  |   include QueriesHelper | 
					
						
							| 
									
										
										
										
											2011-01-08 00:19:51 +00:00
										 |  |  |   helper :repositories | 
					
						
							| 
									
										
										
										
											2008-06-29 12:01:20 +00:00
										 |  |  |   helper :timelog | 
					
						
							| 
									
										
										
										
											2006-09-09 16:07:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2018-12-04 09:23:18 +00:00
										 |  |  |     use_session = !request.format.csv? | 
					
						
							| 
									
										
										
										
											2021-07-06 06:01:50 +00:00
										 |  |  |     retrieve_default_query(use_session) | 
					
						
							| 
									
										
										
										
											2018-12-04 09:23:18 +00:00
										 |  |  |     retrieve_query(IssueQuery, use_session) | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-31 17:02:44 +00:00
										 |  |  |     if @query.valid? | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         format.html do | 
					
						
							| 
									
										
										
										
											2017-03-13 22:04:10 +00:00
										 |  |  |           @issue_count = @query.issue_count | 
					
						
							|  |  |  |           @issue_pages = Paginator.new @issue_count, per_page_option, params['page'] | 
					
						
							|  |  |  |           @issues = @query.issues(:offset => @issue_pages.offset, :limit => @issue_pages.per_page) | 
					
						
							|  |  |  |           render :layout => !request.xhr? | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |         format.api do | 
					
						
							| 
									
										
										
										
											2017-03-13 22:04:10 +00:00
										 |  |  |           @offset, @limit = api_offset_and_limit | 
					
						
							|  |  |  |           @query.column_names = %w(author) | 
					
						
							|  |  |  |           @issue_count = @query.issue_count | 
					
						
							|  |  |  |           @issues = @query.issues(:offset => @offset, :limit => @limit) | 
					
						
							| 
									
										
										
										
											2012-09-29 13:01:09 +00:00
										 |  |  |           Issue.load_visible_relations(@issues) if include_in_api_response?('relations') | 
					
						
							| 
									
										
										
										
											2021-06-27 07:18:58 +00:00
										 |  |  |           if User.current.allowed_to?(:view_time_entries, nil, :global => true) | 
					
						
							|  |  |  |             Issue.load_visible_spent_hours(@issues) | 
					
						
							|  |  |  |             Issue.load_visible_total_spent_hours(@issues) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |         format.atom do | 
					
						
							| 
									
										
										
										
											2017-03-13 22:04:10 +00:00
										 |  |  |           @issues = @query.issues(:limit => Setting.feeds_limit.to_i) | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:42 +00:00
										 |  |  |           render_feed(@issues, | 
					
						
							|  |  |  |                       :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |         format.csv do | 
					
						
							| 
									
										
										
										
											2017-03-13 22:04:10 +00:00
										 |  |  |           @issues = @query.issues(:limit => Setting.issues_export_limit.to_i) | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:42 +00:00
										 |  |  |           send_data(query_to_csv(@issues, @query, params[:csv]), | 
					
						
							|  |  |  |                     :type => 'text/csv; header=present', :filename => 'issues.csv') | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |         format.pdf do | 
					
						
							| 
									
										
										
										
											2017-03-13 22:04:10 +00:00
										 |  |  |           @issues = @query.issues(:limit => Setting.issues_export_limit.to_i) | 
					
						
							|  |  |  |           send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-07-23 19:45:23 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +00:00
										 |  |  |         format.html {render :layout => !request.xhr?} | 
					
						
							|  |  |  |         format.any(:atom, :csv, :pdf) {head 422} | 
					
						
							|  |  |  |         format.api {render_validation_errors(@query)} | 
					
						
							| 
									
										
										
										
											2011-07-23 19:45:23 +00:00
										 |  |  |       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 | 
					
						
							| 
									
										
										
										
											2017-01-14 09:34:24 +00:00
										 |  |  |     @journals = @issue.visible_journals_with_index | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |     @has_changesets = @issue.changesets.visible.preload(:repository, :user).exists? | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:53 +00:00
										 |  |  |     @relations = | 
					
						
							|  |  |  |       @issue.relations. | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         select do |r| | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:53 +00:00
										 |  |  |           r.other_issue(@issue) && r.other_issue(@issue).visible? | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |     @journals.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2017-01-14 09:34:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-29 10:28:48 +00:00
										 |  |  |     if User.current.allowed_to?(:view_time_entries, @project) | 
					
						
							|  |  |  |       Issue.load_visible_spent_hours([@issue]) | 
					
						
							|  |  |  |       Issue.load_visible_total_spent_hours([@issue]) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-05 18:38:42 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |       format.html do | 
					
						
							| 
									
										
										
										
											2017-01-14 09:56:04 +00:00
										 |  |  |         @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 
					
						
							|  |  |  |         @priorities = IssuePriority.active | 
					
						
							|  |  |  |         @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | 
					
						
							| 
									
										
										
										
											2019-06-20 07:11:26 +00:00
										 |  |  |         @time_entries = @issue.time_entries.visible.preload(:activity, :user) | 
					
						
							| 
									
										
										
										
											2017-01-14 09:56:04 +00:00
										 |  |  |         @relation = IssueRelation.new | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |         retrieve_previous_and_next_issue_ids | 
					
						
							|  |  |  |         render :template => 'issues/show' | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       format.api do | 
					
						
							| 
									
										
										
										
											2021-04-19 09:04:24 +00:00
										 |  |  |         @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |         @changesets = @issue.changesets.visible.preload(:repository, :user).to_a | 
					
						
							|  |  |  |         @changesets.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       format.atom do | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:53 +00:00
										 |  |  |         render :template => 'journals/index', :layout => false, | 
					
						
							|  |  |  |         :content_type => 'application/atom+xml' | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       format.pdf do | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:53 +00:00
										 |  |  |         send_file_headers!(:type => 'application/pdf', | 
					
						
							|  |  |  |                            :filename => "#{@project.identifier}-#{@issue.id}.pdf") | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   def new | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +00:00
										 |  |  |       format.html {render :action => 'new', :layout => !request.xhr?} | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							| 
									
										
										
										
											2015-03-20 10:02:45 +00:00
										 |  |  |     unless User.current.allowed_to?(:add_issues, @issue.project, :global => true) | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |       raise ::Unauthorized | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:42 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:42 +00:00
										 |  |  |       call_hook(:controller_issues_new_after_save, {:params => params, :issue => @issue}) | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         format.html do | 
					
						
							| 
									
										
										
										
											2011-07-09 19:23:50 +00:00
										 |  |  |           render_attachment_warning_if_needed(@issue) | 
					
						
							| 
									
										
										
										
											2019-11-22 04:25:03 +00:00
										 |  |  |           flash[:notice] = | 
					
						
							|  |  |  |             l(:notice_issue_successful_create, | 
					
						
							|  |  |  |               :id => view_context.link_to("##{@issue.id}", issue_path(@issue), | 
					
						
							|  |  |  |                                           :title => @issue.subject)) | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |           redirect_after_create | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |         format.api do | 
					
						
							| 
									
										
										
										
											2019-11-22 04:25:03 +00:00
										 |  |  |           render :action => 'show', :status => :created, | 
					
						
							|  |  |  |           :location => issue_url(@issue) | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-04-22 15:43:57 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         format.html do | 
					
						
							| 
									
										
										
										
											2016-08-20 12:41:24 +00:00
										 |  |  |           if @issue.project.nil? | 
					
						
							|  |  |  |             render_error :status => 422
 | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             render :action => 'new' | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +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| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +00:00
										 |  |  |       format.html {} | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:05 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     return unless update_issue_from_params | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:21 +00:00
										 |  |  |     @issue.save_attachments(params[:attachments] || | 
					
						
							|  |  |  |                              (params[:issue] && params[:issue][:uploads])) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     saved = false | 
					
						
							|  |  |  |     begin | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |       saved = save_issue_with_child_records | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     rescue ActiveRecord::StaleObjectError | 
					
						
							| 
									
										
										
										
											2021-04-01 15:25:40 +00:00
										 |  |  |       @issue.detach_saved_attachments | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |       @conflict = true | 
					
						
							|  |  |  |       if params[:last_journal_id] | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |         @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:21 +00:00
										 |  |  |         unless User.current.allowed_to?(:view_private_notes, @issue.project) | 
					
						
							|  |  |  |           @conflict_journals.reject!(&:private_notes?) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:21 +00:00
										 |  |  |       unless @issue.current_journal.new_record? || params[:no_flash] | 
					
						
							|  |  |  |         flash[:notice] = l(:notice_successful_update) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-02-26 16:16:18 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         format.html do | 
					
						
							| 
									
										
										
										
											2019-11-22 04:24:21 +00:00
										 |  |  |           redirect_back_or_default( | 
					
						
							|  |  |  |             issue_path(@issue, previous_and_next_issue_ids_params) | 
					
						
							|  |  |  |           ) | 
					
						
							| 
									
										
										
										
											2019-11-26 06:31:04 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +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| | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +00:00
										 |  |  |         format.html {render :action => 'edit'} | 
					
						
							|  |  |  |         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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |   def issue_tab | 
					
						
							|  |  |  |     return render_error :status => 422 unless request.xhr? | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |     tab = params[:name] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case tab | 
					
						
							|  |  |  |     when 'time_entries' | 
					
						
							|  |  |  |       @time_entries = @issue.time_entries.visible.preload(:activity, :user).to_a | 
					
						
							|  |  |  |       render :partial => 'issues/tabs/time_entries', :locals => {:time_entries => @time_entries} | 
					
						
							|  |  |  |     when 'changesets' | 
					
						
							|  |  |  |       @changesets = @issue.changesets.visible.preload(:repository, :user).to_a | 
					
						
							| 
									
										
										
										
											2019-10-05 23:57:33 +00:00
										 |  |  |       @changesets.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2022-01-18 15:03:29 +00:00
										 |  |  |       render :partial => 'issues/tabs/changesets', :locals => {:changesets => @changesets, :project => @project} | 
					
						
							| 
									
										
										
										
											2019-06-20 07:12:30 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |     if @copy | 
					
						
							|  |  |  |       unless User.current.allowed_to?(:copy_issues, @projects) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-06-05 13:45:10 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       unless @issues.all?(&:attributes_editable?) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |     edited_issues = Issue.where(:id => @issues.map(&:id)).to_a | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 14:49:57 +00:00
										 |  |  |     @values_by_custom_field = {} | 
					
						
							|  |  |  |     edited_issues.each do |issue| | 
					
						
							|  |  |  |       issue.custom_field_values.each do |c| | 
					
						
							|  |  |  |         if c.value_present? | 
					
						
							|  |  |  |           @values_by_custom_field[c.custom_field] ||= [] | 
					
						
							|  |  |  |           @values_by_custom_field[c.custom_field] << issue.id | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 10:20:53 +00:00
										 |  |  |     @allowed_projects = Issue.allowed_target_projects | 
					
						
							|  |  |  |     if params[:issue] | 
					
						
							|  |  |  |       @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} | 
					
						
							|  |  |  |       if @target_project | 
					
						
							|  |  |  |         target_projects = [@target_project] | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |         edited_issues.each {|issue| issue.project = @target_project} | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     target_projects ||= @projects | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +00:00
										 |  |  |     @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p)}.reduce(:&) | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |     if params[:issue] | 
					
						
							|  |  |  |       @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s} | 
					
						
							|  |  |  |       if @target_tracker | 
					
						
							|  |  |  |         edited_issues.each {|issue| issue.tracker = @target_tracker} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-14 05:45:16 +00:00
										 |  |  |     if @copy | 
					
						
							| 
									
										
										
										
											2014-11-02 19:45:14 +00:00
										 |  |  |       # Copied issues will get their default statuses | 
					
						
							|  |  |  |       @available_statuses = [] | 
					
						
							| 
									
										
										
										
											2012-04-14 05:45:16 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |       @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&) | 
					
						
							| 
									
										
										
										
											2012-04-14 05:45:16 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |     if params[:issue] | 
					
						
							|  |  |  |       @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s} | 
					
						
							|  |  |  |       if @target_status | 
					
						
							|  |  |  |         edited_issues.each {|issue| issue.status = @target_status} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 14:49:57 +00:00
										 |  |  |     edited_issues.each do |issue| | 
					
						
							|  |  |  |       issue.custom_field_values.each do |c| | 
					
						
							|  |  |  |         if c.value_present? && @values_by_custom_field[c.custom_field] | 
					
						
							|  |  |  |           @values_by_custom_field[c.custom_field].delete(issue.id) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:53 +00:00
										 |  |  |     @values_by_custom_field.delete_if {|k, v| v.blank?} | 
					
						
							| 
									
										
										
										
											2019-11-22 04:25:14 +00:00
										 |  |  |     @custom_fields = | 
					
						
							|  |  |  |       edited_issues.map{|i| i.editable_custom_fields}. | 
					
						
							|  |  |  |         reduce(:&).select {|field| field.format.bulk_edit_supported} | 
					
						
							| 
									
										
										
										
											2012-02-09 20:06:36 +00:00
										 |  |  |     @assignables = target_projects.map(&:assignable_users).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? | 
					
						
							| 
									
										
										
										
											2012-09-08 05:34:07 +00:00
										 |  |  |       @subtasks_present = @issues.detect {|i| !i.leaf?}.present? | 
					
						
							| 
									
										
										
										
											2019-10-17 16:39:31 +00:00
										 |  |  |       @watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) && | 
					
						
							|  |  |  |                             Watcher.where(:watchable_type => 'Issue', | 
					
						
							|  |  |  |                                           :watchable_id => @issues.map(&:id)).exists? | 
					
						
							| 
									
										
										
										
											2012-04-14 06:21:03 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-03 07:55:57 +00:00
										 |  |  |     @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&) | 
					
						
							| 
									
										
										
										
											2013-05-04 15:03:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @issue_params = params[:issue] || {} | 
					
						
							|  |  |  |     @issue_params[:custom_field_values] ||= {} | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2015-05-23 07:08:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-15 18:24:02 +00:00
										 |  |  |     attributes = parse_params_for_bulk_update(params[:issue]) | 
					
						
							| 
									
										
										
										
											2015-05-23 07:08:53 +00:00
										 |  |  |     copy_subtasks = (params[:copy_subtasks] == '1') | 
					
						
							|  |  |  |     copy_attachments = (params[:copy_attachments] == '1') | 
					
						
							| 
									
										
										
										
											2017-04-06 17:34:45 +00:00
										 |  |  |     copy_watchers = (params[:copy_watchers] == '1') | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |     if @copy | 
					
						
							|  |  |  |       unless User.current.allowed_to?(:copy_issues, @projects) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |       target_projects = @projects | 
					
						
							|  |  |  |       if attributes['project_id'].present? | 
					
						
							|  |  |  |         target_projects = Project.where(:id => attributes['project_id']).to_a | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       unless User.current.allowed_to?(:add_issues, target_projects) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 17:34:45 +00:00
										 |  |  |       unless User.current.allowed_to?(:add_issue_watchers, @projects) | 
					
						
							|  |  |  |         copy_watchers = false | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-06-05 13:45:10 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       unless @issues.all?(&:attributes_editable?) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-02-08 12:07:00 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 08:52:51 +00:00
										 |  |  |     unsaved_issues = [] | 
					
						
							|  |  |  |     saved_issues = [] | 
					
						
							| 
									
										
										
										
											2012-09-08 06:14:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-23 07:08:53 +00:00
										 |  |  |     if @copy && copy_subtasks | 
					
						
							| 
									
										
										
										
											2012-09-08 06:14:35 +00:00
										 |  |  |       # Descendant issues will be copied with the parent task | 
					
						
							|  |  |  |       # Don't copy them twice | 
					
						
							|  |  |  |       @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 15:18:16 +00:00
										 |  |  |     @issues.each do |orig_issue| | 
					
						
							|  |  |  |       orig_issue.reload | 
					
						
							| 
									
										
										
										
											2012-01-07 17:27:47 +00:00
										 |  |  |       if @copy | 
					
						
							| 
									
										
										
										
											2019-11-08 01:37:14 +00:00
										 |  |  |         issue = orig_issue.copy( | 
					
						
							|  |  |  |           {}, | 
					
						
							| 
									
										
										
										
											2015-05-23 07:08:53 +00:00
										 |  |  |           :attachments => copy_attachments, | 
					
						
							|  |  |  |           :subtasks => copy_subtasks, | 
					
						
							| 
									
										
										
										
											2017-04-06 17:34:45 +00:00
										 |  |  |           :watchers => copy_watchers, | 
					
						
							| 
									
										
										
										
											2014-11-29 15:10:59 +00:00
										 |  |  |           :link => link_copy?(params[:link_copy]) | 
					
						
							| 
									
										
										
										
											2012-09-08 05:34:07 +00:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2013-05-04 15:18:16 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         issue = orig_issue | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:42 +00:00
										 |  |  |       call_hook(:controller_issues_bulk_edit_before_save, {:params => params, :issue => issue}) | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |       if issue.save | 
					
						
							| 
									
										
										
										
											2013-05-04 08:52:51 +00:00
										 |  |  |         saved_issues << issue | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2013-05-04 15:18:16 +00:00
										 |  |  |         unsaved_issues << orig_issue | 
					
						
							| 
									
										
										
										
											2010-08-24 15:27:12 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 08:52:51 +00:00
										 |  |  |     if unsaved_issues.empty? | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_successful_update) unless saved_issues.empty? | 
					
						
							|  |  |  |       if params[:follow] | 
					
						
							|  |  |  |         if @issues.size == 1 && saved_issues.size == 1
 | 
					
						
							|  |  |  |           redirect_to issue_path(saved_issues.first) | 
					
						
							|  |  |  |         elsif saved_issues.map(&:project).uniq.size == 1
 | 
					
						
							|  |  |  |           redirect_to project_issues_path(saved_issues.map(&:project).first) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         redirect_back_or_default _project_issues_path(@project) | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2013-05-04 08:52:51 +00:00
										 |  |  |       @saved_issues = @issues | 
					
						
							|  |  |  |       @unsaved_issues = unsaved_issues | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |       @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a | 
					
						
							| 
									
										
										
										
											2013-05-04 08:52:51 +00:00
										 |  |  |       bulk_edit | 
					
						
							|  |  |  |       render :action => 'bulk_edit' | 
					
						
							| 
									
										
										
										
											2012-01-07 16:18:53 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2016-06-05 13:45:10 +00:00
										 |  |  |     raise Unauthorized unless @issues.all?(&:deletable?) | 
					
						
							| 
									
										
										
										
											2016-12-31 15:04:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # all issues and their descendants are about to be deleted | 
					
						
							|  |  |  |     issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id) | 
					
						
							|  |  |  |     time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids) | 
					
						
							|  |  |  |     @hours = time_entries.sum(:hours).to_f | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |     if @hours > 0
 | 
					
						
							|  |  |  |       case params[:todo] | 
					
						
							|  |  |  |       when 'destroy' | 
					
						
							|  |  |  |         # nothing to do | 
					
						
							|  |  |  |       when 'nullify' | 
					
						
							| 
									
										
										
										
											2018-02-18 04:24:05 +00:00
										 |  |  |         if Setting.timelog_required_fields.include?('issue_id') | 
					
						
							|  |  |  |           flash.now[:error] = l(:field_issue) + " " + ::I18n.t('activerecord.errors.messages.blank') | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2020-07-19 14:05:53 +00:00
										 |  |  |           time_entries.update_all(:issue_id => nil) | 
					
						
							| 
									
										
										
										
											2018-02-18 04:24:05 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |       when 'reassign' | 
					
						
							| 
									
										
										
										
											2016-12-31 15:26:00 +00:00
										 |  |  |         reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id]) | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |         if reassign_to.nil? | 
					
						
							|  |  |  |           flash.now[:error] = l(:error_issue_not_found_in_project) | 
					
						
							|  |  |  |           return | 
					
						
							| 
									
										
										
										
											2016-12-31 15:04:05 +00:00
										 |  |  |         elsif issues_and_descendants_ids.include?(reassign_to.id) | 
					
						
							|  |  |  |           flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted) | 
					
						
							|  |  |  |           return | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2016-12-31 15:16:23 +00:00
										 |  |  |           time_entries.update_all(:issue_id => reassign_to.id, :project_id => reassign_to.project_id) | 
					
						
							| 
									
										
										
										
											2008-02-29 22:54:07 +00:00
										 |  |  |         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| | 
					
						
							| 
									
										
										
										
											2020-11-09 13:24:14 +00:00
										 |  |  |       format.html do | 
					
						
							| 
									
										
										
										
											2020-04-04 00:43:28 +00:00
										 |  |  |         flash[:notice] = l(:notice_successful_delete) | 
					
						
							|  |  |  |         redirect_back_or_default _project_issues_path(@project) | 
					
						
							| 
									
										
										
										
											2020-11-09 13:24:14 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-11-26 06:30:53 +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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 17:16:55 +00:00
										 |  |  |   # Overrides Redmine::MenuManager::MenuController::ClassMethods for | 
					
						
							|  |  |  |   # when the "New issue" tab is enabled | 
					
						
							|  |  |  |   def current_menu_item | 
					
						
							| 
									
										
										
										
											2017-02-09 04:08:36 +00:00
										 |  |  |     if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym) | 
					
						
							| 
									
										
										
										
											2016-05-09 17:16:55 +00:00
										 |  |  |       :new_issue | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-02 09:59:22 +00:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 03:58:01 +00:00
										 |  |  |   def query_error(exception) | 
					
						
							|  |  |  |     session.delete(:issue_query) | 
					
						
							|  |  |  |     super | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-06 06:01:50 +00:00
										 |  |  |   def retrieve_default_query(use_session) | 
					
						
							|  |  |  |     return if params[:query_id].present? | 
					
						
							|  |  |  |     return if api_request? | 
					
						
							|  |  |  |     return if params[:set_filter] && (params.key?(:op) || params.key?(:f)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if params[:without_default].present? | 
					
						
							|  |  |  |       params[:set_filter] = 1
 | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     if !params[:set_filter] && use_session && session[:issue_query] | 
					
						
							|  |  |  |       query_id, project_id = session[:issue_query].values_at(:id, :project_id) | 
					
						
							|  |  |  |       return if IssueQuery.where(id: query_id).exists? && project_id == @project&.id | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     if default_query = IssueQuery.default(project: @project) | 
					
						
							|  |  |  |       params[:query_id] = default_query.id | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |   def retrieve_previous_and_next_issue_ids | 
					
						
							| 
									
										
										
										
											2016-03-19 09:00:36 +00:00
										 |  |  |     if params[:prev_issue_id].present? || params[:next_issue_id].present? | 
					
						
							|  |  |  |       @prev_issue_id = params[:prev_issue_id].presence.try(:to_i) | 
					
						
							|  |  |  |       @next_issue_id = params[:next_issue_id].presence.try(:to_i) | 
					
						
							|  |  |  |       @issue_position = params[:issue_position].presence.try(:to_i) | 
					
						
							|  |  |  |       @issue_count = params[:issue_count].presence.try(:to_i) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       retrieve_query_from_session | 
					
						
							|  |  |  |       if @query | 
					
						
							| 
									
										
										
										
											2017-04-04 17:49:40 +00:00
										 |  |  |         @per_page = per_page_option | 
					
						
							| 
									
										
										
										
											2016-03-19 09:00:36 +00:00
										 |  |  |         limit = 500
 | 
					
						
							| 
									
										
										
										
											2017-03-13 19:17:59 +00:00
										 |  |  |         issue_ids = @query.issue_ids(:limit => (limit + 1)) | 
					
						
							| 
									
										
										
										
											2016-03-19 09:00:36 +00:00
										 |  |  |         if (idx = issue_ids.index(@issue.id)) && idx < limit | 
					
						
							|  |  |  |           if issue_ids.size < 500
 | 
					
						
							|  |  |  |             @issue_position = idx + 1
 | 
					
						
							|  |  |  |             @issue_count = issue_ids.size | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           @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-16 18:24:59 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-04-04 17:49:40 +00:00
										 |  |  |         query_params = @query.as_params | 
					
						
							|  |  |  |         if @issue_position | 
					
						
							|  |  |  |           query_params = query_params.merge(:page => (@issue_position / per_page_option) + 1, :per_page => per_page_option) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         @query_path = _project_issues_path(@query.project, query_params) | 
					
						
							| 
									
										
										
										
											2012-01-03 20:09:44 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 09:00:36 +00:00
										 |  |  |   def previous_and_next_issue_ids_params | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       :prev_issue_id => params[:prev_issue_id], | 
					
						
							|  |  |  |       :next_issue_id => params[:next_issue_id], | 
					
						
							|  |  |  |       :issue_position => params[:issue_position], | 
					
						
							|  |  |  |       :issue_count => params[:issue_count] | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:53 +00:00
										 |  |  |     }.reject {|k, v| k.blank?} | 
					
						
							| 
									
										
										
										
											2016-03-19 09:00:36 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 17:01:10 +00:00
										 |  |  |   # Used by #edit and #update to set some common instance variables | 
					
						
							|  |  |  |   # from the params | 
					
						
							|  |  |  |   def update_issue_from_params | 
					
						
							| 
									
										
										
										
											2011-04-01 14:00:31 +00:00
										 |  |  |     @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |     if params[:time_entry] | 
					
						
							| 
									
										
										
										
											2015-11-01 08:16:10 +00:00
										 |  |  |       @time_entry.safe_attributes = params[:time_entry] | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-10-03 21:36:19 +00:00
										 |  |  |     @issue.init_journal(User.current) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     issue_attributes = params[:issue] | 
					
						
							| 
									
										
										
										
											2019-11-22 04:25:25 +00:00
										 |  |  |     if issue_attributes && issue_attributes[:assigned_to_id] == 'me' | 
					
						
							|  |  |  |       issue_attributes[:assigned_to_id] = User.current.id | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     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' | 
					
						
							| 
									
										
										
										
											2015-12-20 10:11:07 +00:00
										 |  |  |         issue_attributes = issue_attributes.slice(:notes, :private_notes) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |       when 'cancel' | 
					
						
							|  |  |  |         redirect_to issue_path(@issue) | 
					
						
							|  |  |  |         return false | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-08-05 23:41:01 +00:00
										 |  |  |     issue_attributes = replace_none_values_with_blank(issue_attributes) | 
					
						
							| 
									
										
										
										
											2012-02-04 17:36:15 +00:00
										 |  |  |     @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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-14 08:09:06 +00:00
										 |  |  |   # Used by #new and #create to build a new issue from the params | 
					
						
							|  |  |  |   # The new issue will be copied from an existing one if copy_from parameter is given | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   def build_new_issue_from_params | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |     @issue = Issue.new | 
					
						
							|  |  |  |     if params[:copy_from] | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         @issue.init_journal(User.current) | 
					
						
							|  |  |  |         @copy_from = Issue.visible.find(params[:copy_from]) | 
					
						
							|  |  |  |         unless User.current.allowed_to?(:copy_issues, @copy_from.project) | 
					
						
							|  |  |  |           raise ::Unauthorized | 
					
						
							| 
									
										
										
										
											2012-01-20 18:22:43 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:50:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |         @link_copy = link_copy?(params[:link_copy]) || request.get? | 
					
						
							|  |  |  |         @copy_attachments = params[:copy_attachments].present? || request.get? | 
					
						
							|  |  |  |         @copy_subtasks = params[:copy_subtasks].present? || request.get? | 
					
						
							| 
									
										
										
										
											2017-04-06 17:34:45 +00:00
										 |  |  |         @copy_watchers = User.current.allowed_to?(:add_issue_watchers, @project) | 
					
						
							| 
									
										
										
										
											2019-11-22 04:25:36 +00:00
										 |  |  |         @issue.copy_from(@copy_from, :attachments => @copy_attachments, | 
					
						
							|  |  |  |                          :subtasks => @copy_subtasks, :watchers => @copy_watchers, | 
					
						
							|  |  |  |                          :link => @link_copy) | 
					
						
							| 
									
										
										
										
											2016-01-10 15:47:52 +00:00
										 |  |  |         @issue.parent_issue_id = @copy_from.parent_id | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |       rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |         render_404 | 
					
						
							|  |  |  |         return | 
					
						
							| 
									
										
										
										
											2012-01-17 20:20:59 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-08-20 15:22:19 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |     @issue.project = @project | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |     if request.get? | 
					
						
							|  |  |  |       @issue.project ||= @issue.allowed_target_projects.first | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-02-13 20:00:22 +00:00
										 |  |  |     @issue.author ||= User.current | 
					
						
							| 
									
										
										
										
											2016-05-07 10:42:22 +00:00
										 |  |  |     @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date? | 
					
						
							| 
									
										
										
										
											2011-05-17 04:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 08:30:19 +00:00
										 |  |  |     attrs = (params[:issue] || {}).deep_dup | 
					
						
							|  |  |  |     if action_name == 'new' && params[:was_default_status] == attrs[:status_id] | 
					
						
							|  |  |  |       attrs.delete(:status_id) | 
					
						
							| 
									
										
										
										
											2014-11-02 19:45:14 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-11-01 08:38:21 +00:00
										 |  |  |     if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id' | 
					
						
							|  |  |  |       # Discard submitted version when changing the project on the issue form | 
					
						
							|  |  |  |       # so we can use the default version for the new project | 
					
						
							|  |  |  |       attrs.delete(:fixed_version_id) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-03-15 09:37:04 +00:00
										 |  |  |     attrs[:assigned_to_id] = User.current.id if attrs[:assigned_to_id] == 'me' | 
					
						
							| 
									
										
										
										
											2015-07-26 08:30:19 +00:00
										 |  |  |     @issue.safe_attributes = attrs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |     if @issue.project | 
					
						
							| 
									
										
										
										
											2016-05-30 18:20:13 +00:00
										 |  |  |       @issue.tracker ||= @issue.allowed_target_trackers.first | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |       if @issue.tracker.nil? | 
					
						
							| 
									
										
										
										
											2016-06-05 10:06:17 +00:00
										 |  |  |         if @issue.project.trackers.any? | 
					
						
							|  |  |  |           # None of the project trackers is allowed to the user | 
					
						
							|  |  |  |           render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403
 | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           # Project has no trackers | 
					
						
							|  |  |  |           render_error l(:error_no_tracker_in_project) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |         return false | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       if @issue.status.nil? | 
					
						
							|  |  |  |         render_error l(:error_no_default_issue_status) | 
					
						
							|  |  |  |         return false | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-20 12:41:24 +00:00
										 |  |  |     elsif request.get? | 
					
						
							| 
									
										
										
										
											2016-08-20 11:26:43 +00:00
										 |  |  |       render_error :message => l(:error_no_projects_with_tracker_allowed_for_new_issue), :status => 403
 | 
					
						
							|  |  |  |       return false | 
					
						
							| 
									
										
										
										
											2014-11-02 19:45:14 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-12-13 19:50:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 19:43:40 +00:00
										 |  |  |     @priorities = IssuePriority.active | 
					
						
							| 
									
										
										
										
											2015-07-26 08:30:19 +00:00
										 |  |  |     @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | 
					
						
							| 
									
										
										
										
											2010-04-23 15:05:13 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |   # Saves @issue and a time_entry from the parameters | 
					
						
							|  |  |  |   def save_issue_with_child_records | 
					
						
							|  |  |  |     Issue.transaction do | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:43 +00:00
										 |  |  |       if params[:time_entry] && | 
					
						
							|  |  |  |            (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && | 
					
						
							|  |  |  |            User.current.allowed_to?(:log_time, @issue.project) | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |         time_entry = @time_entry || TimeEntry.new | 
					
						
							|  |  |  |         time_entry.project = @issue.project | 
					
						
							|  |  |  |         time_entry.issue = @issue | 
					
						
							| 
									
										
										
										
											2020-04-05 19:24:32 +00:00
										 |  |  |         time_entry.author = User.current | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |         time_entry.user = User.current | 
					
						
							|  |  |  |         time_entry.spent_on = User.current.today | 
					
						
							| 
									
										
										
										
											2017-06-01 19:56:13 +00:00
										 |  |  |         time_entry.safe_attributes = params[:time_entry] | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |         @issue.time_entries << time_entry | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:43 +00:00
										 |  |  |       call_hook( | 
					
						
							|  |  |  |         :controller_issues_edit_before_save, | 
					
						
							|  |  |  |         {:params => params, :issue => @issue, | 
					
						
							|  |  |  |          :time_entry => time_entry, | 
					
						
							|  |  |  |          :journal => @issue.current_journal} | 
					
						
							|  |  |  |       ) | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |       if @issue.save | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:43 +00:00
										 |  |  |         call_hook( | 
					
						
							|  |  |  |           :controller_issues_edit_after_save, | 
					
						
							|  |  |  |           {:params => params, :issue => @issue, | 
					
						
							|  |  |  |            :time_entry => time_entry, | 
					
						
							|  |  |  |            :journal => @issue.current_journal} | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2013-10-13 10:31:04 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         raise ActiveRecord::Rollback | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-11-29 15:10:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-14 08:09:06 +00:00
										 |  |  |   # Returns true if the issue copy should be linked | 
					
						
							|  |  |  |   # to the original issue | 
					
						
							| 
									
										
										
										
											2014-11-29 15:10:59 +00:00
										 |  |  |   def link_copy?(param) | 
					
						
							|  |  |  |     case Setting.link_copied_issue | 
					
						
							|  |  |  |     when 'yes' | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     when 'no' | 
					
						
							|  |  |  |       false | 
					
						
							|  |  |  |     when 'ask' | 
					
						
							|  |  |  |       param == '1' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Redirects user after a successful issue creation | 
					
						
							|  |  |  |   def redirect_after_create | 
					
						
							|  |  |  |     if params[:continue] | 
					
						
							| 
									
										
										
										
											2017-01-30 21:24:18 +00:00
										 |  |  |       url_params = {} | 
					
						
							| 
									
										
										
										
											2019-11-22 16:49:53 +00:00
										 |  |  |       url_params[:issue] = | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           :tracker_id => @issue.tracker, | 
					
						
							|  |  |  |           :parent_issue_id => @issue.parent_issue_id | 
					
						
							|  |  |  |         }.reject {|k, v| v.nil?} | 
					
						
							| 
									
										
										
										
											2017-01-30 21:24:18 +00:00
										 |  |  |       url_params[:back_url] = params[:back_url].presence | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |       if params[:project_id] | 
					
						
							| 
									
										
										
										
											2017-01-30 21:24:18 +00:00
										 |  |  |         redirect_to new_project_issue_path(@issue.project, url_params) | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-10-24 05:33:23 +00:00
										 |  |  |         url_params[:issue][:project_id] = @issue.project_id | 
					
						
							| 
									
										
										
										
											2017-01-30 21:24:18 +00:00
										 |  |  |         redirect_to new_issue_path(url_params) | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-11-06 09:11:58 +00:00
										 |  |  |     elsif params[:follow] | 
					
						
							|  |  |  |       redirect_to issue_path(@issue) | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-01-30 21:24:18 +00:00
										 |  |  |       redirect_back_or_default issue_path(@issue) | 
					
						
							| 
									
										
										
										
											2015-02-14 08:03:51 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |