2013-06-23 12:47:22 -04:00
|
|
|
class Projects::DeployKeysController < Projects::ApplicationController
|
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!
|
2011-12-29 14:44:16 -05:00
|
|
|
|
2013-06-19 15:44:57 -04:00
|
|
|
layout "project_settings"
|
|
|
|
|
2011-12-29 14:44:16 -05:00
|
|
|
def index
|
2016-04-25 11:26:41 -04:00
|
|
|
@key = DeployKey.new
|
|
|
|
set_index_vars
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2016-08-05 05:35:44 -04:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 16:24:17 -04:00
|
|
|
@key = DeployKey.new(deploy_key_params)
|
2016-04-25 11:26:41 -04:00
|
|
|
set_index_vars
|
2013-05-06 08:10:55 -04:00
|
|
|
|
|
|
|
if @key.valid? && @project.deploy_keys << @key
|
2016-08-05 05:35:44 -04:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
|
2012-01-17 18:00:40 -05:00
|
|
|
else
|
2016-04-25 11:26:41 -04:00
|
|
|
render "index"
|
2012-01-17 18:00:40 -05:00
|
|
|
end
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
2013-05-06 08:10:55 -04:00
|
|
|
def enable
|
2016-08-08 14:32:10 -04:00
|
|
|
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2016-08-05 05:35:44 -04:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable
|
2015-03-17 09:55:43 -04:00
|
|
|
@project.deploy_keys_projects.find_by(deploy_key_id: params[:id]).destroy
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_default(default: { action: 'index' })
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2016-04-25 11:26:41 -04:00
|
|
|
def set_index_vars
|
2016-08-05 05:35:44 -04:00
|
|
|
@enabled_keys ||= @project.deploy_keys
|
2016-04-25 11:26:41 -04:00
|
|
|
|
2016-08-05 05:35:44 -04:00
|
|
|
@available_keys ||= current_user.accessible_deploy_keys - @enabled_keys
|
2016-04-25 11:26:41 -04:00
|
|
|
@available_project_keys ||= current_user.project_deploy_keys - @enabled_keys
|
|
|
|
@available_public_keys ||= DeployKey.are_public - @enabled_keys
|
|
|
|
|
|
|
|
# Public keys that are already used by another accessible project are already
|
|
|
|
# in @available_project_keys.
|
|
|
|
@available_public_keys -= @available_project_keys
|
|
|
|
end
|
|
|
|
|
2014-06-26 16:24:17 -04:00
|
|
|
def deploy_key_params
|
|
|
|
params.require(:deploy_key).permit(:key, :title)
|
|
|
|
end
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|