2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-19 11:48:53 -05:00
|
|
|
module Projects
|
|
|
|
module Settings
|
|
|
|
class RepositoryController < Projects::ApplicationController
|
2017-01-23 19:28:40 -05:00
|
|
|
before_action :authorize_admin_project!
|
2018-05-03 08:55:14 -04:00
|
|
|
before_action :remote_mirror, only: [:show]
|
2017-01-23 19:28:40 -05:00
|
|
|
|
2017-01-19 11:48:53 -05:00
|
|
|
def show
|
2018-04-05 18:07:36 -04:00
|
|
|
render_show
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_deploy_token
|
|
|
|
@new_deploy_token = DeployTokens::CreateService.new(@project, current_user, deploy_token_params).execute
|
|
|
|
|
2018-04-05 21:04:11 -04:00
|
|
|
if @new_deploy_token.persisted?
|
2018-10-05 10:01:04 -04:00
|
|
|
flash.now[:notice] = s_('DeployTokens|Your new project deploy token has been created.')
|
2018-04-05 18:07:36 -04:00
|
|
|
end
|
|
|
|
|
2018-10-05 10:01:04 -04:00
|
|
|
render_show
|
2018-04-05 18:07:36 -04:00
|
|
|
end
|
|
|
|
|
2018-11-19 10:03:58 -05:00
|
|
|
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
|
|
|
|
RepositoryCleanupWorker.perform_async(project.id, current_user.id)
|
|
|
|
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
|
|
|
|
|
2018-04-05 18:07:36 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def render_show
|
2017-04-03 12:10:58 -04:00
|
|
|
@deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user)
|
2018-04-06 11:22:08 -04:00
|
|
|
@deploy_tokens = @project.deploy_tokens.active
|
2017-01-31 09:12:02 -05:00
|
|
|
|
2018-03-19 12:11:12 -04:00
|
|
|
define_deploy_token
|
2017-03-17 15:55:15 -04:00
|
|
|
define_protected_refs
|
2018-05-03 08:55:14 -04:00
|
|
|
remote_mirror
|
2017-01-23 19:28:40 -05:00
|
|
|
|
2018-04-05 18:07:36 -04:00
|
|
|
render 'show'
|
|
|
|
end
|
2017-01-23 19:28:40 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-03-17 15:55:15 -04:00
|
|
|
def define_protected_refs
|
|
|
|
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
|
2017-04-03 22:37:22 -04:00
|
|
|
@protected_tags = @project.protected_tags.order(:name).page(params[:page])
|
2017-01-23 19:28:40 -05:00
|
|
|
@protected_branch = @project.protected_branches.new
|
2017-03-17 15:55:15 -04:00
|
|
|
@protected_tag = @project.protected_tags.new
|
2018-04-04 06:37:44 -04:00
|
|
|
|
|
|
|
@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-02-10 12:27:43 -05:00
|
|
|
load_gon_index
|
2017-01-19 11:48:53 -05:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-02-21 16:37:00 -05:00
|
|
|
|
2018-05-03 08:55:14 -04:00
|
|
|
def remote_mirror
|
|
|
|
@remote_mirror = project.remote_mirrors.first_or_initialize
|
|
|
|
end
|
|
|
|
|
2017-02-28 12:49:32 -05:00
|
|
|
def access_levels_options
|
|
|
|
{
|
2017-11-24 07:43:02 -05:00
|
|
|
create_access_levels: levels_for_dropdown,
|
|
|
|
push_access_levels: levels_for_dropdown,
|
|
|
|
merge_access_levels: levels_for_dropdown
|
2017-02-28 12:49:32 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-11-24 07:43:02 -05:00
|
|
|
def levels_for_dropdown
|
|
|
|
roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.map do |id, text|
|
2017-04-03 21:59:37 -04:00
|
|
|
{ id: id, text: text, before_divider: true }
|
|
|
|
end
|
|
|
|
{ roles: roles }
|
|
|
|
end
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
def protectable_tags_for_dropdown
|
|
|
|
{ open_tags: ProtectableDropdown.new(@project, :tags).hash }
|
2017-03-17 15:55:15 -04:00
|
|
|
end
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
def protectable_branches_for_dropdown
|
|
|
|
{ open_branches: ProtectableDropdown.new(@project, :branches).hash }
|
2017-03-01 11:15:46 -05:00
|
|
|
end
|
|
|
|
|
2017-02-28 12:49:32 -05:00
|
|
|
def load_gon_index
|
2017-04-03 12:10:58 -04:00
|
|
|
gon.push(protectable_tags_for_dropdown)
|
|
|
|
gon.push(protectable_branches_for_dropdown)
|
2017-03-17 15:55:15 -04:00
|
|
|
gon.push(access_levels_options)
|
2017-02-28 12:49:32 -05:00
|
|
|
end
|
2018-03-19 12:11:12 -04:00
|
|
|
|
|
|
|
def define_deploy_token
|
2018-04-05 18:07:36 -04:00
|
|
|
@new_deploy_token ||= DeployToken.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_token_params
|
2019-07-02 14:56:48 -04:00
|
|
|
params.require(:deploy_token).permit(:name, :expires_at, :read_repository, :read_registry, :username)
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
2017-01-19 11:48:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Projects::Settings::RepositoryController.prepend_if_ee('EE::Projects::Settings::RepositoryController')
|