| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							|  |  |  | # Copyright (C) 2006-2011  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 | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |   before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] | 
					
						
							|  |  |  |   before_filter :find_relation, :except => [:index, :create] | 
					
						
							| 
									
										
										
										
											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| | 
					
						
							|  |  |  |       format.html { render :nothing => true } | 
					
						
							|  |  |  |       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| | 
					
						
							|  |  |  |       format.html { render :nothing => true } | 
					
						
							|  |  |  |       format.api | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def create | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     @relation = IssueRelation.new(params[:relation]) | 
					
						
							|  |  |  |     @relation.issue_from = @issue | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |     if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) | 
					
						
							|  |  |  |       @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |     saved = @relation.save | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | 
					
						
							|  |  |  |       format.js do | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |         @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |         render :update do |page| | 
					
						
							|  |  |  |           page.replace_html "relations", :partial => 'issues/relations' | 
					
						
							|  |  |  |           if @relation.errors.empty? | 
					
						
							|  |  |  |             page << "$('relation_delay').value = ''" | 
					
						
							|  |  |  |             page << "$('relation_issue_to_id').value = ''" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							|  |  |  |     @relation.destroy | 
					
						
							| 
									
										
										
										
											2011-08-31 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 13:22:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2011-12-10 13:33:01 +00:00
										 |  |  |       format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |       format.js   { render(:update) {|page| page.remove "relation-#{@relation.id}"} } | 
					
						
							|  |  |  |       format.api  { head :ok } | 
					
						
							| 
									
										
										
										
											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
										 |  |  | private | 
					
						
							| 
									
										
										
										
											2010-03-16 15:17:47 +00:00
										 |  |  |   def find_issue | 
					
						
							|  |  |  |     @issue = @object = Issue.find(params[:issue_id]) | 
					
						
							| 
									
										
										
										
											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 |