two_factor_updates.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class User::Current::TwoFactorUpdates < BaseSubscription
  4. description 'Updates to current user two factor records'
  5. subscription_scope :current_user_id
  6. field :configuration, Gql::Types::User::ConfigurationTwoFactorType, description: 'Configuration information for the current user.'
  7. def authorized?
  8. context.current_user.permissions?('user_preferences.two_factor_authentication')
  9. end
  10. def subscribe
  11. response
  12. end
  13. def update
  14. response
  15. end
  16. private
  17. def response
  18. user = context.current_user
  19. enabled_authentication_methods = user.two_factor_enabled_authentication_methods
  20. {
  21. configuration: {
  22. enabled_authentication_methods: enabled_authentication_methods.each { |item| item[:authentication_method] = item.delete(:method) },
  23. recovery_codes_exist: user.auth_two_factor.user_recovery_codes_exists?
  24. }
  25. }
  26. end
  27. end
  28. end