| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2019-05-25 07:36:06 +00:00
										 |  |  | # Copyright (C) 2006-2019  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| | 
					
						
							| 
									
										
										
										
											2016-07-17 06:35:28 +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| | 
					
						
							| 
									
										
										
										
											2016-07-17 06:35:28 +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 | 
					
						
							| 
									
										
										
										
											2016-01-16 08:56:30 +00:00
										 |  |  |     @relation = IssueRelation.new | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     @relation.issue_from = @issue | 
					
						
							| 
									
										
										
										
											2016-01-16 08:56:30 +00:00
										 |  |  |     @relation.safe_attributes = params[:relation] | 
					
						
							| 
									
										
										
										
											2014-11-02 15:38:11 +00:00
										 |  |  |     @relation.init_journals(User.current) | 
					
						
							| 
									
										
										
										
											2018-01-07 00:37:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       saved = @relation.save | 
					
						
							|  |  |  |     rescue ActiveRecord::RecordNotUnique | 
					
						
							|  |  |  |       saved = false | 
					
						
							|  |  |  |       @relation.errors.add :base, :taken | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to issue_path(@issue) } | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |       format.js { | 
					
						
							| 
									
										
										
										
											2013-02-24 09:59:45 +00:00
										 |  |  |         @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  |       format.api { | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											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| | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       format.html { redirect_to issue_path(@relation.issue_from) } | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2012-07-14 08:13:55 +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 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  | end |