2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::DeployKeysController < Projects::ApplicationController
|
2017-03-03 12:41:15 -05:00
|
|
|
include RepositorySettingsRedirect
|
2012-01-17 17:46:13 -05:00
|
|
|
respond_to :html
|
2011-12-29 16:46:18 -05:00
|
|
|
|
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_project!
|
2017-03-31 08:54:38 -04:00
|
|
|
before_action :authorize_update_deploy_key!, only: [:edit, :update]
|
2011-12-29 14:44:16 -05:00
|
|
|
|
2017-06-20 05:37:07 -04:00
|
|
|
layout 'project_settings'
|
2013-06-19 15:44:57 -04:00
|
|
|
|
2011-12-29 14:44:16 -05:00
|
|
|
def index
|
2017-03-24 06:11:36 -04:00
|
|
|
respond_to do |format|
|
2018-08-08 02:17:43 -04:00
|
|
|
format.html { redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings') }
|
2017-03-24 06:11:36 -04:00
|
|
|
format.json do
|
|
|
|
render json: Projects::Settings::DeployKeysPresenter.new(@project, current_user: current_user).as_json
|
|
|
|
end
|
|
|
|
end
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2018-08-08 02:17:43 -04:00
|
|
|
redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings')
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2018-12-18 11:40:05 -05:00
|
|
|
@key = DeployKeys::CreateService.new(current_user, create_params).execute(project: @project)
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2018-01-05 10:23:44 -05:00
|
|
|
unless @key.valid?
|
2017-03-24 06:11:36 -04:00
|
|
|
flash[:alert] = @key.errors.full_messages.join(', ').html_safe
|
2012-01-17 18:00:40 -05:00
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2018-08-08 02:17:43 -04:00
|
|
|
redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings')
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-07-02 06:43:06 -04:00
|
|
|
if deploy_key.update(update_params)
|
2017-03-31 08:54:38 -04:00
|
|
|
flash[:notice] = 'Deploy key was successfully updated.'
|
2018-08-08 02:17:43 -04:00
|
|
|
redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings')
|
2017-03-31 08:54:38 -04:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 08:10:55 -04:00
|
|
|
def enable
|
2018-11-17 00:59:17 -05:00
|
|
|
key = Projects::EnableDeployKeyService.new(@project, current_user, params).execute
|
|
|
|
|
|
|
|
return render_404 unless key
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2017-04-28 12:06:19 -04:00
|
|
|
respond_to do |format|
|
2018-08-08 02:17:43 -04:00
|
|
|
format.html { redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings') }
|
2017-04-28 12:06:19 -04:00
|
|
|
format.json { head :ok }
|
|
|
|
end
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable
|
2018-11-17 00:59:17 -05:00
|
|
|
deploy_key_project = Projects::DisableDeployKeyService.new(@project, current_user, params).execute
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2018-11-17 00:59:17 -05:00
|
|
|
return render_404 unless deploy_key_project
|
2017-04-28 12:06:19 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2018-08-08 02:17:43 -04:00
|
|
|
format.html { redirect_to_repository_settings(@project, anchor: 'js-deploy-keys-settings') }
|
2017-04-28 12:06:19 -04:00
|
|
|
format.json { head :ok }
|
|
|
|
end
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
def deploy_key
|
2017-06-20 05:37:07 -04:00
|
|
|
@deploy_key ||= DeployKey.find(params[:id])
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_params
|
2018-01-05 10:23:44 -05:00
|
|
|
create_params = params.require(:deploy_key)
|
|
|
|
.permit(:key, :title, deploy_keys_projects_attributes: [:can_push])
|
|
|
|
create_params.dig(:deploy_keys_projects_attributes, '0')&.merge!(project_id: @project.id)
|
|
|
|
create_params
|
2014-06-26 16:24:17 -04:00
|
|
|
end
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
def update_params
|
2018-01-05 10:23:44 -05:00
|
|
|
params.require(:deploy_key).permit(:title, deploy_keys_projects_attributes: [:id, :can_push])
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_update_deploy_key!
|
|
|
|
access_denied! unless can?(current_user, :update_deploy_key, deploy_key)
|
|
|
|
end
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|