2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2009-02-10 22:03:25 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2007-04-01 19:43:59 +00: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 04:39:33 +00:00
|
|
|
#
|
2007-04-01 19:43:59 +00: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 04:39:33 +00:00
|
|
|
#
|
2007-04-01 19:43:59 +00: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
|
2021-03-26 05:08:03 +00:00
|
|
|
include ActiveSupport::SecurityUtils
|
|
|
|
|
|
2016-07-14 07:27:31 +00:00
|
|
|
before_action :check_enabled
|
2011-05-25 04:39:33 +00:00
|
|
|
|
2022-08-10 01:34:37 +00:00
|
|
|
# Requests from repository WS clients don't contain CSRF tokens
|
|
|
|
|
skip_before_action :verify_authenticity_token
|
|
|
|
|
|
2009-02-10 22:03:25 +00:00
|
|
|
def projects
|
2014-10-22 17:37:16 +00:00
|
|
|
p = Project.active.has_module(:repository).
|
|
|
|
|
order("#{Project.table_name}.identifier").preload(:repository).to_a
|
2011-11-27 17:30:28 +00:00
|
|
|
# extra_info attribute from repository breaks activeresource client
|
2020-09-26 15:02:26 +00:00
|
|
|
render :json =>
|
|
|
|
|
p.to_json(:only => [:id, :identifier, :name, :is_public, :status],
|
|
|
|
|
:include => {:repository => {:only => [:id, :url]}})
|
2007-04-01 19:43:59 +00:00
|
|
|
end
|
2011-05-25 04:39:33 +00:00
|
|
|
|
2009-02-10 22:03:25 +00:00
|
|
|
def create_project_repository
|
|
|
|
|
project = Project.find(params[:id])
|
|
|
|
|
if project.repository
|
2024-05-18 05:56:55 +00:00
|
|
|
head :conflict
|
2009-02-10 22:03:25 +00:00
|
|
|
else
|
|
|
|
|
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
2017-06-01 20:09:08 +00:00
|
|
|
repository = Repository.factory(params[:vendor])
|
|
|
|
|
repository.safe_attributes = params[:repository]
|
2012-02-25 13:04:34 +00:00
|
|
|
repository.project = project
|
|
|
|
|
if repository.save
|
2024-05-18 05:56:55 +00:00
|
|
|
render :json => {repository.class.name.underscore.tr('/', '-') => {:id => repository.id, :url => repository.url}}, :status => :created
|
2009-02-10 22:03:25 +00:00
|
|
|
else
|
2024-06-12 16:09:37 +00:00
|
|
|
head :unprocessable_content
|
2009-02-10 22:03:25 +00:00
|
|
|
end
|
|
|
|
|
end
|
2007-04-01 19:43:59 +00:00
|
|
|
end
|
2011-05-25 04:39:33 +00:00
|
|
|
|
2009-11-28 16:50:26 +00:00
|
|
|
def fetch_changesets
|
|
|
|
|
projects = []
|
2012-02-25 12:57:30 +00:00
|
|
|
scope = Project.active.has_module(:repository)
|
2009-11-28 16:50:26 +00:00
|
|
|
if params[:id]
|
2012-02-25 12:57:30 +00:00
|
|
|
project = nil
|
2019-03-27 02:15:24 +00:00
|
|
|
if /^\d*$/.match?(params[:id].to_s)
|
2012-02-25 12:57:30 +00:00
|
|
|
project = scope.find(params[:id])
|
|
|
|
|
else
|
|
|
|
|
project = scope.find_by_identifier(params[:id])
|
|
|
|
|
end
|
|
|
|
|
raise ActiveRecord::RecordNotFound unless project
|
2020-11-05 13:41:52 +00:00
|
|
|
|
2012-02-25 12:57:30 +00:00
|
|
|
projects << project
|
2009-11-28 16:50:26 +00:00
|
|
|
else
|
2014-10-22 17:37:16 +00:00
|
|
|
projects = scope.to_a
|
2009-11-28 16:50:26 +00:00
|
|
|
end
|
|
|
|
|
projects.each do |project|
|
2012-01-15 18:19:19 +00:00
|
|
|
project.repositories.each do |repository|
|
|
|
|
|
repository.fetch_changesets
|
2009-11-28 16:50:26 +00:00
|
|
|
end
|
|
|
|
|
end
|
2024-05-18 05:56:55 +00:00
|
|
|
head :ok
|
2009-11-28 16:50:26 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2024-05-18 05:56:55 +00:00
|
|
|
head :not_found
|
2009-11-28 16:50:26 +00:00
|
|
|
end
|
2007-04-01 19:43:59 +00:00
|
|
|
|
2009-02-10 22:03:25 +00:00
|
|
|
protected
|
2007-04-01 19:43:59 +00:00
|
|
|
|
2009-02-10 22:03:25 +00:00
|
|
|
def check_enabled
|
|
|
|
|
User.current = nil
|
2021-03-26 05:08:03 +00:00
|
|
|
unless Setting.sys_api_enabled? && secure_compare(params[:key].to_s, Setting.sys_api_key.to_s)
|
2024-05-18 05:56:55 +00:00
|
|
|
render :plain => 'Access denied. Repository management WS is disabled or key is invalid.', :status => :forbidden
|
2009-02-10 22:03:25 +00:00
|
|
|
return false
|
|
|
|
|
end
|
2007-04-01 19:43:59 +00:00
|
|
|
end
|
|
|
|
|
end
|