Commit bc8a5ec7 authored by Rajendra Kadam's avatar Rajendra Kadam

Use CreateService when an admin creates a new gpg key for a user

parent 318d5541
......@@ -2,6 +2,14 @@
module GpgKeys
class CreateService < Keys::BaseService
attr_accessor :current_user
def initialize(current_user, params = {})
@current_user, @params = current_user, params
@ip_address = @params.delete(:ip_address)
@user = params.delete(:user) || current_user
end
def execute
key = user.gpg_keys.create(params)
notification_service.new_gpg_key(key) if key.persisted?
......
......@@ -328,9 +328,9 @@ module API
user = User.find_by(id: params.delete(:id))
not_found!('User') unless user
key = user.gpg_keys.new(declared_params(include_missing: false))
key = ::GpgKeys::CreateService.new(current_user, declared_params(include_missing: false).merge(user: user)).execute
if key.save
if key.persisted?
present key, with: Entities::GpgKey
else
render_validation_error!(key)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment