settings_controller_policy.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Controllers::SettingsControllerPolicy < Controllers::ApplicationControllerPolicy
  3. default_permit!('admin.*')
  4. def show?
  5. user.permissions!('admin.*')
  6. authorized_for_setting?(:show?)
  7. rescue Exceptions::Forbidden => e
  8. not_authorized(e)
  9. end
  10. def update?
  11. updateable?
  12. end
  13. def update_image?
  14. updateable?
  15. end
  16. private
  17. def setting
  18. @setting ||= Setting.lookup(id: record.params[:id])
  19. end
  20. def authorized_for_setting?(query)
  21. Pundit.authorize(user, setting, query)
  22. true
  23. rescue Pundit::NotAuthorizedError
  24. not_authorized("required #{setting.preferences[:permission].inspect}")
  25. end
  26. def updateable?
  27. return false if !user.permissions?('admin.*')
  28. return false if !authorized_for_setting?(:update?)
  29. service_enabled?
  30. end
  31. def service_enabled?
  32. return true if !Setting.get('system_online_service')
  33. return true if !setting.preferences[:online_service_disable]
  34. not_authorized('service disabled')
  35. end
  36. end