| 
									
										
										
										
											2019-03-16 09:37:35 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2019-03-15 01:32:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2021-03-25 06:58:56 +00:00
										 |  |  | # Copyright (C) 2006-2021  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +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-08-31 11:14:13 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +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-08-31 11:14:13 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +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 IssueRelationsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2016-11-19 10:03:27 +00:00
										 |  |  |   helper :issues | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 07:27:31 +00:00
										 |  |  |   before_action :find_issue, :authorize, :only => [:index, :create] | 
					
						
							|  |  |  |   before_action :find_relation, :only => [:show, :destroy] | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   accept_api_auth :index, :show, :create, :destroy | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:44:41 +00:00
										 |  |  |   def index | 
					
						
							|  |  |  |     @relations = @issue.relations | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:44:41 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |       format.html {head 200} | 
					
						
							| 
									
										
										
										
											2011-07-04 17:44:41 +00:00
										 |  |  |       format.api | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def show | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |     raise Unauthorized unless @relation.visible? | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |       format.html {head 200} | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |       format.api | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def create | 
					
						
							| 
									
										
										
										
											2020-12-25 02:25:41 +00:00
										 |  |  |     saved = false | 
					
						
							|  |  |  |     params_relation = params[:relation] | 
					
						
							|  |  |  |     unsaved_relations = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     relation_issues_to_id.each do |issue_to_id| | 
					
						
							|  |  |  |       params_relation[:issue_to_id] = issue_to_id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @relation = IssueRelation.new | 
					
						
							|  |  |  |       @relation.issue_from = @issue | 
					
						
							|  |  |  |       @relation.safe_attributes = params_relation | 
					
						
							|  |  |  |       @relation.init_journals(User.current) | 
					
						
							| 
									
										
										
										
											2018-01-07 00:37:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-25 02:25:41 +00:00
										 |  |  |       unless saved = @relation.save | 
					
						
							|  |  |  |         saved = false | 
					
						
							|  |  |  |         unsaved_relations << @relation | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-01-07 00:37:16 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |       format.html {redirect_to issue_path(@issue)} | 
					
						
							| 
									
										
										
										
											2020-11-09 13:24:44 +00:00
										 |  |  |       format.js do | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |         @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible?} | 
					
						
							| 
									
										
										
										
											2020-12-25 02:25:41 +00:00
										 |  |  |         @unsaved_relations = unsaved_relations | 
					
						
							| 
									
										
										
										
											2020-11-09 13:24:44 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       format.api do | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |         if saved | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |           render :action => 'show', :status => :created, :location => relation_url(@relation) | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |         else | 
					
						
							|  |  |  |           render_validation_errors(@relation) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-11-09 13:24:44 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |     raise Unauthorized unless @relation.deletable? | 
					
						
							| 
									
										
										
										
											2020-11-04 14:44:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-02 15:38:11 +00:00
										 |  |  |     @relation.init_journals(User.current) | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |     @relation.destroy | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |       format.html {redirect_to issue_path(@relation.issue_from)} | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2020-11-14 13:18:18 +00:00
										 |  |  |       format.api  {render_api_ok} | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-05 08:14:21 +00:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-16 15:17:47 +00:00
										 |  |  |   def find_issue | 
					
						
							| 
									
										
										
										
											2014-12-05 08:14:21 +00:00
										 |  |  |     @issue = Issue.find(params[:issue_id]) | 
					
						
							|  |  |  |     @project = @issue.project | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |   def find_relation | 
					
						
							|  |  |  |     @relation = IssueRelation.find(params[:id]) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-12-25 02:25:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def relation_issues_to_id | 
					
						
							| 
									
										
										
										
											2021-04-12 09:20:02 +00:00
										 |  |  |     issue_to_id = params[:relation].require(:issue_to_id) | 
					
						
							|  |  |  |     case issue_to_id | 
					
						
							|  |  |  |     when String | 
					
						
							|  |  |  |       issue_to_id = issue_to_id.split(',').reject(&:blank?) | 
					
						
							|  |  |  |     when Integer | 
					
						
							|  |  |  |       issue_to_id = [issue_to_id] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     issue_to_id | 
					
						
							| 
									
										
										
										
											2020-12-25 02:25:41 +00:00
										 |  |  |   rescue ActionController::ParameterMissing => e | 
					
						
							|  |  |  |     # We return a empty array just to loop once and return a validation error | 
					
						
							|  |  |  |     # ToDo: Find a better method to return an error if the param is missing. | 
					
						
							|  |  |  |     [''] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  | end |