two_factors_controller_policy.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Controllers::User::TwoFactorsControllerPolicy < Controllers::ApplicationControllerPolicy
  3. def two_factor_enabled_authentication_methods?
  4. admin_access? || access?
  5. end
  6. def two_factor_remove_authentication_method?
  7. admin_access? || access?
  8. end
  9. def two_factor_remove_all_authentication_methods?
  10. admin_access? || access?
  11. end
  12. def two_factor_personal_configuration?
  13. true
  14. end
  15. def two_factor_verify_configuration?
  16. true
  17. end
  18. def two_factor_recovery_codes_generate?
  19. true
  20. end
  21. def two_factor_default_authentication_method?
  22. true
  23. end
  24. def two_factor_authentication_method_initiate_configuration?
  25. true
  26. end
  27. def two_factor_authentication_method_configuration?
  28. true
  29. end
  30. def two_factor_authentication_remove_credentials?
  31. true
  32. end
  33. private
  34. def admin_access?
  35. user.permissions?('admin.user')
  36. end
  37. def access?
  38. return false if record.params['id']&.to_i != user.id
  39. user.permissions?('user_preferences.two_factor_authentication')
  40. end
  41. end