debian-mirror-gitlab/app/controllers/projects/deploy_keys_controller.rb
2017-08-17 22:00:37 +05:30

58 lines
1.4 KiB
Ruby

class Projects::DeployKeysController < Projects::ApplicationController
include RepositorySettingsRedirect
respond_to :html
# Authorize
before_action :authorize_admin_project!
layout "project_settings"
def index
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json do
render json: Projects::Settings::DeployKeysPresenter.new(@project, current_user: current_user).as_json
end
end
end
def new
redirect_to_repository_settings(@project)
end
def create
@key = DeployKey.new(deploy_key_params.merge(user: current_user))
unless @key.valid? && @project.deploy_keys << @key
flash[:alert] = @key.errors.full_messages.join(', ').html_safe
end
redirect_to_repository_settings(@project)
end
def enable
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
end
def disable
deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id])
return render_404 unless deploy_key_project
deploy_key_project.destroy!
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
end
protected
def deploy_key_params
params.require(:deploy_key).permit(:key, :title, :can_push)
end
end