2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-08 14:32:10 -04:00
|
|
|
module Projects
|
|
|
|
class EnableDeployKeyService < BaseService
|
|
|
|
def execute
|
2018-11-17 00:59:17 -05:00
|
|
|
key_id = params[:key_id] || params[:id]
|
|
|
|
key = find_accessible_key(key_id)
|
|
|
|
|
2016-08-08 14:32:10 -04:00
|
|
|
return unless key
|
|
|
|
|
2017-05-01 01:22:11 -04:00
|
|
|
unless project.deploy_keys.include?(key)
|
|
|
|
project.deploy_keys << key
|
|
|
|
end
|
|
|
|
|
2016-08-08 14:32:10 -04:00
|
|
|
key
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-11-17 00:59:17 -05: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 14:32:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|