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

88 lines
2.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::DeployKeysController < Projects::ApplicationController
2017-08-17 22:00:37 +05:30
include RepositorySettingsRedirect
2014-09-02 18:07:02 +05:30
respond_to :html
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!
2017-09-10 17:25:29 +05:30
before_action :authorize_update_deploy_key!, only: [:edit, :update]
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
layout 'project_settings'
2014-09-02 18:07:02 +05:30
def index
2017-08-17 22:00:37 +05:30
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
2014-09-02 18:07:02 +05:30
end
def new
2017-08-17 22:00:37 +05:30
redirect_to_repository_settings(@project)
2014-09-02 18:07:02 +05:30
end
def create
2018-03-17 18:26:18 +05:30
@key = DeployKeys::CreateService.new(current_user, create_params).execute
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
unless @key.valid?
2017-08-17 22:00:37 +05:30
flash[:alert] = @key.errors.full_messages.join(', ').html_safe
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
redirect_to_repository_settings(@project)
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
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
2014-09-02 18:07:02 +05:30
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
2017-08-17 22:00:37 +05:30
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
2014-09-02 18:07:02 +05:30
end
def disable
2017-08-17 22:00:37 +05:30
deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id])
return render_404 unless deploy_key_project
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
deploy_key_project.destroy!
respond_to do |format|
format.html { redirect_to_repository_settings(@project) }
format.json { head :ok }
end
2014-09-02 18:07:02 +05:30
end
protected
2017-09-10 17:25:29 +05:30
def deploy_key
@deploy_key ||= DeployKey.find(params[:id])
end
def create_params
2018-03-17 18:26:18 +05:30
create_params = params.require(:deploy_key)
.permit(:key, :title, deploy_keys_projects_attributes: [:can_push])
create_params.dig(:deploy_keys_projects_attributes, '0')&.merge!(project_id: @project.id)
create_params
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
def update_params
2018-03-17 18:26:18 +05:30
params.require(:deploy_key).permit(:title, deploy_keys_projects_attributes: [:id, :can_push])
2017-09-10 17:25:29 +05:30
end
def authorize_update_deploy_key!
access_denied! unless can?(current_user, :update_deploy_key, deploy_key)
end
2014-09-02 18:07:02 +05:30
end