application_config.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Queries
  3. class ApplicationConfig < BaseQuery
  4. description 'Configuration required for front end operation (more results returned for authenticated users)'
  5. type [Gql::Types::KeyComplexValueType, { null: false }], null: false
  6. def self.authorize(...)
  7. true # This query should be available for all (including unauthenticated) users.
  8. end
  9. # Reimplemented from sessions_controller#config_frontend.
  10. def resolve(...)
  11. frontend_settings + rails_application_config
  12. end
  13. private
  14. def frontend_settings
  15. result = []
  16. unauthenticated = context.current_user?.nil?
  17. Setting.select('name, preferences').where(frontend: true).each do |setting|
  18. next if setting.preferences[:authentication] && unauthenticated
  19. value = Setting.get(setting.name)
  20. next if unauthenticated && !value
  21. result << { key: setting.name, value: value }
  22. end
  23. result
  24. end
  25. def rails_application_config
  26. relevant_configs = [
  27. 'active_storage.web_image_content_types',
  28. ]
  29. relevant_configs.map do |config_name|
  30. (method, key) = config_name.split('.')
  31. value = Rails.application.config.send(method)
  32. value = value[key.to_sym] if key.present?
  33. { key: config_name, value: value }
  34. end
  35. end
  36. end
  37. end