2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Projects
|
|
|
|
module Settings
|
|
|
|
class RepositoryController < Projects::ApplicationController
|
|
|
|
before_action :authorize_admin_project!
|
2018-10-15 14:42:47 +05:30
|
|
|
before_action :remote_mirror, only: [:show]
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def show
|
2018-05-09 12:01:36 +05:30
|
|
|
render_show
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def create_deploy_token
|
|
|
|
@new_deploy_token = DeployTokens::CreateService.new(@project, current_user, deploy_token_params).execute
|
|
|
|
|
|
|
|
if @new_deploy_token.persisted?
|
|
|
|
flash.now[:notice] = s_('DeployTokens|Your new project deploy token has been created.')
|
|
|
|
end
|
|
|
|
|
|
|
|
render_show
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def cleanup
|
|
|
|
cleanup_params = params.require(:project).permit(:bfg_object_map)
|
|
|
|
result = Projects::UpdateService.new(project, current_user, cleanup_params).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
2020-03-13 15:44:24 +05:30
|
|
|
RepositoryCleanupWorker.perform_async(project.id, current_user.id) # rubocop:disable CodeReuse/Worker
|
2019-02-15 15:39:39 +05:30
|
|
|
flash[:notice] = _('Repository cleanup has started. You will receive an email once the cleanup operation is complete.')
|
|
|
|
else
|
|
|
|
flash[:alert] = _('Failed to upload object map file')
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def render_show
|
|
|
|
@deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user)
|
|
|
|
@deploy_tokens = @project.deploy_tokens.active
|
|
|
|
|
|
|
|
define_deploy_token
|
|
|
|
define_protected_refs
|
2018-10-15 14:42:47 +05:30
|
|
|
remote_mirror
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def define_protected_refs
|
|
|
|
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
|
|
|
|
@protected_tags = @project.protected_tags.order(:name).page(params[:page])
|
|
|
|
@protected_branch = @project.protected_branches.new
|
|
|
|
@protected_tag = @project.protected_tags.new
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
@protected_branches_count = @protected_branches.reduce(0) { |sum, branch| sum + branch.matching(@project.repository.branches).size }
|
|
|
|
@protected_tags_count = @protected_tags.reduce(0) { |sum, tag| sum + tag.matching(@project.repository.tags).size }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
load_gon_index
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def remote_mirror
|
|
|
|
@remote_mirror = project.remote_mirrors.first_or_initialize
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def access_levels_options
|
|
|
|
{
|
2018-03-17 18:26:18 +05:30
|
|
|
create_access_levels: levels_for_dropdown,
|
|
|
|
push_access_levels: levels_for_dropdown,
|
|
|
|
merge_access_levels: levels_for_dropdown
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def levels_for_dropdown
|
|
|
|
roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.map do |id, text|
|
2017-08-17 22:00:37 +05:30
|
|
|
{ id: id, text: text, before_divider: true }
|
|
|
|
end
|
|
|
|
{ roles: roles }
|
|
|
|
end
|
|
|
|
|
|
|
|
def protectable_tags_for_dropdown
|
|
|
|
{ open_tags: ProtectableDropdown.new(@project, :tags).hash }
|
|
|
|
end
|
|
|
|
|
|
|
|
def protectable_branches_for_dropdown
|
|
|
|
{ open_branches: ProtectableDropdown.new(@project, :branches).hash }
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_gon_index
|
|
|
|
gon.push(protectable_tags_for_dropdown)
|
|
|
|
gon.push(protectable_branches_for_dropdown)
|
|
|
|
gon.push(access_levels_options)
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
def define_deploy_token
|
|
|
|
@new_deploy_token ||= DeployToken.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_token_params
|
2019-09-30 21:07:59 +05:30
|
|
|
params.require(:deploy_token).permit(:name, :expires_at, :read_repository, :read_registry, :username)
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Projects::Settings::RepositoryController.prepend_if_ee('EE::Projects::Settings::RepositoryController')
|