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
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Config
|
2022-03-28 20:02:43 +02:00
|
|
|
alias Mobilizon.Events.Categories
|
2023-06-01 14:48:42 +02:00
|
|
|
alias Mobilizon.Service.{AntiSpam, FrontEndAnalytics}
|
2020-01-22 02:14:42 +01:00
|
|
|
|
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
|
|
|
"""
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec get_config(any(), map(), Absinthe.Resolution.t()) :: {:ok, map()}
|
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
|
2020-06-09 15:20:07 +02:00
|
|
|
%{country: %{iso_code: country_code}} -> String.downcase(country_code)
|
2019-11-08 19:37:14 +01:00
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
|
|
|
|
location =
|
2019-11-19 10:46:54 +01:00
|
|
|
case Map.get(geolix, :city) do
|
2022-10-05 17:42:12 +02:00
|
|
|
%{location: location} -> location
|
2019-11-08 19:37:14 +01:00
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
data = Map.merge(config_cache(), %{location: location, country_code: country_code})
|
|
|
|
|
|
|
|
{:ok, data}
|
|
|
|
end
|
|
|
|
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec terms(any(), map(), Absinthe.Resolution.t()) :: {:ok, map()}
|
2019-12-20 13:04:34 +01:00
|
|
|
def terms(_parent, %{locale: locale}, _resolution) do
|
|
|
|
type = Config.instance_terms_type()
|
|
|
|
|
|
|
|
{url, body_html} =
|
|
|
|
case type do
|
|
|
|
"URL" -> {Config.instance_terms_url(), nil}
|
|
|
|
"DEFAULT" -> {nil, Config.generate_terms(locale)}
|
|
|
|
_ -> {nil, Config.instance_terms(locale)}
|
|
|
|
end
|
|
|
|
|
|
|
|
{:ok, %{body_html: body_html, type: type, url: url}}
|
|
|
|
end
|
|
|
|
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec privacy(any(), map(), Absinthe.Resolution.t()) :: {:ok, map()}
|
2020-06-19 19:27:10 +02:00
|
|
|
def privacy(_parent, %{locale: locale}, _resolution) do
|
|
|
|
type = Config.instance_privacy_type()
|
|
|
|
|
|
|
|
{url, body_html} =
|
|
|
|
case type do
|
|
|
|
"URL" -> {Config.instance_privacy_url(), nil}
|
|
|
|
"DEFAULT" -> {nil, Config.generate_privacy(locale)}
|
|
|
|
_ -> {nil, Config.instance_privacy(locale)}
|
|
|
|
end
|
|
|
|
|
|
|
|
{:ok, %{body_html: body_html, type: type, url: url}}
|
|
|
|
end
|
|
|
|
|
2022-03-28 20:02:43 +02:00
|
|
|
@spec event_categories(any(), map(), Absinthe.Resolution.t()) :: {:ok, [map()]}
|
|
|
|
def event_categories(_parent, _args, _resolution) do
|
|
|
|
categories =
|
|
|
|
Categories.list()
|
|
|
|
|> Enum.map(fn %{id: id, label: label} ->
|
|
|
|
%{id: id |> to_string |> String.upcase(), label: label}
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, categories}
|
|
|
|
end
|
|
|
|
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec config_cache :: map()
|
2019-12-20 13:04:34 +01:00
|
|
|
defp config_cache do
|
|
|
|
case Cachex.fetch(:config, "full_config", fn _key ->
|
|
|
|
case build_config_cache() do
|
|
|
|
value when not is_nil(value) -> {:commit, value}
|
|
|
|
err -> {:ignore, err}
|
|
|
|
end
|
|
|
|
end) do
|
|
|
|
{status, value} when status in [:ok, :commit] -> value
|
2021-09-28 19:40:37 +02:00
|
|
|
_err -> %{}
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec build_config_cache :: map()
|
2019-12-20 13:04:34 +01:00
|
|
|
defp build_config_cache do
|
|
|
|
%{
|
|
|
|
name: Config.instance_name(),
|
|
|
|
registrations_open: Config.instance_registrations_open?(),
|
2020-09-29 09:53:48 +02:00
|
|
|
registrations_allowlist: Config.instance_registrations_allowlist?(),
|
2020-06-19 19:27:10 +02:00
|
|
|
contact: Config.contact(),
|
2019-12-20 13:04:34 +01:00
|
|
|
demo_mode: Config.instance_demo_mode?(),
|
|
|
|
description: Config.instance_description(),
|
2020-06-19 19:27:10 +02:00
|
|
|
long_description: Config.instance_long_description(),
|
2020-10-21 17:49:18 +02:00
|
|
|
slogan: Config.instance_slogan(),
|
2020-10-07 15:37:23 +02:00
|
|
|
languages: Config.instance_languages(),
|
2019-12-20 13:04:34 +01:00
|
|
|
anonymous: %{
|
|
|
|
participation: %{
|
|
|
|
allowed: Config.anonymous_participation?(),
|
|
|
|
validation: %{
|
|
|
|
email: %{
|
|
|
|
enabled: Config.anonymous_participation_email_required?(),
|
|
|
|
confirmation_required:
|
|
|
|
Config.anonymous_event_creation_email_confirmation_required?()
|
|
|
|
},
|
|
|
|
captcha: %{
|
|
|
|
enabled: Config.anonymous_event_creation_email_captcha_required?()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
event_creation: %{
|
|
|
|
allowed: Config.anonymous_event_creation?(),
|
|
|
|
validation: %{
|
|
|
|
email: %{
|
|
|
|
enabled: Config.anonymous_event_creation_email_required?(),
|
|
|
|
confirmation_required:
|
|
|
|
Config.anonymous_event_creation_email_confirmation_required?()
|
|
|
|
},
|
|
|
|
captcha: %{
|
|
|
|
enabled: Config.anonymous_event_creation_email_captcha_required?()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-06-09 14:07:49 +02:00
|
|
|
reports: %{
|
|
|
|
allowed: Config.anonymous_reporting?()
|
|
|
|
},
|
2019-12-20 13:04:34 +01:00
|
|
|
actor_id: Config.anonymous_actor_id()
|
|
|
|
},
|
|
|
|
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()
|
2020-12-17 11:26:25 +01:00
|
|
|
},
|
|
|
|
routing: %{
|
|
|
|
type: Config.instance_maps_routing_type()
|
2019-12-20 13:04:34 +01:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
},
|
|
|
|
resource_providers: Config.instance_resource_providers(),
|
2020-06-08 16:47:57 +02:00
|
|
|
timezones: Tzdata.zone_list(),
|
|
|
|
features: %{
|
2020-09-02 15:08:47 +02:00
|
|
|
groups: Config.instance_group_feature_enabled?(),
|
2023-01-31 19:35:29 +01:00
|
|
|
event_creation: Config.instance_event_creation_enabled?(),
|
2023-06-01 14:48:42 +02:00
|
|
|
antispam: AntiSpam.service().ready?()
|
2020-06-15 11:01:49 +02:00
|
|
|
},
|
2021-10-06 18:00:50 +02:00
|
|
|
restrictions: %{
|
|
|
|
only_admin_can_create_groups: Config.only_admin_can_create_groups?(),
|
|
|
|
only_groups_can_create_events: Config.only_groups_can_create_events?()
|
|
|
|
},
|
2020-06-19 19:27:10 +02:00
|
|
|
rules: Config.instance_rules(),
|
|
|
|
version: Config.instance_version(),
|
2020-06-27 19:12:45 +02:00
|
|
|
federating: Config.instance_federating(),
|
|
|
|
auth: %{
|
|
|
|
ldap: Config.ldap_enabled?(),
|
2022-10-28 16:05:55 +02:00
|
|
|
database_login:
|
|
|
|
Application.get_env(:mobilizon, :instance) |> get_in([:disable_database_login]) == false,
|
2020-06-27 19:12:45 +02:00
|
|
|
oauth_providers: Config.oauth_consumer_strategies()
|
2021-04-12 10:13:11 +02:00
|
|
|
},
|
|
|
|
upload_limits: %{
|
|
|
|
default: Config.get([:instance, :upload_limit]),
|
|
|
|
avatar: Config.get([:instance, :avatar_upload_limit]),
|
|
|
|
banner: Config.get([:instance, :banner_upload_limit])
|
2021-04-19 12:40:51 +02:00
|
|
|
},
|
|
|
|
instance_feeds: %{
|
|
|
|
enabled: Config.get([:instance, :enable_instance_feeds])
|
2021-05-06 18:39:59 +02:00
|
|
|
},
|
|
|
|
web_push: %{
|
|
|
|
enabled: !is_nil(Application.get_env(:web_push_encryption, :vapid_details)),
|
|
|
|
public_key:
|
|
|
|
get_in(Application.get_env(:web_push_encryption, :vapid_details), [:public_key])
|
2021-10-04 18:59:41 +02:00
|
|
|
},
|
2021-12-16 16:48:50 +01:00
|
|
|
export_formats: Config.instance_export_formats(),
|
2022-08-26 16:08:58 +02:00
|
|
|
analytics: FrontEndAnalytics.config(),
|
|
|
|
search: %{
|
|
|
|
global: %{
|
|
|
|
is_enabled:
|
|
|
|
Application.get_env(:mobilizon, :search) |> get_in([:global]) |> get_in([:is_enabled]),
|
|
|
|
is_default:
|
|
|
|
Application.get_env(:mobilizon, :search)
|
|
|
|
|> get_in([:global])
|
|
|
|
|> get_in([:is_default_search])
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 13:04:34 +01:00
|
|
|
}
|
2019-03-22 10:53:38 +01:00
|
|
|
end
|
|
|
|
end
|