issue_relations_controller.rb
88 lines
| 2.7 KiB
| text/x-ruby
|
RubyLexer
|
r6056 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r503 | # | ||
# 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. | ||||
|
r6769 | # | ||
|
r503 | # 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. | ||||
|
r6769 | # | ||
|
r503 | # 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 | ||||
|
r6064 | before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] | ||
before_filter :find_relation, :except => [:index, :create] | ||||
|
r6769 | |||
|
r6077 | accept_api_auth :index, :show, :create, :destroy | ||
|
r6769 | |||
|
r6059 | def index | ||
@relations = @issue.relations | ||||
|
r6769 | |||
|
r6059 | respond_to do |format| | ||
format.html { render :nothing => true } | ||||
format.api | ||||
end | ||||
end | ||||
|
r6769 | |||
|
r6056 | def show | ||
|
r6064 | raise Unauthorized unless @relation.visible? | ||
|
r6056 | |||
respond_to do |format| | ||||
format.html { render :nothing => true } | ||||
format.api | ||||
end | ||||
end | ||||
|
r6769 | |||
|
r6056 | def create | ||
|
r503 | @relation = IssueRelation.new(params[:relation]) | ||
@relation.issue_from = @issue | ||||
|
r9250 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) | ||
|
r3299 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | ||
|
r2321 | end | ||
|
r6056 | saved = @relation.save | ||
|
r6769 | |||
|
r503 | respond_to do |format| | ||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | ||||
|
r9862 | format.js { | ||
|
r4644 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | ||
|
r9862 | } | ||
|
r6769 | format.api { | ||
|
r6056 | if saved | ||
|
r6064 | render :action => 'show', :status => :created, :location => relation_url(@relation) | ||
|
r6056 | else | ||
render_validation_errors(@relation) | ||||
end | ||||
} | ||||
|
r503 | end | ||
end | ||||
|
r6769 | |||
|
r503 | def destroy | ||
|
r6064 | raise Unauthorized unless @relation.deletable? | ||
@relation.destroy | ||||
|
r6769 | |||
|
r503 | respond_to do |format| | ||
|
r8042 | format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? | ||
|
r9862 | format.js | ||
|
r9792 | format.api { render_api_ok } | ||
|
r503 | end | ||
end | ||||
|
r6769 | |||
|
r503 | private | ||
|
r3477 | def find_issue | ||
@issue = @object = Issue.find(params[:issue_id]) | ||||
|
r503 | rescue ActiveRecord::RecordNotFound | ||
render_404 | ||||
end | ||||
|
r6769 | |||
|
r6064 | def find_relation | ||
@relation = IssueRelation.find(params[:id]) | ||||
rescue ActiveRecord::RecordNotFound | ||||
render_404 | ||||
end | ||||
|
r503 | end | ||