2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-15 11:35:24 -04:00
|
|
|
module Keys
|
|
|
|
class CreateService < ::Keys::BaseService
|
2020-06-15 08:08:44 -04:00
|
|
|
attr_accessor :current_user
|
|
|
|
|
|
|
|
def initialize(current_user, params = {})
|
2021-04-19 17:09:27 -04:00
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
2020-06-15 08:08:44 -04:00
|
|
|
@ip_address = @params.delete(:ip_address)
|
|
|
|
@user = params.delete(:user) || current_user
|
|
|
|
end
|
|
|
|
|
2017-09-15 11:35:24 -04:00
|
|
|
def execute
|
|
|
|
key = user.keys.create(params)
|
|
|
|
notification_service.new_key(key) if key.persisted?
|
|
|
|
key
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Keys::CreateService.prepend_mod_with('Keys::CreateService')
|