application_config.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 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 + custom_settings
  12. end
  13. private
  14. def unauthenticated?
  15. context.current_user?.nil?
  16. end
  17. def frontend_settings
  18. Setting.select('name, preferences').where(frontend: true).each_with_object([]) do |setting, result|
  19. next if setting.preferences[:authentication] && unauthenticated?
  20. value = Setting.get(setting.name)
  21. next if unauthenticated? && !value
  22. result << { key: setting.name, value: value }
  23. end
  24. end
  25. def rails_application_config
  26. [
  27. 'active_storage.web_image_content_types',
  28. ].map do |config_name|
  29. (method, key) = config_name.split('.')
  30. value = Rails.application.config.send(method)
  31. value = value[key.to_sym] if key.present?
  32. { key: config_name, value: value }
  33. end
  34. end
  35. def custom_settings
  36. [
  37. 'auth_saml_credentials.display_name',
  38. ].filter_map do |config_name|
  39. (setting, key) = config_name.split('.')
  40. value = Setting.get(setting)
  41. value = value[key.to_sym] if key.present?
  42. next if unauthenticated? && !value
  43. { key: config_name, value: value }
  44. end
  45. end
  46. end
  47. end