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
|
|
|
|
before_filter :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
|
2013-12-14 08:43:48 -05:00
|
|
|
@enabled_keys = @project.deploy_keys
|
2013-05-06 08:10:55 -04:00
|
|
|
@available_keys = available_keys - @enabled_keys
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2011-12-31 12:37:14 -05:00
|
|
|
@key = @project.deploy_keys.find(params[:id])
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2011-12-31 12:37:14 -05:00
|
|
|
@key = @project.deploy_keys.new
|
2011-12-29 14:44:16 -05:00
|
|
|
|
|
|
|
respond_with(@key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 16:24:17 -04:00
|
|
|
@key = DeployKey.new(deploy_key_params)
|
2013-05-06 08:10:55 -04:00
|
|
|
|
|
|
|
if @key.valid? && @project.deploy_keys << @key
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace,
|
|
|
|
@project)
|
2012-01-17 18:00:40 -05:00
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-12-31 12:37:14 -05:00
|
|
|
@key = @project.deploy_keys.find(params[:id])
|
2011-12-29 14:44:16 -05:00
|
|
|
@key.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2011-12-29 16:31:27 -05:00
|
|
|
format.html { redirect_to project_deploy_keys_url }
|
2012-08-10 18:07:50 -04:00
|
|
|
format.js { render nothing: true }
|
2011-12-29 14:44:16 -05:00
|
|
|
end
|
|
|
|
end
|
2013-05-06 08:10:55 -04:00
|
|
|
|
|
|
|
def enable
|
2014-10-19 17:20:55 -04:00
|
|
|
@project.deploy_keys << available_keys.find(params[:id])
|
2013-05-06 08:10:55 -04:00
|
|
|
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace,
|
|
|
|
@project)
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable
|
|
|
|
@project.deploy_keys_projects.where(deploy_key_id: params[:id]).last.destroy
|
|
|
|
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_deploy_keys_path(@project.namespace,
|
|
|
|
@project)
|
2013-05-06 08:10:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def available_keys
|
2013-06-04 10:50:51 -04:00
|
|
|
@available_keys ||= current_user.accessible_deploy_keys
|
2013-05-06 08:10:55 -04:00
|
|
|
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
|