Class: Webauthn::DestroyService

Inherits:
BaseService show all
Defined in:
app/services/webauthn/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, second_factor_webauthn_registrations_id) ⇒ DestroyService

Returns a new instance of DestroyService.



7
8
9
10
11
# File 'app/services/webauthn/destroy_service.rb', line 7

def initialize(current_user, user, second_factor_webauthn_registrations_id)
  @current_user = current_user
  @user = user
  @webauthn_registration = user.second_factor_webauthn_registrations.find(second_factor_webauthn_registrations_id)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



5
6
7
# File 'app/services/webauthn/destroy_service.rb', line 5

def current_user
  @current_user
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/services/webauthn/destroy_service.rb', line 5

def user
  @user
end

#webauthn_registrationObject (readonly)

Returns the value of attribute webauthn_registration.



5
6
7
# File 'app/services/webauthn/destroy_service.rb', line 5

def webauthn_registration
  @webauthn_registration
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/webauthn/destroy_service.rb', line 13

def execute
  return error(_('You are not authorized to perform this action')) unless authorized?

  result = destroy_second_factor_webauthn_device

  if result[:status] == :success
    notify_on_success(user, webauthn_registration.name)

    unless user.two_factor_enabled?
      user.reset_backup_codes!
      notification_service.disabled_two_factor(user)
    end
  end

  result
end