Class: Authn::Passkey::DestroyService

Inherits:
BaseService show all
Defined in:
app/services/authn/passkey/destroy_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary collapse

Attributes inherited from BaseService

#params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(current_user, user, passkey_id) ⇒ DestroyService

Returns a new instance of DestroyService.



8
9
10
11
12
# File 'app/services/authn/passkey/destroy_service.rb', line 8

def initialize(current_user, user, passkey_id)
  @current_user = current_user
  @user = user
  @passkey = user.passkeys.find(passkey_id)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/services/authn/passkey/destroy_service.rb', line 6

def current_user
  @current_user
end

#passkeyObject (readonly)

Returns the value of attribute passkey.



6
7
8
# File 'app/services/authn/passkey/destroy_service.rb', line 6

def passkey
  @passkey
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'app/services/authn/passkey/destroy_service.rb', line 6

def user
  @user
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/authn/passkey/destroy_service.rb', line 14

def execute
  return ServiceResponse.error(message: _("You are not authorized to perform this action")) unless authorized?

  passkey.destroy!

  notify_on_success(user, passkey.name)

  ServiceResponse.success(
    message: _("Passkey has been deleted!")
  )
end