gitlab-org--gitlab-foss/app/services/projects/enable_deploy_key_service.rb
Mark Fletcher d02e7226c4 Detect already enabled DeployKeys in EnableDeployKeyService
Ensures deploy keys can't be re-added, which causes a validation error
2017-05-03 17:37:08 +08:00

20 lines
383 B
Ruby

module Projects
class EnableDeployKeyService < BaseService
def execute
key = accessible_keys.find_by(id: params[:key_id] || params[:id])
return unless key
unless project.deploy_keys.include?(key)
project.deploy_keys << key
end
key
end
private
def accessible_keys
current_user.accessible_deploy_keys
end
end
end