@@ -0,0 +1,7 | |||
|
1 | api.relation do | |
|
2 | api.id @relation.id | |
|
3 | api.issue_id @relation.issue_from_id | |
|
4 | api.issue_to_id @relation.issue_to_id | |
|
5 | api.relation_type @relation.relation_type_for(@issue) | |
|
6 | api.delay @relation.delay | |
|
7 | end |
@@ -0,0 +1,83 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 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 | require File.expand_path('../../../test_helper', __FILE__) | |
|
19 | ||
|
20 | class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |
|
21 | fixtures :all | |
|
22 | ||
|
23 | def setup | |
|
24 | Setting.rest_api_enabled = '1' | |
|
25 | end | |
|
26 | ||
|
27 | context "/issues/:issue_id/relations" do | |
|
28 | context "POST" do | |
|
29 | should "create a relation" do | |
|
30 | assert_difference('IssueRelation.count') do | |
|
31 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, :authorization => credentials('jsmith') | |
|
32 | end | |
|
33 | ||
|
34 | relation = IssueRelation.first(:order => 'id DESC') | |
|
35 | assert_equal 2, relation.issue_from_id | |
|
36 | assert_equal 7, relation.issue_to_id | |
|
37 | assert_equal 'relates', relation.relation_type | |
|
38 | ||
|
39 | assert_response :created | |
|
40 | assert_equal 'application/xml', @response.content_type | |
|
41 | assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s} | |
|
42 | end | |
|
43 | ||
|
44 | context "with failure" do | |
|
45 | should "return the errors" do | |
|
46 | assert_no_difference('IssueRelation.count') do | |
|
47 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, :authorization => credentials('jsmith') | |
|
48 | end | |
|
49 | ||
|
50 | assert_response :unprocessable_entity | |
|
51 | assert_tag :errors, :child => {:tag => 'error', :content => 'relation_type is not included in the list'} | |
|
52 | end | |
|
53 | end | |
|
54 | end | |
|
55 | end | |
|
56 | ||
|
57 | context "/issues/:issue_id/relations/:id" do | |
|
58 | context "GET" do | |
|
59 | should "return the relation" do | |
|
60 | get '/issues/3/relations/2.xml', {}, :authorization => credentials('jsmith') | |
|
61 | ||
|
62 | assert_response :success | |
|
63 | assert_equal 'application/xml', @response.content_type | |
|
64 | assert_tag 'relation', :child => {:tag => 'id', :content => '2'} | |
|
65 | end | |
|
66 | end | |
|
67 | ||
|
68 | context "DELETE" do | |
|
69 | should "delete the relation" do | |
|
70 | assert_difference('IssueRelation.count', -1) do | |
|
71 | delete '/issues/3/relations/2.xml', {}, :authorization => credentials('jsmith') | |
|
72 | end | |
|
73 | ||
|
74 | assert_response :ok | |
|
75 | assert_nil IssueRelation.find_by_id(2) | |
|
76 | end | |
|
77 | end | |
|
78 | end | |
|
79 | ||
|
80 | def credentials(user, password=nil) | |
|
81 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
|
82 | end | |
|
83 | end |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -17,14 +17,28 | |||
|
17 | 17 | |
|
18 | 18 | class IssueRelationsController < ApplicationController |
|
19 | 19 | before_filter :find_issue, :find_project_from_association, :authorize |
|
20 | accept_key_auth :show, :create, :destroy | |
|
20 | 21 | |
|
21 |
def |
|
|
22 | def show | |
|
23 | @relation = @issue.find_relation(params[:id]) | |
|
24 | ||
|
25 | respond_to do |format| | |
|
26 | format.html { render :nothing => true } | |
|
27 | format.api | |
|
28 | end | |
|
29 | rescue ActiveRecord::RecordNotFound | |
|
30 | render_404 | |
|
31 | end | |
|
32 | ||
|
33 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
|
34 | def create | |
|
22 | 35 | @relation = IssueRelation.new(params[:relation]) |
|
23 | 36 | @relation.issue_from = @issue |
|
24 | 37 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) |
|
25 | 38 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
|
26 | 39 | end |
|
27 | @relation.save if request.post? | |
|
40 | saved = @relation.save | |
|
41 | ||
|
28 | 42 | respond_to do |format| |
|
29 | 43 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
30 | 44 | format.js do |
@@ -37,22 +51,31 class IssueRelationsController < ApplicationController | |||
|
37 | 51 | end |
|
38 | 52 | end |
|
39 | 53 | end |
|
54 | format.api { | |
|
55 | if saved | |
|
56 | render :action => 'show', :status => :created, :location => issue_relation_url(@issue, @relation) | |
|
57 | else | |
|
58 | render_validation_errors(@relation) | |
|
59 | end | |
|
60 | } | |
|
40 | 61 | end |
|
41 | 62 | end |
|
42 | 63 | |
|
64 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } | |
|
43 | 65 | def destroy |
|
44 |
relation = |
|
|
45 | if request.post? && @issue.relations.include?(relation) | |
|
46 | relation.destroy | |
|
47 | @issue.reload | |
|
48 | end | |
|
66 | relation = @issue.find_relation(params[:id]) | |
|
67 | relation.destroy | |
|
68 | ||
|
49 | 69 | respond_to do |format| |
|
50 | 70 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
51 | 71 | format.js { |
|
52 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |
|
72 | @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |
|
53 | 73 | render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} |
|
54 | 74 | } |
|
75 | format.api { head :ok } | |
|
55 | 76 | end |
|
77 | rescue ActiveRecord::RecordNotFound | |
|
78 | render_404 | |
|
56 | 79 | end |
|
57 | 80 | |
|
58 | 81 | private |
@@ -501,6 +501,11 class Issue < ActiveRecord::Base | |||
|
501 | 501 | def relations |
|
502 | 502 | (relations_from + relations_to).sort |
|
503 | 503 | end |
|
504 | ||
|
505 | # Finds an issue relation given its id. | |
|
506 | def find_relation(relation_id) | |
|
507 | IssueRelation.find(relation_id, :conditions => ["issue_to_id = ? OR issue_from_id = ?", id, id]) | |
|
508 | end | |
|
504 | 509 | |
|
505 | 510 | def all_dependent_issues(except=[]) |
|
506 | 511 | except << self |
@@ -20,7 +20,7 | |||
|
20 | 20 | <td class="start_date"><%= format_date(relation.other_issue(@issue).start_date) %></td> |
|
21 | 21 | <td class="due_date"><%= format_date(relation.other_issue(@issue).due_date) %></td> |
|
22 | 22 | <td class="buttons"><%= link_to_remote(image_tag('link_break.png'), { :url => {:controller => 'issue_relations', :action => 'destroy', :issue_id => @issue, :id => relation}, |
|
23 |
:method => : |
|
|
23 | :method => :delete | |
|
24 | 24 | }, :title => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %></td> |
|
25 | 25 | </tr> |
|
26 | 26 | <% end %> |
@@ -29,7 +29,7 | |||
|
29 | 29 | <% end %> |
|
30 | 30 | |
|
31 | 31 | <% remote_form_for(:relation, @relation, |
|
32 |
:url => {:controller => 'issue_relations', :action => ' |
|
|
32 | :url => {:controller => 'issue_relations', :action => 'create', :issue_id => @issue}, | |
|
33 | 33 | :method => :post, |
|
34 | 34 | :complete => "Form.Element.focus('relation_issue_to_id');", |
|
35 | 35 | :html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %> |
@@ -27,7 +27,7 api.issue do | |||
|
27 | 27 | |
|
28 | 28 | api.array :relations do |
|
29 | 29 | @relations.each do |relation| |
|
30 |
api.relation(:id => relation.id, :issue_id => relation. |
|
|
30 | api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay) | |
|
31 | 31 | end |
|
32 | 32 | end if include_in_api_response?('relations') && @relations.present? |
|
33 | 33 |
@@ -110,17 +110,13 ActionController::Routing::Routes.draw do |map| | |||
|
110 | 110 | |
|
111 | 111 | map.resources :issues, :member => { :edit => :post }, :collection => {} do |issues| |
|
112 | 112 | issues.resources :time_entries, :controller => 'timelog' |
|
113 | issues.resources :relations, :controller => 'issue_relations', :only => [:show, :create, :destroy] | |
|
113 | 114 | end |
|
114 | 115 | |
|
115 | 116 | map.resources :issues, :path_prefix => '/projects/:project_id', :collection => { :create => :post } do |issues| |
|
116 | 117 | issues.resources :time_entries, :controller => 'timelog' |
|
117 | 118 | end |
|
118 | 119 | |
|
119 | map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations| | |
|
120 | relations.connect 'issues/:issue_id/relations/:id', :action => 'new' | |
|
121 | relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy' | |
|
122 | end | |
|
123 | ||
|
124 | 120 | map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new' |
|
125 | 121 | |
|
126 | 122 | map.with_options :controller => 'users' do |users| |
@@ -235,7 +231,6 ActionController::Routing::Routes.draw do |map| | |||
|
235 | 231 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' |
|
236 | 232 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' |
|
237 | 233 | map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki' |
|
238 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' | |
|
239 | 234 | map.connect 'projects/:project_id/news/:action', :controller => 'news' |
|
240 | 235 | map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/ |
|
241 | 236 | map.with_options :controller => 'repositories' do |omap| |
@@ -69,7 +69,7 Redmine::AccessControl.map do |map| | |||
|
69 | 69 | :reports => [:issue_report, :issue_report_details]} |
|
70 | 70 | map.permission :add_issues, {:issues => [:new, :create, :update_form]} |
|
71 | 71 | map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]} |
|
72 |
map.permission :manage_issue_relations, {:issue_relations => [: |
|
|
72 | map.permission :manage_issue_relations, {:issue_relations => [:show, :create, :destroy]} | |
|
73 | 73 | map.permission :manage_subtasks, {} |
|
74 | 74 | map.permission :set_issues_private, {} |
|
75 | 75 | map.permission :set_own_issues_private, {}, :require => :loggedin |
@@ -1,3 +1,20 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 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 | ||
|
1 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 19 | require 'issue_relations_controller' |
|
3 | 20 | |
@@ -25,18 +42,18 class IssueRelationsControllerTest < ActionController::TestCase | |||
|
25 | 42 | User.current = nil |
|
26 | 43 | end |
|
27 | 44 | |
|
28 |
def test_ |
|
|
45 | def test_create | |
|
29 | 46 | assert_difference 'IssueRelation.count' do |
|
30 | 47 | @request.session[:user_id] = 3 |
|
31 |
post : |
|
|
48 | post :create, :issue_id => 1, | |
|
32 | 49 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} |
|
33 | 50 | end |
|
34 | 51 | end |
|
35 | 52 | |
|
36 |
def test_ |
|
|
53 | def test_create_xhr | |
|
37 | 54 | assert_difference 'IssueRelation.count' do |
|
38 | 55 | @request.session[:user_id] = 3 |
|
39 |
xhr :post, : |
|
|
56 | xhr :post, :create, | |
|
40 | 57 | :issue_id => 3, |
|
41 | 58 | :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} |
|
42 | 59 | assert_select_rjs 'relations' do |
@@ -46,19 +63,19 class IssueRelationsControllerTest < ActionController::TestCase | |||
|
46 | 63 | end |
|
47 | 64 | end |
|
48 | 65 | |
|
49 |
def test_ |
|
|
66 | def test_create_should_accept_id_with_hash | |
|
50 | 67 | assert_difference 'IssueRelation.count' do |
|
51 | 68 | @request.session[:user_id] = 3 |
|
52 |
post : |
|
|
69 | post :create, :issue_id => 1, | |
|
53 | 70 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} |
|
54 | 71 | end |
|
55 | 72 | end |
|
56 | 73 | |
|
57 |
def test_ |
|
|
74 | def test_create_should_not_break_with_non_numerical_id | |
|
58 | 75 | assert_no_difference 'IssueRelation.count' do |
|
59 | 76 | assert_nothing_raised do |
|
60 | 77 | @request.session[:user_id] = 3 |
|
61 |
post : |
|
|
78 | post :create, :issue_id => 1, | |
|
62 | 79 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} |
|
63 | 80 | end |
|
64 | 81 | end |
@@ -70,7 +87,7 class IssueRelationsControllerTest < ActionController::TestCase | |||
|
70 | 87 | |
|
71 | 88 | assert_no_difference 'IssueRelation.count' do |
|
72 | 89 | @request.session[:user_id] = 3 |
|
73 |
post : |
|
|
90 | post :create, :issue_id => 1, | |
|
74 | 91 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} |
|
75 | 92 | end |
|
76 | 93 | end |
@@ -80,7 +97,7 class IssueRelationsControllerTest < ActionController::TestCase | |||
|
80 | 97 | def test_destroy |
|
81 | 98 | assert_difference 'IssueRelation.count', -1 do |
|
82 | 99 | @request.session[:user_id] = 3 |
|
83 |
|
|
|
100 | delete :destroy, :id => '2', :issue_id => '3' | |
|
84 | 101 | end |
|
85 | 102 | end |
|
86 | 103 | |
@@ -92,7 +109,7 class IssueRelationsControllerTest < ActionController::TestCase | |||
|
92 | 109 | |
|
93 | 110 | assert_difference 'IssueRelation.count', -1 do |
|
94 | 111 | @request.session[:user_id] = 3 |
|
95 |
xhr : |
|
|
112 | xhr :delete, :destroy, :id => '2', :issue_id => '3' | |
|
96 | 113 | assert_select_rjs 'relations' do |
|
97 | 114 | assert_select 'table', 1 |
|
98 | 115 | assert_select 'tr', 1 # relation left |
@@ -118,8 +118,17 class RoutingTest < ActionController::IntegrationTest | |||
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | context "issue relations" do |
|
121 |
should_route :post, "/issues/1/relations", :controller => 'issue_relations', :action => ' |
|
|
122 |
should_route :post, "/issues/1/relations |
|
|
121 | should_route :post, "/issues/1/relations", :controller => 'issue_relations', :action => 'create', :issue_id => '1' | |
|
122 | should_route :post, "/issues/1/relations.xml", :controller => 'issue_relations', :action => 'create', :issue_id => '1', :format => 'xml' | |
|
123 | should_route :post, "/issues/1/relations.json", :controller => 'issue_relations', :action => 'create', :issue_id => '1', :format => 'json' | |
|
124 | ||
|
125 | should_route :get, "/issues/1/relations/23", :controller => 'issue_relations', :action => 'show', :issue_id => '1', :id => '23' | |
|
126 | should_route :get, "/issues/1/relations/23.xml", :controller => 'issue_relations', :action => 'show', :issue_id => '1', :id => '23', :format => 'xml' | |
|
127 | should_route :get, "/issues/1/relations/23.json", :controller => 'issue_relations', :action => 'show', :issue_id => '1', :id => '23', :format => 'json' | |
|
128 | ||
|
129 | should_route :delete, "/issues/1/relations/23", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23' | |
|
130 | should_route :delete, "/issues/1/relations/23.xml", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23', :format => 'xml' | |
|
131 | should_route :delete, "/issues/1/relations/23.json", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23', :format => 'json' | |
|
123 | 132 | end |
|
124 | 133 | |
|
125 | 134 | context "issue reports" do |
General Comments 0
You need to be logged in to leave comments.
Login now