2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.Config do
|
2019-03-22 10:53:38 +01:00
|
|
|
@moduledoc """
|
2019-09-08 00:05:54 +02:00
|
|
|
Handles the config-related GraphQL calls.
|
2019-03-22 10:53:38 +01:00
|
|
|
"""
|
2019-03-22 13:58:19 +01:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
alias Geolix.Adapter.MMDB2.Record.{Country, Location}
|
2019-03-22 10:53:38 +01:00
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Config
|
|
|
|
|
2019-03-22 10:53:38 +01:00
|
|
|
@doc """
|
2019-09-08 00:05:54 +02:00
|
|
|
Gets config.
|
2019-03-22 10:53:38 +01:00
|
|
|
"""
|
2020-01-26 20:34:25 +01:00
|
|
|
def get_config(_parent, _params, %{context: %{ip: ip}}) do
|
2019-11-08 19:37:14 +01:00
|
|
|
geolix = Geolix.lookup(ip)
|
|
|
|
|
|
|
|
country_code =
|
2019-11-19 10:46:54 +01:00
|
|
|
case Map.get(geolix, :city) do
|
2019-11-08 19:37:14 +01:00
|
|
|
%{country: %Country{iso_code: country_code}} -> String.downcase(country_code)
|
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
|
|
|
|
location =
|
2019-11-19 10:46:54 +01:00
|
|
|
case Map.get(geolix, :city) do
|
2019-11-08 19:37:14 +01:00
|
|
|
%{location: %Location{} = location} -> Map.from_struct(location)
|
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
{:ok,
|
|
|
|
%{
|
2019-09-08 00:05:54 +02:00
|
|
|
name: Config.instance_name(),
|
|
|
|
registrations_open: Config.instance_registrations_open?(),
|
2019-12-17 12:09:24 +01:00
|
|
|
registrations_whitelist: Config.instance_registrations_whitelist?(),
|
2019-11-21 16:07:43 +01:00
|
|
|
demo_mode: Config.instance_demo_mode?(),
|
2019-11-08 19:37:14 +01:00
|
|
|
description: Config.instance_description(),
|
|
|
|
location: location,
|
2019-11-20 13:49:57 +01:00
|
|
|
country_code: country_code,
|
|
|
|
geocoding: %{
|
|
|
|
provider: Config.instance_geocoding_provider(),
|
|
|
|
autocomplete: Config.instance_geocoding_autocomplete()
|
|
|
|
},
|
|
|
|
maps: %{
|
|
|
|
tiles: %{
|
|
|
|
endpoint: Config.instance_maps_tiles_endpoint(),
|
|
|
|
attribution: Config.instance_maps_tiles_attribution()
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
}}
|
2019-03-22 10:53:38 +01:00
|
|
|
end
|
|
|
|
end
|