debian-mirror-gitlab/app/controllers/projects/deploy_keys_controller.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::DeployKeysController < Projects::ApplicationController
respond_to :html
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!
2014-09-02 18:07:02 +05:30
layout "project_settings"
def index
2016-06-02 11:05:42 +05:30
@key = DeployKey.new
set_index_vars
2014-09-02 18:07:02 +05:30
end
def new
2016-09-13 17:45:13 +05:30
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
end
def create
@key = DeployKey.new(deploy_key_params)
2016-06-02 11:05:42 +05:30
set_index_vars
2014-09-02 18:07:02 +05:30
if @key.valid? && @project.deploy_keys << @key
2016-09-13 17:45:13 +05:30
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
else
2016-06-02 11:05:42 +05:30
render "index"
2014-09-02 18:07:02 +05:30
end
end
def enable
2016-09-13 17:45:13 +05:30
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
2014-09-02 18:07:02 +05:30
2016-09-13 17:45:13 +05:30
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
end
def disable
2015-04-26 12:48:37 +05:30
@project.deploy_keys_projects.find_by(deploy_key_id: params[:id]).destroy
2014-09-02 18:07:02 +05:30
2015-10-24 18:46:33 +05:30
redirect_back_or_default(default: { action: 'index' })
2014-09-02 18:07:02 +05:30
end
protected
2016-06-02 11:05:42 +05:30
def set_index_vars
2016-09-13 17:45:13 +05:30
@enabled_keys ||= @project.deploy_keys
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
@available_keys ||= current_user.accessible_deploy_keys - @enabled_keys
2016-06-02 11:05:42 +05:30
@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-09-02 18:07:02 +05:30
def deploy_key_params
params.require(:deploy_key).permit(:key, :title)
end
end