feat(backend): add external_urls to GraphQL
Available for : - saveAdminSettings - adminSettings - config For #1764
This commit is contained in:
@@ -280,6 +280,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
|||||||
:ok <- eventually_update_instance_actor(res) do
|
:ok <- eventually_update_instance_actor(res) do
|
||||||
Config.clear_config_cache()
|
Config.clear_config_cache()
|
||||||
|
|
||||||
|
# add external_urls
|
||||||
|
urls = Map.get(res, :external_urls, [])
|
||||||
|
external_urls = Enum.map(urls, &Config.transform_external_url/1)
|
||||||
|
res = Map.put(res, :external_urls, external_urls)
|
||||||
|
|
||||||
{:ok, res}
|
{:ok, res}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
|
|||||||
get_in(Application.get_env(:web_push_encryption, :vapid_details), [:public_key])
|
get_in(Application.get_env(:web_push_encryption, :vapid_details), [:public_key])
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
external_urls: Config.external_urls(),
|
||||||
name: Config.instance_name(),
|
name: Config.instance_name(),
|
||||||
registrations_open: Config.instance_registrations_open?(),
|
registrations_open: Config.instance_registrations_open?(),
|
||||||
registrations_moderation: Config.instance_registrations_moderation?(),
|
registrations_moderation: Config.instance_registrations_moderation?(),
|
||||||
|
|||||||
@@ -159,6 +159,24 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
|||||||
)
|
)
|
||||||
|
|
||||||
field(:instance_languages, list_of(:string), description: "The instance's languages")
|
field(:instance_languages, list_of(:string), description: "The instance's languages")
|
||||||
|
|
||||||
|
field(:external_urls, list_of(:external_url),
|
||||||
|
description: "List of URL that will be shown to users"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
object :external_url do
|
||||||
|
meta(:authorize, :all)
|
||||||
|
field(:label, non_null(:string), description: "A human-readable label for the external URL")
|
||||||
|
field(:url, non_null(:string), description: "The actual external URL")
|
||||||
|
field(:enabled, non_null(:boolean), description: "Whether the external URL is enabled")
|
||||||
|
end
|
||||||
|
|
||||||
|
input_object :external_url_input do
|
||||||
|
meta(:authorize, :administrator)
|
||||||
|
field(:label, non_null(:string))
|
||||||
|
field(:url, non_null(:string))
|
||||||
|
field(:enabled, non_null(:boolean))
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "The acceptable values for the instance's terms type"
|
@desc "The acceptable values for the instance's terms type"
|
||||||
@@ -475,6 +493,11 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
|||||||
)
|
)
|
||||||
|
|
||||||
arg(:instance_languages, list_of(:string), description: "The instance's languages")
|
arg(:instance_languages, list_of(:string), description: "The instance's languages")
|
||||||
|
|
||||||
|
arg(:external_urls, list_of(:external_url_input),
|
||||||
|
description: "Array of external URLs with label, status, and id"
|
||||||
|
)
|
||||||
|
|
||||||
middleware(Rajska.QueryAuthorization, permit: :administrator)
|
middleware(Rajska.QueryAuthorization, permit: :administrator)
|
||||||
resolve(&Admin.save_settings/3)
|
resolve(&Admin.save_settings/3)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
|
|||||||
)
|
)
|
||||||
|
|
||||||
field(:search, :search_settings, description: "The instance's search settings")
|
field(:search, :search_settings, description: "The instance's search settings")
|
||||||
|
|
||||||
|
field(:external_urls, list_of(:external_url),
|
||||||
|
description: "List of URL that will be shown to users"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
|
|||||||
@@ -59,6 +59,20 @@ defmodule Mobilizon.Config do
|
|||||||
instance_config()[:name]
|
instance_config()[:name]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@spec external_urls :: String.t()
|
||||||
|
def external_urls do
|
||||||
|
config_cached_value("instance", "external_urls", [])
|
||||||
|
|> Enum.map(&transform_external_url/1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def transform_external_url(map) do
|
||||||
|
%{
|
||||||
|
enabled: Map.fetch!(map, "enabled"),
|
||||||
|
label: Map.fetch!(map, "label"),
|
||||||
|
url: Map.fetch!(map, "url")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
@spec instance_description :: String.t()
|
@spec instance_description :: String.t()
|
||||||
def instance_description,
|
def instance_description,
|
||||||
do:
|
do:
|
||||||
@@ -475,7 +489,8 @@ defmodule Mobilizon.Config do
|
|||||||
instance_privacy_policy_type: instance_privacy_type(),
|
instance_privacy_policy_type: instance_privacy_type(),
|
||||||
instance_privacy_policy_url: instance_privacy_url(),
|
instance_privacy_policy_url: instance_privacy_url(),
|
||||||
instance_rules: instance_rules(),
|
instance_rules: instance_rules(),
|
||||||
instance_languages: instance_languages()
|
instance_languages: instance_languages(),
|
||||||
|
external_urls: external_urls()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user