2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-08 18:32:10 +00:00
|
|
|
module Projects
|
|
|
|
class EnableDeployKeyService < BaseService
|
|
|
|
def execute
|
2018-11-17 05:59:17 +00:00
|
|
|
key_id = params[:key_id] || params[:id]
|
|
|
|
key = find_accessible_key(key_id)
|
|
|
|
|
2016-08-08 18:32:10 +00:00
|
|
|
return unless key
|
|
|
|
|
2017-05-01 05:22:11 +00:00
|
|
|
unless project.deploy_keys.include?(key)
|
|
|
|
project.deploy_keys << key
|
|
|
|
end
|
|
|
|
|
2016-08-08 18:32:10 +00:00
|
|
|
key
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-11-17 05:59:17 +00:00
|
|
|
def find_accessible_key(key_id)
|
|
|
|
if current_user.admin?
|
|
|
|
DeployKey.find_by_id(key_id)
|
|
|
|
else
|
|
|
|
current_user.accessible_deploy_keys.find_by_id(key_id)
|
|
|
|
end
|
2016-08-08 18:32:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Projects::EnableDeployKeyService.prepend_mod_with('Projects::EnableDeployKeyService')
|