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

62 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
@enabled_keys = @project.deploy_keys
2015-04-26 12:48:37 +05:30
@available_keys = accessible_keys - @enabled_keys
@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
2014-09-02 18:07:02 +05:30
end
def new
@key = @project.deploy_keys.new
respond_with(@key)
end
def create
@key = DeployKey.new(deploy_key_params)
if @key.valid? && @project.deploy_keys << @key
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_deploy_keys_path(@project.namespace,
@project)
2014-09-02 18:07:02 +05:30
else
render "new"
end
end
def enable
2015-04-26 12:48:37 +05:30
@key = accessible_keys.find(params[:id])
@project.deploy_keys << @key
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +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
2015-04-26 12:48:37 +05:30
def accessible_keys
@accessible_keys ||= current_user.accessible_deploy_keys
2014-09-02 18:07:02 +05:30
end
def deploy_key_params
params.require(:deploy_key).permit(:key, :title)
end
end