diff options
Diffstat (limited to 'app/services/two_factor/destroy_service.rb')
-rw-r--r-- | app/services/two_factor/destroy_service.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/services/two_factor/destroy_service.rb b/app/services/two_factor/destroy_service.rb new file mode 100644 index 00000000000..b8bbe215d6e --- /dev/null +++ b/app/services/two_factor/destroy_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module TwoFactor + class DestroyService < ::TwoFactor::BaseService + def execute + return error(_('You are not authorized to perform this action')) unless can?(current_user, :disable_two_factor, user) + return error(_('Two-factor authentication is not enabled for this user')) unless user.two_factor_enabled? + + result = disable_two_factor + + notification_service.disabled_two_factor(user) if result[:status] == :success + + result + end + + private + + def disable_two_factor + ::Users::UpdateService.new(current_user, user: user).execute do |user| + user.disable_two_factor! + end + end + end +end |