diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-08-08 20:32:10 +0200 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-08-08 20:59:51 +0200 |
commit | 7e47a82899bdb10d2cdc61ce237a25bfa7f8a392 (patch) | |
tree | 0600640a8d146b0c6505ee5e6a466dfda3ce8da9 | |
parent | 81e839f41b38d165bd6af4899e12be2967d607e8 (diff) | |
download | gitlab-ce-7e47a82899bdb10d2cdc61ce237a25bfa7f8a392.tar.gz |
Namespace EnableDeployKeyService under Projects
-rw-r--r-- | app/controllers/projects/deploy_keys_controller.rb | 2 | ||||
-rw-r--r-- | app/services/enable_deploy_key_service.rb | 14 | ||||
-rw-r--r-- | app/services/projects/enable_deploy_key_service.rb | 17 | ||||
-rw-r--r-- | lib/api/deploy_keys.rb | 3 | ||||
-rw-r--r-- | spec/services/projects/enable_deploy_key_service_spec.rb (renamed from spec/services/enable_deploy_key_service_spec.rb) | 4 |
5 files changed, 22 insertions, 18 deletions
diff --git a/app/controllers/projects/deploy_keys_controller.rb b/app/controllers/projects/deploy_keys_controller.rb index ade2c54552b..529e0aa2d33 100644 --- a/app/controllers/projects/deploy_keys_controller.rb +++ b/app/controllers/projects/deploy_keys_controller.rb @@ -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 diff --git a/app/services/enable_deploy_key_service.rb b/app/services/enable_deploy_key_service.rb deleted file mode 100644 index baa4a9dd2d4..00000000000 --- a/app/services/enable_deploy_key_service.rb +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/app/services/projects/enable_deploy_key_service.rb b/app/services/projects/enable_deploy_key_service.rb new file mode 100644 index 00000000000..3cf4264ce9b --- /dev/null +++ b/app/services/projects/enable_deploy_key_service.rb @@ -0,0 +1,17 @@ +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 diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index 6dc9beb57ec..825e05fbae3 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -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 diff --git a/spec/services/enable_deploy_key_service_spec.rb b/spec/services/projects/enable_deploy_key_service_spec.rb index abb5710dfc0..a37510cf159 100644 --- a/spec/services/enable_deploy_key_service_spec.rb +++ b/spec/services/projects/enable_deploy_key_service_spec.rb @@ -1,6 +1,6 @@ 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 |