gitlab-org--gitlab-foss/app/controllers/projects/deploy_keys_controller.rb

84 lines
2 KiB
Ruby
Raw Normal View History

class Projects::DeployKeysController < Projects::ApplicationController
include RepositorySettingsRedirect
2012-01-17 17:46:13 -05:00
respond_to :html
# Authorize
before_action :authorize_admin_project!
before_action :authorize_update_deploy_key!, only: [:edit, :update]
2011-12-29 14:44:16 -05:00
layout 'project_settings'
2013-06-19 15:44:57 -04:00
2011-12-29 14:44:16 -05:00
def index
2017-03-24 06:11:36 -04:00
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
2011-12-29 14:44:16 -05:00
end
def new
redirect_to_repository_settings(@project)
2011-12-29 14:44:16 -05:00
end
def create
@key = DeployKey.new(create_params.merge(user: current_user))
2013-05-06 08:10:55 -04:00
unless @key.valid? && @project.deploy_keys << @key
2017-03-24 06:11:36 -04:00
flash[:alert] = @key.errors.full_messages.join(', ').html_safe
2012-01-17 18:00:40 -05:00
end
redirect_to_repository_settings(@project)
2011-12-29 14:44:16 -05:00
end
def edit
end
def update
if deploy_key.update_attributes(update_params)
flash[:notice] = 'Deploy key was successfully updated.'
redirect_to_repository_settings(@project)
else
render 'edit'
end
end
2013-05-06 08:10:55 -04:00
def enable
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
2013-05-06 08:10:55 -04:00
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
2013-05-06 08:10:55 -04:00
end
def disable
deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id])
return render_404 unless deploy_key_project
2013-05-06 08:10:55 -04:00
deploy_key_project.destroy!
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
2013-05-06 08:10:55 -04:00
end
protected
def deploy_key
@deploy_key ||= DeployKey.find(params[:id])
end
def create_params
params.require(:deploy_key).permit(:key, :title, :can_push)
end
def update_params
params.require(:deploy_key).permit(:title, :can_push)
end
def authorize_update_deploy_key!
access_denied! unless can?(current_user, :update_deploy_key, deploy_key)
end
2011-12-29 14:44:16 -05:00
end