@@ -1,68 +1,75 | |||||
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 => "#{Project.table_name}.identifier") |
|
22 | p = Project.active.has_module(:repository).find( | |
|
23 | :all, | |||
|
24 | :include => :repository, | |||
|
25 | :order => "#{Project.table_name}.identifier" | |||
|
26 | ) | |||
23 | # extra_info attribute from repository breaks activeresource client |
|
27 | # 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]}}) |
|
28 | render :xml => p.to_xml( | |
|
29 | :only => [:id, :identifier, :name, :is_public, :status], | |||
|
30 | :include => {:repository => {:only => [:id, :url]}} | |||
|
31 | ) | |||
25 | end |
|
32 | end | |
26 |
|
33 | |||
27 | def create_project_repository |
|
34 | def create_project_repository | |
28 | project = Project.find(params[:id]) |
|
35 | project = Project.find(params[:id]) | |
29 | if project.repository |
|
36 | if project.repository | |
30 | render :nothing => true, :status => 409 |
|
37 | render :nothing => true, :status => 409 | |
31 | else |
|
38 | else | |
32 | 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}." | |
33 | project.repository = Repository.factory(params[:vendor], params[:repository]) |
|
40 | project.repository = Repository.factory(params[:vendor], params[:repository]) | |
34 | if project.repository && project.repository.save |
|
41 | if project.repository && project.repository.save | |
35 | render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201 |
|
42 | render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201 | |
36 | else |
|
43 | else | |
37 | render :nothing => true, :status => 422 |
|
44 | render :nothing => true, :status => 422 | |
38 | end |
|
45 | end | |
39 | end |
|
46 | end | |
40 | end |
|
47 | end | |
41 |
|
48 | |||
42 | def fetch_changesets |
|
49 | def fetch_changesets | |
43 | projects = [] |
|
50 | projects = [] | |
44 | if params[:id] |
|
51 | if params[:id] | |
45 | projects << Project.active.has_module(:repository).find(params[:id]) |
|
52 | projects << Project.active.has_module(:repository).find(params[:id]) | |
46 | else |
|
53 | else | |
47 | projects = Project.active.has_module(:repository).all |
|
54 | projects = Project.active.has_module(:repository).all | |
48 | end |
|
55 | end | |
49 | projects.each do |project| |
|
56 | projects.each do |project| | |
50 | project.repositories.each do |repository| |
|
57 | project.repositories.each do |repository| | |
51 | repository.fetch_changesets |
|
58 | repository.fetch_changesets | |
52 | end |
|
59 | end | |
53 | end |
|
60 | end | |
54 | render :nothing => true, :status => 200 |
|
61 | render :nothing => true, :status => 200 | |
55 | rescue ActiveRecord::RecordNotFound |
|
62 | rescue ActiveRecord::RecordNotFound | |
56 | render :nothing => true, :status => 404 |
|
63 | render :nothing => true, :status => 404 | |
57 | end |
|
64 | end | |
58 |
|
65 | |||
59 | protected |
|
66 | protected | |
60 |
|
67 | |||
61 | def check_enabled |
|
68 | def check_enabled | |
62 | User.current = nil |
|
69 | User.current = nil | |
63 | unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key |
|
70 | unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key | |
64 | render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403 |
|
71 | render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403 | |
65 | return false |
|
72 | return false | |
66 | end |
|
73 | end | |
67 | end |
|
74 | end | |
68 | end |
|
75 | end |
General Comments 0
You need to be logged in to leave comments.
Login now