##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r8882:b6742bda3d91
parent child
Show More
@@ -1,83 +1,84
1 1 # Redmine - project management software
2 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
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class SysController < ActionController::Base
19 19 before_filter :check_enabled
20 20
21 21 def projects
22 22 p = Project.active.has_module(:repository).find(
23 23 :all,
24 24 :include => :repository,
25 25 :order => "#{Project.table_name}.identifier"
26 26 )
27 27 # extra_info attribute from repository breaks activeresource client
28 28 render :xml => p.to_xml(
29 29 :only => [:id, :identifier, :name, :is_public, :status],
30 30 :include => {:repository => {:only => [:id, :url]}}
31 31 )
32 32 end
33 33
34 34 def create_project_repository
35 35 project = Project.find(params[:id])
36 36 if project.repository
37 37 render :nothing => true, :status => 409
38 38 else
39 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])
41 if project.repository && project.repository.save
42 render :xml => {project.repository.class.name.underscore.gsub('/', '-') => {:id => project.repository.id, :url => project.repository.url}}, :status => 201
40 repository = Repository.factory(params[:vendor], params[:repository])
41 repository.project = project
42 if repository.save
43 render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
43 44 else
44 45 render :nothing => true, :status => 422
45 46 end
46 47 end
47 48 end
48 49
49 50 def fetch_changesets
50 51 projects = []
51 52 scope = Project.active.has_module(:repository)
52 53 if params[:id]
53 54 project = nil
54 55 if params[:id].to_s =~ /^\d*$/
55 56 project = scope.find(params[:id])
56 57 else
57 58 project = scope.find_by_identifier(params[:id])
58 59 end
59 60 raise ActiveRecord::RecordNotFound unless project
60 61 projects << project
61 62 else
62 63 projects = scope.all
63 64 end
64 65 projects.each do |project|
65 66 project.repositories.each do |repository|
66 67 repository.fetch_changesets
67 68 end
68 69 end
69 70 render :nothing => true, :status => 200
70 71 rescue ActiveRecord::RecordNotFound
71 72 render :nothing => true, :status => 404
72 73 end
73 74
74 75 protected
75 76
76 77 def check_enabled
77 78 User.current = nil
78 79 unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
79 80 render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
80 81 return false
81 82 end
82 83 end
83 84 end
General Comments 0
You need to be logged in to leave comments. Login now