##// END OF EJS Templates
Removed useless rescue....
Jean-Philippe Lang -
r7861:740dc53aab0c
parent child
Show More
@@ -1,101 +1,97
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssueRelationsController < ApplicationController
18 class IssueRelationsController < ApplicationController
19 before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
19 before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
20 before_filter :find_relation, :except => [:index, :create]
20 before_filter :find_relation, :except => [:index, :create]
21
21
22 accept_api_auth :index, :show, :create, :destroy
22 accept_api_auth :index, :show, :create, :destroy
23
23
24 def index
24 def index
25 @relations = @issue.relations
25 @relations = @issue.relations
26
26
27 respond_to do |format|
27 respond_to do |format|
28 format.html { render :nothing => true }
28 format.html { render :nothing => true }
29 format.api
29 format.api
30 end
30 end
31 end
31 end
32
32
33 def show
33 def show
34 raise Unauthorized unless @relation.visible?
34 raise Unauthorized unless @relation.visible?
35
35
36 respond_to do |format|
36 respond_to do |format|
37 format.html { render :nothing => true }
37 format.html { render :nothing => true }
38 format.api
38 format.api
39 end
39 end
40 rescue ActiveRecord::RecordNotFound
41 render_404
42 end
40 end
43
41
44 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
42 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
45 def create
43 def create
46 @relation = IssueRelation.new(params[:relation])
44 @relation = IssueRelation.new(params[:relation])
47 @relation.issue_from = @issue
45 @relation.issue_from = @issue
48 if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
46 if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
49 @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
47 @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
50 end
48 end
51 saved = @relation.save
49 saved = @relation.save
52
50
53 respond_to do |format|
51 respond_to do |format|
54 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
52 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
55 format.js do
53 format.js do
56 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
54 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
57 render :update do |page|
55 render :update do |page|
58 page.replace_html "relations", :partial => 'issues/relations'
56 page.replace_html "relations", :partial => 'issues/relations'
59 if @relation.errors.empty?
57 if @relation.errors.empty?
60 page << "$('relation_delay').value = ''"
58 page << "$('relation_delay').value = ''"
61 page << "$('relation_issue_to_id').value = ''"
59 page << "$('relation_issue_to_id').value = ''"
62 end
60 end
63 end
61 end
64 end
62 end
65 format.api {
63 format.api {
66 if saved
64 if saved
67 render :action => 'show', :status => :created, :location => relation_url(@relation)
65 render :action => 'show', :status => :created, :location => relation_url(@relation)
68 else
66 else
69 render_validation_errors(@relation)
67 render_validation_errors(@relation)
70 end
68 end
71 }
69 }
72 end
70 end
73 end
71 end
74
72
75 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
73 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
76 def destroy
74 def destroy
77 raise Unauthorized unless @relation.deletable?
75 raise Unauthorized unless @relation.deletable?
78 @relation.destroy
76 @relation.destroy
79
77
80 respond_to do |format|
78 respond_to do |format|
81 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
79 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
82 format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
80 format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
83 format.api { head :ok }
81 format.api { head :ok }
84 end
82 end
85 rescue ActiveRecord::RecordNotFound
86 render_404
87 end
83 end
88
84
89 private
85 private
90 def find_issue
86 def find_issue
91 @issue = @object = Issue.find(params[:issue_id])
87 @issue = @object = Issue.find(params[:issue_id])
92 rescue ActiveRecord::RecordNotFound
88 rescue ActiveRecord::RecordNotFound
93 render_404
89 render_404
94 end
90 end
95
91
96 def find_relation
92 def find_relation
97 @relation = IssueRelation.find(params[:id])
93 @relation = IssueRelation.find(params[:id])
98 rescue ActiveRecord::RecordNotFound
94 rescue ActiveRecord::RecordNotFound
99 render_404
95 render_404
100 end
96 end
101 end
97 end
General Comments 0
You need to be logged in to leave comments. Login now