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