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 @ 1592:72d9219f2f19

History | View | Annotate | Download (4.37 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2014  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).order("#{Project.table_name}.identifier").preload(:repository).all
23
    # extra_info attribute from repository breaks activeresource client
24
    render :xml => p.to_xml(
25
                       :only => [:id, :identifier, :name, :is_public, :status],
26
                       :include => {:repository => {:only => [:id, :url, :is_external, :external_url]}}
27
                     )
28
  end
29

    
30
  def create_project_repository
31
    project = Project.find(params[:id])
32
    if project.repository
33
      render :nothing => true, :status => 409
34
    else
35
      logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
36
      repository = Repository.factory(params[:vendor], params[:repository])
37
      repository.project = project
38
      if repository.save
39
        render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
40
      else
41
        render :nothing => true, :status => 422
42
      end
43
    end
44
  end
45

    
46
  def fetch_changesets
47
    projects = []
48
    scope = Project.active.has_module(:repository)
49
    if params[:id]
50
      project = nil
51
      if params[:id].to_s =~ /^\d*$/
52
        project = scope.find(params[:id])
53
      else
54
        project = scope.find_by_identifier(params[:id])
55
      end
56
      raise ActiveRecord::RecordNotFound unless project
57
      projects << project
58
    else
59
      projects = scope.all
60
    end
61
    projects.each do |project|
62
      project.repositories.each do |repository|
63
        repository.fetch_changesets
64
      end
65
    end
66
    render :nothing => true, :status => 200
67
  rescue ActiveRecord::RecordNotFound
68
    render :nothing => true, :status => 404
69
  end
70

    
71
  def get_external_repo_url
72
    project = Project.find(params[:id])
73
    if project.repository
74
      repo = project.repository
75
      if repo.is_external?
76
        render :text => repo.external_url, :status => 200
77
      else
78
        render :nothing => true, :status => 200
79
      end
80
    end
81
  rescue ActiveRecord::RecordNotFound
82
    render :nothing => true, :status => 404
83
  end
84

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

    
120
  protected
121

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