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
|
2021-04-29 21:17:54 +05:30
|
|
|
layout 'project_settings'
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :authorize_admin_project!
|
2020-04-25 10:58:03 +05:30
|
|
|
before_action :define_variables, only: [:create_deploy_token]
|
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:ajax_new_deploy_token, @project)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :source_code_management, [:show, :cleanup]
|
|
|
|
feature_category :continuous_delivery, [:create_deploy_token]
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low, [:show, :create_deploy_token]
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def show
|
2022-07-23 23:45:48 +05:30
|
|
|
push_frontend_feature_flag(:branch_rules, @project)
|
2018-05-09 12:01:36 +05:30
|
|
|
render_show
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def cleanup
|
2021-01-29 00:20:46 +05:30
|
|
|
bfg_object_map = params.require(:project).require(:bfg_object_map)
|
|
|
|
result = Projects::CleanupService.enqueue(project, current_user, bfg_object_map)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] = _('Repository cleanup has started. You will receive an email once the cleanup operation is complete.')
|
|
|
|
else
|
2022-04-04 11:22:00 +05:30
|
|
|
flash[:alert] = result.fetch(:message, _('Failed to upload object map file'))
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
2020-04-25 10:58:03 +05:30
|
|
|
def create_deploy_token
|
|
|
|
result = Projects::DeployTokens::CreateService.new(@project, current_user, deploy_token_params).execute
|
|
|
|
@new_deploy_token = result[:deploy_token]
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
# IMPORTANT: It's a security risk to expose the token value more than just once here!
|
|
|
|
json = API::Entities::DeployTokenWithToken.represent(@new_deploy_token).as_json
|
|
|
|
render json: json, status: result[:http_status]
|
|
|
|
end
|
|
|
|
format.html do
|
|
|
|
flash.now[:notice] = s_('DeployTokens|Your new project deploy token has been created.')
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: { message: result[:message] }, status: result[:http_status] }
|
|
|
|
format.html do
|
|
|
|
flash.now[:alert] = result[:message]
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def render_show
|
2020-04-25 10:58:03 +05:30
|
|
|
define_variables
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
|
2020-04-25 10:58:03 +05:30
|
|
|
def define_variables
|
2020-05-05 14:28:15 +05:30
|
|
|
@deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user)
|
|
|
|
|
2020-04-25 10:58:03 +05:30
|
|
|
define_deploy_token_variables
|
|
|
|
define_protected_refs
|
|
|
|
remote_mirror
|
|
|
|
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
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
@protected_tags_count = @protected_tags.reduce(0) { |sum, tag| sum + tag.matching(@project.repository.tag_names).size }
|
2018-05-09 12:01:36 +05:30
|
|
|
|
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
|
|
|
|
|
2020-04-25 10:58:03 +05:30
|
|
|
def deploy_token_params
|
2020-05-24 23:13:21 +05:30
|
|
|
params.require(:deploy_token).permit(:name, :expires_at, :read_repository, :read_registry, :write_registry, :read_package_registry, :write_package_registry, :username)
|
2020-04-25 10:58:03 +05:30
|
|
|
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
|
|
|
|
|
2020-04-25 10:58:03 +05:30
|
|
|
def define_deploy_token_variables
|
|
|
|
@deploy_tokens = @project.deploy_tokens.active
|
|
|
|
|
|
|
|
@new_deploy_token ||= DeployToken.new
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def load_gon_index
|
|
|
|
gon.push(protectable_tags_for_dropdown)
|
|
|
|
gon.push(protectable_branches_for_dropdown)
|
|
|
|
gon.push(access_levels_options)
|
2021-01-03 14:25:43 +05:30
|
|
|
gon.push(current_project_id: project.id) if project
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Projects::Settings::RepositoryController.prepend_mod_with('Projects::Settings::RepositoryController')
|