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 @ 1034:ea5d9652c6f6

History | View | Annotate | Download (4.05 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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(:all, :include => :repository, :order => 'identifier')
23
    # 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, :is_external, :external_url]}})
25
  end
26

    
27
  def create_project_repository
28
    project = Project.find(params[:id])
29
    if project.repository
30
      render :nothing => true, :status => 409
31
    else
32
      logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
33
      project.repository = Repository.factory(params[:vendor], params[:repository])
34
      if project.repository && project.repository.save
35
        render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201
36
      else
37
        render :nothing => true, :status => 422
38
      end
39
    end
40
  end
41

    
42
  def fetch_changesets
43
    projects = []
44
    if params[:id]
45
      projects << Project.active.has_module(:repository).find(params[:id])
46
    else
47
      projects = Project.active.has_module(:repository).find(:all, :include => :repository)
48
    end
49
    projects.each do |project|
50
      if project.repository
51
        project.repository.fetch_changesets
52
      end
53
    end
54
    render :nothing => true, :status => 200
55
  rescue ActiveRecord::RecordNotFound
56
    render :nothing => true, :status => 404
57
  end
58

    
59
  def get_external_repo_url
60
    project = Project.find(params[:id])
61
    if project.repository
62
      repo = project.repository
63
      if repo.is_external?
64
        render :text => repo.external_url, :status => 200
65
      else
66
        render :nothing => true, :status => 200
67
      end
68
    end
69
  rescue ActiveRecord::RecordNotFound
70
    render :nothing => true, :status => 404
71
  end
72

    
73
  def clear_repository_cache
74
    project = Project.find(params[:id])
75
    if project.repository
76
      project.repository.clear_cache
77
    end
78
    render :nothing => true, :status => 200
79
  rescue ActiveRecord::RecordNotFound
80
    render :nothing => true, :status => 404
81
  end
82
  
83
  def set_embedded_active
84
    project = Project.find(params[:id])
85
    mods = project.enabled_modules
86
    enable = (params[:enable] == "1")
87
    if mods.detect {|m| m.name == "embedded"}
88
      logger.info "Project #{project.name} currently has Embedded enabled"
89
      if !enable
90
        logger.info "Disabling Embedded"
91
        modnames = mods.all(:select => :name).collect{|m| m.name}.reject{|n| n == "embedded"}
92
        project.enabled_module_names = modnames
93
      end
94
    else
95
      logger.info "Project #{project.name} currently has Embedded disabled"
96
      if enable
97
        logger.info "Enabling Embedded"
98
        modnames = mods.all(:select => :name).collect{|m| m.name}
99
        modnames << "embedded"
100
        project.enabled_module_names = modnames
101
      end
102
    end
103
    render :nothing => true, :status => 200
104
  rescue ActiveRecord::RecordNotFound
105
    render :nothing => true, :status => 404
106
  end
107

    
108
  protected
109

    
110
  def check_enabled
111
    User.current = nil
112
    unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
113
      render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
114
      return false
115
    end
116
  end
117
end