debian-mirror-gitlab/app/services/projects/enable_deploy_key_service.rb

31 lines
636 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Projects
class EnableDeployKeyService < BaseService
def execute
2019-02-15 15:39:39 +05:30
key_id = params[:key_id] || params[:id]
key = find_accessible_key(key_id)
2016-09-13 17:45:13 +05:30
return unless key
2017-08-17 22:00:37 +05:30
unless project.deploy_keys.include?(key)
project.deploy_keys << key
end
2016-09-13 17:45:13 +05:30
key
end
private
2019-02-15 15:39:39 +05:30
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-09-13 17:45:13 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Projects::EnableDeployKeyService.prepend_mod_with('Projects::EnableDeployKeyService')