config_updates.rb 960 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class ConfigUpdates < BaseSubscription
  4. # This subscription must not be broadcastable as it sends different data depding on
  5. # authenticated state.
  6. description 'Updates to configuration settings'
  7. field :setting, Gql::Types::KeyComplexValueType, description: 'Updated setting'
  8. def self.authorize(...)
  9. true # This subscription should be available for all (including unauthenticated) users.
  10. end
  11. def update
  12. return no_update if !object.frontend
  13. return no_update if object.preferences[:authentication] && !context.current_user?
  14. # Some setting values use interpolation to reference other settings.
  15. # This is applied in `Setting.get`, thus direct reading of the value should be avoided.
  16. value = Setting.get(object.name)
  17. { setting: { key: object.name, value: value } }
  18. end
  19. end
  20. end