##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r8882:b6742bda3d91
parent child
Show More
@@ -1,83 +1,84
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(
22 p = Project.active.has_module(:repository).find(
23 :all,
23 :all,
24 :include => :repository,
24 :include => :repository,
25 :order => "#{Project.table_name}.identifier"
25 :order => "#{Project.table_name}.identifier"
26 )
26 )
27 # extra_info attribute from repository breaks activeresource client
27 # extra_info attribute from repository breaks activeresource client
28 render :xml => p.to_xml(
28 render :xml => p.to_xml(
29 :only => [:id, :identifier, :name, :is_public, :status],
29 :only => [:id, :identifier, :name, :is_public, :status],
30 :include => {:repository => {:only => [:id, :url]}}
30 :include => {:repository => {:only => [:id, :url]}}
31 )
31 )
32 end
32 end
33
33
34 def create_project_repository
34 def create_project_repository
35 project = Project.find(params[:id])
35 project = Project.find(params[:id])
36 if project.repository
36 if project.repository
37 render :nothing => true, :status => 409
37 render :nothing => true, :status => 409
38 else
38 else
39 logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
39 logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
40 project.repository = Repository.factory(params[:vendor], params[:repository])
40 repository = Repository.factory(params[:vendor], params[:repository])
41 if project.repository && project.repository.save
41 repository.project = project
42 render :xml => {project.repository.class.name.underscore.gsub('/', '-') => {:id => project.repository.id, :url => project.repository.url}}, :status => 201
42 if repository.save
43 render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
43 else
44 else
44 render :nothing => true, :status => 422
45 render :nothing => true, :status => 422
45 end
46 end
46 end
47 end
47 end
48 end
48
49
49 def fetch_changesets
50 def fetch_changesets
50 projects = []
51 projects = []
51 scope = Project.active.has_module(:repository)
52 scope = Project.active.has_module(:repository)
52 if params[:id]
53 if params[:id]
53 project = nil
54 project = nil
54 if params[:id].to_s =~ /^\d*$/
55 if params[:id].to_s =~ /^\d*$/
55 project = scope.find(params[:id])
56 project = scope.find(params[:id])
56 else
57 else
57 project = scope.find_by_identifier(params[:id])
58 project = scope.find_by_identifier(params[:id])
58 end
59 end
59 raise ActiveRecord::RecordNotFound unless project
60 raise ActiveRecord::RecordNotFound unless project
60 projects << project
61 projects << project
61 else
62 else
62 projects = scope.all
63 projects = scope.all
63 end
64 end
64 projects.each do |project|
65 projects.each do |project|
65 project.repositories.each do |repository|
66 project.repositories.each do |repository|
66 repository.fetch_changesets
67 repository.fetch_changesets
67 end
68 end
68 end
69 end
69 render :nothing => true, :status => 200
70 render :nothing => true, :status => 200
70 rescue ActiveRecord::RecordNotFound
71 rescue ActiveRecord::RecordNotFound
71 render :nothing => true, :status => 404
72 render :nothing => true, :status => 404
72 end
73 end
73
74
74 protected
75 protected
75
76
76 def check_enabled
77 def check_enabled
77 User.current = nil
78 User.current = nil
78 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
79 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
79 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
80 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
80 return false
81 return false
81 end
82 end
82 end
83 end
83 end
84 end
General Comments 0
You need to be logged in to leave comments. Login now