@@ -1,90 +1,92 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 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 |
|
19 | before_filter :find_issue, :authorize, :only => [:index, :create] | |
20 |
before_filter :find_relation, : |
|
20 | before_filter :find_relation, :only => [:show, :destroy] | |
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 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def create |
|
42 | def create | |
43 | @relation = IssueRelation.new(params[:relation]) |
|
43 | @relation = IssueRelation.new(params[:relation]) | |
44 | @relation.issue_from = @issue |
|
44 | @relation.issue_from = @issue | |
45 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) |
|
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) |
|
46 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | |
47 | end |
|
47 | end | |
48 | @relation.init_journals(User.current) |
|
48 | @relation.init_journals(User.current) | |
49 | saved = @relation.save |
|
49 | saved = @relation.save | |
50 |
|
50 | |||
51 | respond_to do |format| |
|
51 | respond_to do |format| | |
52 | format.html { redirect_to issue_path(@issue) } |
|
52 | format.html { redirect_to issue_path(@issue) } | |
53 | format.js { |
|
53 | format.js { | |
54 | @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
54 | @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |
55 | } |
|
55 | } | |
56 | format.api { |
|
56 | format.api { | |
57 | if saved |
|
57 | if saved | |
58 | render :action => 'show', :status => :created, :location => relation_url(@relation) |
|
58 | render :action => 'show', :status => :created, :location => relation_url(@relation) | |
59 | else |
|
59 | else | |
60 | render_validation_errors(@relation) |
|
60 | render_validation_errors(@relation) | |
61 | end |
|
61 | end | |
62 | } |
|
62 | } | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def destroy |
|
66 | def destroy | |
67 | raise Unauthorized unless @relation.deletable? |
|
67 | raise Unauthorized unless @relation.deletable? | |
68 | @relation.init_journals(User.current) |
|
68 | @relation.init_journals(User.current) | |
69 | @relation.destroy |
|
69 | @relation.destroy | |
70 |
|
70 | |||
71 | respond_to do |format| |
|
71 | respond_to do |format| | |
72 | format.html { redirect_to issue_path(@relation.issue_from) } |
|
72 | format.html { redirect_to issue_path(@relation.issue_from) } | |
73 | format.js |
|
73 | format.js | |
74 | format.api { render_api_ok } |
|
74 | format.api { render_api_ok } | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | private |
|
78 | private | |
|
79 | ||||
79 | def find_issue |
|
80 | def find_issue | |
80 |
@issue |
|
81 | @issue = Issue.find(params[:issue_id]) | |
|
82 | @project = @issue.project | |||
81 | rescue ActiveRecord::RecordNotFound |
|
83 | rescue ActiveRecord::RecordNotFound | |
82 | render_404 |
|
84 | render_404 | |
83 | end |
|
85 | end | |
84 |
|
86 | |||
85 | def find_relation |
|
87 | def find_relation | |
86 | @relation = IssueRelation.find(params[:id]) |
|
88 | @relation = IssueRelation.find(params[:id]) | |
87 | rescue ActiveRecord::RecordNotFound |
|
89 | rescue ActiveRecord::RecordNotFound | |
88 | render_404 |
|
90 | render_404 | |
89 | end |
|
91 | end | |
90 | end |
|
92 | end |
General Comments 0
You need to be logged in to leave comments.
Login now