To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 9c / 9cf686fc2a47c572e6d1fe8e9ebae6d200ed1f80.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.89 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  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
class SysController < ActionController::Base
19
  before_filter :check_enabled
20
21
  def projects
22
    p = Project.active.has_module(:repository).find(
23
                   :all,
24
                   :include => :repository,
25
                   :order => "#{Project.table_name}.identifier"
26
                 )
27
    # extra_info attribute from repository breaks activeresource client
28
    render :xml => p.to_xml(
29
                       :only => [:id, :identifier, :name, :is_public, :status],
30
                       :include => {:repository => {:only => [:id, :url]}}
31
                     )
32
  end
33
34
  def create_project_repository
35
    project = Project.find(params[:id])
36
    if project.repository
37
      render :nothing => true, :status => 409
38
    else
39
      logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
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
44
      else
45
        render :nothing => true, :status => 422
46
      end
47
    end
48
  end
49
50
  def fetch_changesets
51
    projects = []
52
    scope = Project.active.has_module(:repository)
53
    if params[:id]
54
      project = nil
55
      if params[:id].to_s =~ /^\d*$/
56
        project = scope.find(params[:id])
57
      else
58
        project = scope.find_by_identifier(params[:id])
59
      end
60
      raise ActiveRecord::RecordNotFound unless project
61
      projects << project
62
    else
63
      projects = scope.all
64
    end
65
    projects.each do |project|
66
      project.repositories.each do |repository|
67
        repository.fetch_changesets
68
      end
69
    end
70
    render :nothing => true, :status => 200
71
  rescue ActiveRecord::RecordNotFound
72
    render :nothing => true, :status => 404
73
  end
74
75
  protected
76
77
  def check_enabled
78
    User.current = nil
79
    unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
80
      render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
81
      return false
82
    end
83
  end
84
end