Commit 7e47a828 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Namespace EnableDeployKeyService under Projects

parent 81e839f4
......@@ -27,7 +27,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
def enable
EnableDeployKeyService.new(@project, current_user, params).execute
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
end
......
class EnableDeployKeyService < BaseService
def execute
key = accessible_keys.find_by(id: params[:key_id] || params[:id])
project.deploy_keys << key if key
key
end
private
def accessible_keys
current_user.accessible_deploy_keys
end
end
module Projects
class EnableDeployKeyService < BaseService
def execute
key = accessible_keys.find_by(id: params[:key_id] || params[:id])
return unless key
project.deploy_keys << key
key
end
private
def accessible_keys
current_user.accessible_deploy_keys
end
end
end
......@@ -76,7 +76,8 @@ module API
requires :key_id, type: Integer, desc: 'The ID of the deploy key'
end
post ":id/#{path}/:key_id/enable" do
key = EnableDeployKeyService.new(user_project, current_user, declared(params)).execute
key = ::Projects::EnableDeployKeyService.new(user_project,
current_user, declared(params)).execute
if key
present key, with: Entities::SSHKey
......
require 'spec_helper'
describe EnableDeployKeyService, services: true do
describe Projects::EnableDeployKeyService, services: true do
let(:deploy_key) { create(:deploy_key, public: true) }
let(:project) { create(:empty_project) }
let(:user) { project.creator}
......@@ -22,6 +22,6 @@ describe EnableDeployKeyService, services: true do
end
def service
EnableDeployKeyService.new(project, user, params)
Projects::EnableDeployKeyService.new(project, user, params)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment