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

29 lines
549 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
2018-12-23 12:14:25 +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
2018-12-23 12:14:25 +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