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 / app / controllers / sys_controller.rb @ 1345:1f9cdee56991

History | View | Annotate | Download (4.46 KB)

1
# 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, :is_external, :external_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
  def get_external_repo_url
76
    project = Project.find(params[:id])
77
    if project.repository
78
      repo = project.repository
79
      if repo.is_external?
80
        render :text => repo.external_url, :status => 200
81
      else
82
        render :nothing => true, :status => 200
83
      end
84
    end
85
  rescue ActiveRecord::RecordNotFound
86
    render :nothing => true, :status => 404
87
  end
88

    
89
  def clear_repository_cache
90
    project = Project.find(params[:id])
91
    if project.repository
92
      project.repository.clear_cache
93
    end
94
    render :nothing => true, :status => 200
95
  rescue ActiveRecord::RecordNotFound
96
    render :nothing => true, :status => 404
97
  end
98
  
99
  def set_embedded_active
100
    project = Project.find(params[:id])
101
    mods = project.enabled_modules
102
    enable = (params[:enable] == "1")
103
    if mods.detect {|m| m.name == "redmine_embedded"}
104
      logger.info "Project #{project.name} currently has Embedded enabled"
105
      if !enable
106
        logger.info "Disabling Embedded"
107
        modnames = mods.all(:select => :name).collect{|m| m.name}.reject{|n| n == "redmine_embedded"}
108
        project.enabled_module_names = modnames
109
      end
110
    else
111
      logger.info "Project #{project.name} currently has Embedded disabled"
112
      if enable
113
        logger.info "Enabling Embedded"
114
        modnames = mods.all(:select => :name).collect{|m| m.name}
115
        modnames << "redmine_embedded"
116
        project.enabled_module_names = modnames
117
      end
118
    end
119
    render :nothing => true, :status => 200
120
  rescue ActiveRecord::RecordNotFound
121
    render :nothing => true, :status => 404
122
  end
123

    
124
  protected
125

    
126
  def check_enabled
127
    User.current = nil
128
    unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
129
      render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
130
      return false
131
    end
132
  end
133
end