monitoring_controller_policy.rb 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Controllers::MonitoringControllerPolicy < Controllers::ApplicationControllerPolicy
  3. def health_check?
  4. token_or_permission?
  5. end
  6. def status?
  7. token_or_permission?
  8. end
  9. def amount_check?
  10. token_or_permission?
  11. end
  12. def token?
  13. permission_and_permission_active?
  14. end
  15. def restart_failed_jobs?
  16. permission_and_permission_active?
  17. end
  18. private
  19. def user_required?
  20. false
  21. end
  22. def token_or_permission?
  23. if user.present?
  24. return monitoring_admin?
  25. end
  26. valid_token_param?
  27. end
  28. def permission_and_permission_active?
  29. user.present? && monitoring_admin? && permission_active?
  30. end
  31. def valid_token_param?
  32. Setting.get('monitoring_token') == record.params[:token]
  33. end
  34. def permission_active?
  35. Permission.exists?(name: 'admin.monitoring', active: true)
  36. end
  37. def monitoring_admin?
  38. user.permissions?('admin.monitoring')
  39. end
  40. end