To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / issue_relations_controller.rb @ 1360:45dbcd39b9e9
History | View | Annotate | Download (2.67 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 14 |
# You should have received a copy of the GNU General Public License
|
| 15 |
# along with this program; if not, write to the Free Software
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
class IssueRelationsController < ApplicationController |
| 19 |
before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] |
| 20 |
before_filter :find_relation, :except => [:index, :create] |
| 21 |
|
| 22 |
accept_api_auth :index, :show, :create, :destroy |
| 23 |
|
| 24 |
def index |
| 25 |
@relations = @issue.relations |
| 26 |
|
| 27 |
respond_to do |format|
|
| 28 |
format.html { render :nothing => true }
|
| 29 |
format.api |
| 30 |
end
|
| 31 |
end
|
| 32 |
|
| 33 |
def show |
| 34 |
raise Unauthorized unless @relation.visible? |
| 35 |
|
| 36 |
respond_to do |format|
|
| 37 |
format.html { render :nothing => true }
|
| 38 |
format.api |
| 39 |
end
|
| 40 |
end
|
| 41 |
|
| 42 |
def create |
| 43 |
@relation = IssueRelation.new(params[:relation]) |
| 44 |
@relation.issue_from = @issue |
| 45 |
if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) |
| 46 |
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
| 47 |
end
|
| 48 |
saved = @relation.save
|
| 49 |
|
| 50 |
respond_to do |format|
|
| 51 |
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
| 52 |
format.js {
|
| 53 |
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
| 54 |
} |
| 55 |
format.api {
|
| 56 |
if saved
|
| 57 |
render :action => 'show', :status => :created, :location => relation_url(@relation) |
| 58 |
else
|
| 59 |
render_validation_errors(@relation)
|
| 60 |
end
|
| 61 |
} |
| 62 |
end
|
| 63 |
end
|
| 64 |
|
| 65 |
def destroy |
| 66 |
raise Unauthorized unless @relation.deletable? |
| 67 |
@relation.destroy
|
| 68 |
|
| 69 |
respond_to do |format|
|
| 70 |
format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
|
| 71 |
format.js |
| 72 |
format.api { render_api_ok }
|
| 73 |
end
|
| 74 |
end
|
| 75 |
|
| 76 |
private |
| 77 |
def find_issue |
| 78 |
@issue = @object = Issue.find(params[:issue_id]) |
| 79 |
rescue ActiveRecord::RecordNotFound |
| 80 |
render_404 |
| 81 |
end
|
| 82 |
|
| 83 |
def find_relation |
| 84 |
@relation = IssueRelation.find(params[:id]) |
| 85 |
rescue ActiveRecord::RecordNotFound |
| 86 |
render_404 |
| 87 |
end
|
| 88 |
end
|