123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- module Gql::Queries
- class ApplicationConfig < BaseQuery
- description 'Configuration required for front end operation (more results returned for authenticated users)'
- type [Gql::Types::KeyComplexValueType, { null: false }], null: false
- def self.authorize(...)
- true # This query should be available for all (including unauthenticated) users.
- end
- # Reimplemented from sessions_controller#config_frontend.
- def resolve(...)
- frontend_settings + rails_application_config + custom_settings
- end
- private
- def unauthenticated?
- context.current_user?.nil?
- end
- def frontend_settings
- Setting.select('name, preferences').where(frontend: true).each_with_object([]) do |setting, result|
- next if setting.preferences[:authentication] && unauthenticated?
- value = Setting.get(setting.name)
- next if unauthenticated? && !value
- result << { key: setting.name, value: value }
- end
- end
- def rails_application_config
- [
- 'active_storage.web_image_content_types',
- ].map do |config_name|
- (method, key) = config_name.split('.')
- value = Rails.application.config.send(method)
- value = value[key.to_sym] if key.present?
- { key: config_name, value: value }
- end
- end
- def custom_settings
- [
- 'auth_saml_credentials.display_name',
- ].filter_map do |config_name|
- (setting, key) = config_name.split('.')
- value = Setting.get(setting)
- value = value[key.to_sym] if key.present?
- next if unauthenticated? && !value
- { key: config_name, value: value }
- end
- end
- end
- end
|