##// END OF EJS Templates
Do not include extra_info attribute in SysController responses because it breaks reposman activeresource client (#8707)....
Jean-Philippe Lang -
r7836:5ac802080172
parent child
Show More
@@ -1,67 +1,68
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 SysController < ActionController::Base
18 class SysController < ActionController::Base
19 before_filter :check_enabled
19 before_filter :check_enabled
20
20
21 def projects
21 def projects
22 p = Project.active.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
22 p = Project.active.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
23 render :xml => p.to_xml(:include => :repository)
23 # extra_info attribute from repository breaks activeresource client
24 render :xml => p.to_xml(:only => [:id, :identifier, :name, :is_public, :status], :include => {:repository => {:only => [:id, :url]}})
24 end
25 end
25
26
26 def create_project_repository
27 def create_project_repository
27 project = Project.find(params[:id])
28 project = Project.find(params[:id])
28 if project.repository
29 if project.repository
29 render :nothing => true, :status => 409
30 render :nothing => true, :status => 409
30 else
31 else
31 logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
32 logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
32 project.repository = Repository.factory(params[:vendor], params[:repository])
33 project.repository = Repository.factory(params[:vendor], params[:repository])
33 if project.repository && project.repository.save
34 if project.repository && project.repository.save
34 render :xml => project.repository, :status => 201
35 render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201
35 else
36 else
36 render :nothing => true, :status => 422
37 render :nothing => true, :status => 422
37 end
38 end
38 end
39 end
39 end
40 end
40
41
41 def fetch_changesets
42 def fetch_changesets
42 projects = []
43 projects = []
43 if params[:id]
44 if params[:id]
44 projects << Project.active.has_module(:repository).find(params[:id])
45 projects << Project.active.has_module(:repository).find(params[:id])
45 else
46 else
46 projects = Project.active.has_module(:repository).find(:all, :include => :repository)
47 projects = Project.active.has_module(:repository).find(:all, :include => :repository)
47 end
48 end
48 projects.each do |project|
49 projects.each do |project|
49 if project.repository
50 if project.repository
50 project.repository.fetch_changesets
51 project.repository.fetch_changesets
51 end
52 end
52 end
53 end
53 render :nothing => true, :status => 200
54 render :nothing => true, :status => 200
54 rescue ActiveRecord::RecordNotFound
55 rescue ActiveRecord::RecordNotFound
55 render :nothing => true, :status => 404
56 render :nothing => true, :status => 404
56 end
57 end
57
58
58 protected
59 protected
59
60
60 def check_enabled
61 def check_enabled
61 User.current = nil
62 User.current = nil
62 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
63 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
63 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
64 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
64 return false
65 return false
65 end
66 end
66 end
67 end
67 end
68 end
@@ -1,95 +1,107
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 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'sys_controller'
19 require 'sys_controller'
20 require 'mocha'
20 require 'mocha'
21
21
22 # Re-raise errors caught by the controller.
22 # Re-raise errors caught by the controller.
23 class SysController; def rescue_action(e) raise e end; end
23 class SysController; def rescue_action(e) raise e end; end
24
24
25 class SysControllerTest < ActionController::TestCase
25 class SysControllerTest < ActionController::TestCase
26 fixtures :projects, :repositories, :enabled_modules
26 fixtures :projects, :repositories, :enabled_modules
27
27
28 def setup
28 def setup
29 @controller = SysController.new
29 @controller = SysController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 Setting.sys_api_enabled = '1'
32 Setting.sys_api_enabled = '1'
33 Setting.enabled_scm = %w(Subversion Git)
33 Setting.enabled_scm = %w(Subversion Git)
34 end
34 end
35
35
36 def test_projects_with_repository_enabled
36 def test_projects_with_repository_enabled
37 get :projects
37 get :projects
38 assert_response :success
38 assert_response :success
39 assert_equal 'application/xml', @response.content_type
39 assert_equal 'application/xml', @response.content_type
40 with_options :tag => 'projects' do |test|
40 with_options :tag => 'projects' do |test|
41 test.assert_tag :children => { :count => Project.active.has_module(:repository).count }
41 test.assert_tag :children => { :count => Project.active.has_module(:repository).count }
42 test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}}
42 end
43 end
44 assert_no_tag 'extra-info'
45 assert_no_tag 'extra_info'
43 end
46 end
44
47
45 def test_create_project_repository
48 def test_create_project_repository
46 assert_nil Project.find(4).repository
49 assert_nil Project.find(4).repository
47
50
48 post :create_project_repository, :id => 4,
51 post :create_project_repository, :id => 4,
49 :vendor => 'Subversion',
52 :vendor => 'Subversion',
50 :repository => { :url => 'file:///create/project/repository/subproject2'}
53 :repository => { :url => 'file:///create/project/repository/subproject2'}
51 assert_response :created
54 assert_response :created
55 assert_equal 'application/xml', @response.content_type
52
56
53 r = Project.find(4).repository
57 r = Project.find(4).repository
54 assert r.is_a?(Repository::Subversion)
58 assert r.is_a?(Repository::Subversion)
55 assert_equal 'file:///create/project/repository/subproject2', r.url
59 assert_equal 'file:///create/project/repository/subproject2', r.url
60
61 assert_tag 'repository-subversion',
62 :child => {
63 :tag => 'id', :content => r.id.to_s,
64 :sibling => {:tag => 'url', :content => r.url}
65 }
66 assert_no_tag 'extra-info'
67 assert_no_tag 'extra_info'
56 end
68 end
57
69
58 def test_fetch_changesets
70 def test_fetch_changesets
59 Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
71 Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
60 get :fetch_changesets
72 get :fetch_changesets
61 assert_response :success
73 assert_response :success
62 end
74 end
63
75
64 def test_fetch_changesets_one_project
76 def test_fetch_changesets_one_project
65 Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
77 Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
66 get :fetch_changesets, :id => 'ecookbook'
78 get :fetch_changesets, :id => 'ecookbook'
67 assert_response :success
79 assert_response :success
68 end
80 end
69
81
70 def test_fetch_changesets_unknown_project
82 def test_fetch_changesets_unknown_project
71 get :fetch_changesets, :id => 'unknown'
83 get :fetch_changesets, :id => 'unknown'
72 assert_response 404
84 assert_response 404
73 end
85 end
74
86
75 def test_disabled_ws_should_respond_with_403_error
87 def test_disabled_ws_should_respond_with_403_error
76 with_settings :sys_api_enabled => '0' do
88 with_settings :sys_api_enabled => '0' do
77 get :projects
89 get :projects
78 assert_response 403
90 assert_response 403
79 end
91 end
80 end
92 end
81
93
82 def test_api_key
94 def test_api_key
83 with_settings :sys_api_key => 'my_secret_key' do
95 with_settings :sys_api_key => 'my_secret_key' do
84 get :projects, :key => 'my_secret_key'
96 get :projects, :key => 'my_secret_key'
85 assert_response :success
97 assert_response :success
86 end
98 end
87 end
99 end
88
100
89 def test_wrong_key_should_respond_with_403_error
101 def test_wrong_key_should_respond_with_403_error
90 with_settings :sys_api_enabled => 'my_secret_key' do
102 with_settings :sys_api_enabled => 'my_secret_key' do
91 get :projects, :key => 'wrong_key'
103 get :projects, :key => 'wrong_key'
92 assert_response 403
104 assert_response 403
93 end
105 end
94 end
106 end
95 end
107 end
General Comments 0
You need to be logged in to leave comments. Login now