gitlab-org--gitlab-foss/app/services/projects/enable_deploy_key_service.rb
Yorick Peterse 2039c8280d
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
2018-09-11 17:32:00 +02:00

24 lines
505 B
Ruby

# frozen_string_literal: true
module Projects
class EnableDeployKeyService < BaseService
# rubocop: disable CodeReuse/ActiveRecord
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
# rubocop: enable CodeReuse/ActiveRecord
private
def accessible_keys
current_user.accessible_deploy_keys
end
end
end