2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups
|
|
|
|
module Settings
|
|
|
|
class RepositoryController < Groups::ApplicationController
|
2021-03-16 14:11:53 -04:00
|
|
|
layout 'group_settings'
|
2020-04-21 11:21:10 -04:00
|
|
|
skip_cross_project_access_check :show
|
2022-08-18 05:11:27 -04:00
|
|
|
before_action :authorize_create_deploy_token!, only: :create_deploy_token
|
|
|
|
before_action :authorize_access!, only: :show
|
|
|
|
before_action :define_deploy_token_variables, if: -> { can?(current_user, :create_deploy_token, @group) }
|
2020-04-21 11:21:10 -04:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:ajax_new_deploy_token, @group)
|
|
|
|
end
|
|
|
|
|
2020-10-06 08:08:38 -04:00
|
|
|
feature_category :continuous_delivery
|
2022-04-29 08:10:13 -04:00
|
|
|
urgency :low
|
2020-10-06 08:08:38 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def create_deploy_token
|
|
|
|
result = Groups::DeployTokens::CreateService.new(@group, current_user, deploy_token_params).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
2022-08-26 17:10:03 -04:00
|
|
|
@created_deploy_token = result[:deploy_token]
|
2020-04-21 11:21:10 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
# IMPORTANT: It's a security risk to expose the token value more than just once here!
|
2022-08-26 17:10:03 -04:00
|
|
|
json = API::Entities::DeployTokenWithToken.represent(@created_deploy_token).as_json
|
2020-04-21 11:21:10 -04:00
|
|
|
render json: json, status: result[:http_status]
|
|
|
|
end
|
|
|
|
format.html do
|
|
|
|
flash.now[:notice] = s_('DeployTokens|Your new group deploy token has been created.')
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2022-08-26 17:10:03 -04:00
|
|
|
@new_deploy_token = result[:deploy_token]
|
2020-04-21 11:21:10 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-08-18 05:11:27 -04:00
|
|
|
def authorize_access!
|
|
|
|
authorize_admin_group!
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def define_deploy_token_variables
|
|
|
|
@deploy_tokens = @group.deploy_tokens.active
|
|
|
|
|
|
|
|
@new_deploy_token = DeployToken.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_token_params
|
2020-05-13 23:07:52 -04:00
|
|
|
params.require(:deploy_token).permit(:name, :expires_at, :read_repository, :read_registry, :write_registry, :read_package_registry, :write_package_registry, :username)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-08-18 05:11:27 -04:00
|
|
|
|
|
|
|
Groups::Settings::RepositoryController.prepend_mod
|