2009-02-10 23:03:25 +01:00
|
|
|
# Redmine - project management software
|
2013-01-12 10:29:31 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2007-04-01 21:43:59 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-25 06:39:33 +02:00
|
|
|
#
|
2007-04-01 21:43:59 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-25 06:39:33 +02:00
|
|
|
#
|
2007-04-01 21:43:59 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class SysController < ActionController::Base
|
2009-02-10 23:03:25 +01:00
|
|
|
before_filter :check_enabled
|
2011-05-25 06:39:33 +02:00
|
|
|
|
2009-02-10 23:03:25 +01:00
|
|
|
def projects
|
2012-02-03 00:26:54 +01:00
|
|
|
p = Project.active.has_module(:repository).find(
|
|
|
|
:all,
|
|
|
|
:include => :repository,
|
|
|
|
:order => "#{Project.table_name}.identifier"
|
|
|
|
)
|
2011-11-27 18:30:28 +01:00
|
|
|
# extra_info attribute from repository breaks activeresource client
|
2012-02-03 00:26:54 +01:00
|
|
|
render :xml => p.to_xml(
|
|
|
|
:only => [:id, :identifier, :name, :is_public, :status],
|
|
|
|
:include => {:repository => {:only => [:id, :url]}}
|
|
|
|
)
|
2007-04-01 21:43:59 +02:00
|
|
|
end
|
2011-05-25 06:39:33 +02:00
|
|
|
|
2009-02-10 23:03:25 +01:00
|
|
|
def create_project_repository
|
|
|
|
project = Project.find(params[:id])
|
|
|
|
if project.repository
|
|
|
|
render :nothing => true, :status => 409
|
|
|
|
else
|
|
|
|
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
2012-02-25 14:04:34 +01:00
|
|
|
repository = Repository.factory(params[:vendor], params[:repository])
|
|
|
|
repository.project = project
|
|
|
|
if repository.save
|
|
|
|
render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
|
2009-02-10 23:03:25 +01:00
|
|
|
else
|
|
|
|
render :nothing => true, :status => 422
|
|
|
|
end
|
|
|
|
end
|
2007-04-01 21:43:59 +02:00
|
|
|
end
|
2011-05-25 06:39:33 +02:00
|
|
|
|
2009-11-28 17:50:26 +01:00
|
|
|
def fetch_changesets
|
|
|
|
projects = []
|
2012-02-25 13:57:30 +01:00
|
|
|
scope = Project.active.has_module(:repository)
|
2009-11-28 17:50:26 +01:00
|
|
|
if params[:id]
|
2012-02-25 13:57:30 +01:00
|
|
|
project = nil
|
|
|
|
if params[:id].to_s =~ /^\d*$/
|
|
|
|
project = scope.find(params[:id])
|
|
|
|
else
|
|
|
|
project = scope.find_by_identifier(params[:id])
|
|
|
|
end
|
|
|
|
raise ActiveRecord::RecordNotFound unless project
|
|
|
|
projects << project
|
2009-11-28 17:50:26 +01:00
|
|
|
else
|
2012-02-25 13:57:30 +01:00
|
|
|
projects = scope.all
|
2009-11-28 17:50:26 +01:00
|
|
|
end
|
|
|
|
projects.each do |project|
|
2012-01-15 19:19:19 +01:00
|
|
|
project.repositories.each do |repository|
|
|
|
|
repository.fetch_changesets
|
2009-11-28 17:50:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render :nothing => true, :status => 404
|
|
|
|
end
|
2007-04-01 21:43:59 +02:00
|
|
|
|
2009-02-10 23:03:25 +01:00
|
|
|
protected
|
2007-04-01 21:43:59 +02:00
|
|
|
|
2009-02-10 23:03:25 +01:00
|
|
|
def check_enabled
|
|
|
|
User.current = nil
|
2009-12-20 10:44:28 +01:00
|
|
|
unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
|
|
|
|
render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
|
2009-02-10 23:03:25 +01:00
|
|
|
return false
|
|
|
|
end
|
2007-04-01 21:43:59 +02:00
|
|
|
end
|
|
|
|
end
|