2011-07-04 19:03:04 +02:00
|
|
|
# Redmine - project management software
|
2013-01-12 10:29:31 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2007-05-05 15:22:27 +02: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 13:14:13 +02:00
|
|
|
#
|
2007-05-05 15:22:27 +02: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 13:14:13 +02:00
|
|
|
#
|
2007-05-05 15:22:27 +02: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 18:47:34 +02:00
|
|
|
before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
|
|
|
|
before_filter :find_relation, :except => [:index, :create]
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-09 10:56:07 +02:00
|
|
|
accept_api_auth :index, :show, :create, :destroy
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-04 19:44:41 +02:00
|
|
|
def index
|
|
|
|
@relations = @issue.relations
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-04 19:44:41 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :nothing => true }
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-04 19:03:04 +02:00
|
|
|
def show
|
2011-07-05 18:47:34 +02:00
|
|
|
raise Unauthorized unless @relation.visible?
|
2011-07-04 19:03:04 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :nothing => true }
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-04 19:03:04 +02:00
|
|
|
def create
|
2007-05-05 15:22:27 +02:00
|
|
|
@relation = IssueRelation.new(params[:relation])
|
|
|
|
@relation.issue_from = @issue
|
2012-04-11 19:25:05 +02:00
|
|
|
if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
|
2010-02-12 19:35:31 +01:00
|
|
|
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
|
2009-01-27 20:33:03 +01:00
|
|
|
end
|
2011-07-04 19:03:04 +02:00
|
|
|
saved = @relation.save
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2007-05-05 15:22:27 +02:00
|
|
|
respond_to do |format|
|
2012-12-11 18:51:30 +01:00
|
|
|
format.html { redirect_to issue_path(@issue) }
|
2012-07-19 19:06:30 +02:00
|
|
|
format.js {
|
2013-02-24 11:06:27 +01:00
|
|
|
@relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
2012-07-19 19:06:30 +02:00
|
|
|
}
|
2011-08-31 13:14:13 +02:00
|
|
|
format.api {
|
2011-07-04 19:03:04 +02:00
|
|
|
if saved
|
2011-07-05 18:47:34 +02:00
|
|
|
render :action => 'show', :status => :created, :location => relation_url(@relation)
|
2011-07-04 19:03:04 +02:00
|
|
|
else
|
|
|
|
render_validation_errors(@relation)
|
|
|
|
end
|
|
|
|
}
|
2007-05-05 15:22:27 +02:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2007-05-05 15:22:27 +02:00
|
|
|
def destroy
|
2011-07-05 18:47:34 +02:00
|
|
|
raise Unauthorized unless @relation.deletable?
|
|
|
|
@relation.destroy
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2007-05-05 15:22:27 +02:00
|
|
|
respond_to do |format|
|
2012-12-11 18:51:30 +01:00
|
|
|
format.html { redirect_to issue_path(@relation.issue_from) }
|
2012-07-19 19:06:30 +02:00
|
|
|
format.js
|
2012-07-14 10:13:55 +02:00
|
|
|
format.api { render_api_ok }
|
2007-05-05 15:22:27 +02:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2007-05-05 15:22:27 +02:00
|
|
|
private
|
2010-03-16 16:17:47 +01:00
|
|
|
def find_issue
|
|
|
|
@issue = @object = Issue.find(params[:issue_id])
|
2007-05-05 15:22:27 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2011-08-31 13:14:13 +02:00
|
|
|
|
2011-07-05 18:47:34 +02:00
|
|
|
def find_relation
|
|
|
|
@relation = IssueRelation.find(params[:id])
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2007-05-05 15:22:27 +02:00
|
|
|
end
|