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 ...@@ -27,7 +27,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end end
def enable 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) redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
end 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 ...@@ -76,7 +76,8 @@ module API
requires :key_id, type: Integer, desc: 'The ID of the deploy key' requires :key_id, type: Integer, desc: 'The ID of the deploy key'
end end
post ":id/#{path}/:key_id/enable" do 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 if key
present key, with: Entities::SSHKey present key, with: Entities::SSHKey
......
require 'spec_helper' require 'spec_helper'
describe EnableDeployKeyService, services: true do describe Projects::EnableDeployKeyService, services: true do
let(:deploy_key) { create(:deploy_key, public: true) } let(:deploy_key) { create(:deploy_key, public: true) }
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { project.creator} let(:user) { project.creator}
...@@ -22,6 +22,6 @@ describe EnableDeployKeyService, services: true do ...@@ -22,6 +22,6 @@ describe EnableDeployKeyService, services: true do
end end
def service def service
EnableDeployKeyService.new(project, user, params) Projects::EnableDeployKeyService.new(project, user, params)
end end
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