all developments of milestone 1
This commit is contained in:
@@ -57,15 +57,25 @@ defmodule Mobilizon.GraphQL.API.Events do
|
||||
defp process_picture(%{media_id: _picture_id} = args, _), do: args
|
||||
|
||||
defp process_picture(%{media: media}, %Actor{id: actor_id}) do
|
||||
with uploaded when is_map(uploaded) <-
|
||||
media
|
||||
|> Map.get(:file)
|
||||
|> Utils.make_media_data(description: Map.get(media, :name)) do
|
||||
# case url
|
||||
if Map.has_key?(media, :url) do
|
||||
%{
|
||||
file: Map.take(uploaded, [:url, :name, :content_type, :size]),
|
||||
metadata: Map.take(uploaded, [:width, :height, :blurhash]),
|
||||
file: %{"url" => media.url, "name" => media.name},
|
||||
actor_id: actor_id
|
||||
}
|
||||
|
||||
# case upload
|
||||
else
|
||||
with uploaded when is_map(uploaded) <-
|
||||
media
|
||||
|> Map.get(:file)
|
||||
|> Utils.make_media_data(description: Map.get(media, :name)) do
|
||||
%{
|
||||
file: Map.take(uploaded, [:url, :name, :content_type, :size]),
|
||||
metadata: Map.take(uploaded, [:width, :height, :blurhash]),
|
||||
actor_id: actor_id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,11 +5,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
alias Mobilizon.{Actors, Admin, Config, Events, Instances, Users}
|
||||
alias Mobilizon.{Actors, Admin, Config, Events, Instances, Media, Users}
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
alias Mobilizon.Admin.{ActionLog, Setting}
|
||||
alias Mobilizon.Admin.{ActionLog, Setting, SettingMedia}
|
||||
alias Mobilizon.Cldr.Language
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Discussions.Comment
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Relay}
|
||||
@@ -20,6 +19,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Web.Email
|
||||
|
||||
alias Mobilizon.GraphQL.Resolvers.Media, as: MediaResolver
|
||||
|
||||
import Mobilizon.Web.Gettext
|
||||
require Logger
|
||||
|
||||
@@ -268,8 +270,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
with {:ok, res} <- Admin.save_settings("instance", args),
|
||||
res <-
|
||||
res
|
||||
|> Enum.map(fn {key, %Setting{value: value}} ->
|
||||
{key, Admin.get_setting_value(value)}
|
||||
|> Enum.map(fn {key, val} ->
|
||||
case val do
|
||||
%Setting{value: value} -> {key, Admin.get_setting_value(value)}
|
||||
%SettingMedia{media: media} -> {key, media}
|
||||
end
|
||||
end)
|
||||
|> Enum.into(%{}),
|
||||
:ok <- eventually_update_instance_actor(res) do
|
||||
@@ -284,6 +289,38 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
dgettext("errors", "You need to be logged-in and an administrator to save admin settings")}
|
||||
end
|
||||
|
||||
@spec get_media_setting(any(), any(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Media.t()} | {:error, String.t()}
|
||||
def get_media_setting(_parent, %{group: group, name: name}, %{
|
||||
context: %{current_user: %User{role: role}}
|
||||
})
|
||||
when is_admin(role) do
|
||||
{:ok, MediaResolver.transform_media(Admin.get_admin_setting_media(group, name, nil))}
|
||||
end
|
||||
|
||||
def get_media_setting(_parent, _args, _resolution) do
|
||||
{:error,
|
||||
dgettext("errors", "You need to be logged-in and an administrator to access admin settings")}
|
||||
end
|
||||
|
||||
@spec get_instance_logo(any(), any(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Media.t() | nil} | {:error, String.t()}
|
||||
def get_instance_logo(parent, _args, resolution) do
|
||||
get_media_setting(parent, %{group: "instance", name: "instance_logo"}, resolution)
|
||||
end
|
||||
|
||||
@spec get_instance_favicon(any(), any(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Media.t() | nil} | {:error, String.t()}
|
||||
def get_instance_favicon(parent, _args, resolution) do
|
||||
get_media_setting(parent, %{group: "instance", name: "instance_favicon"}, resolution)
|
||||
end
|
||||
|
||||
@spec get_default_picture(any(), any(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Media.t() | nil} | {:error, String.t()}
|
||||
def get_default_picture(parent, _args, resolution) do
|
||||
get_media_setting(parent, %{group: "instance", name: "default_picture"}, resolution)
|
||||
end
|
||||
|
||||
@spec update_user(any, map(), Absinthe.Resolution.t()) ::
|
||||
{:error, :invalid_argument | :user_not_found | binary | Ecto.Changeset.t()}
|
||||
| {:ok, Mobilizon.Users.User.t()}
|
||||
|
||||
@@ -5,8 +5,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Events.Categories
|
||||
alias Mobilizon.Medias.Media
|
||||
alias Mobilizon.Service.{AntiSpam, FrontEndAnalytics}
|
||||
|
||||
alias Mobilizon.GraphQL.Resolvers.Media, as: MediaResolver
|
||||
|
||||
@doc """
|
||||
Gets config.
|
||||
"""
|
||||
@@ -31,6 +34,16 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
|
||||
{:ok, data}
|
||||
end
|
||||
|
||||
@spec instance_logo(any(), map(), Absinthe.Resolution.t()) :: {:ok, Media.t()}
|
||||
def instance_logo(_parent, _params, _resolution) do
|
||||
{:ok, MediaResolver.transform_media(Config.instance_logo())}
|
||||
end
|
||||
|
||||
@spec default_picture(any(), map(), Absinthe.Resolution.t()) :: {:ok, Media.t()}
|
||||
def default_picture(_parent, _params, _resolution) do
|
||||
{:ok, MediaResolver.transform_media(Config.default_picture())}
|
||||
end
|
||||
|
||||
@spec terms(any(), map(), Absinthe.Resolution.t()) :: {:ok, map()}
|
||||
def terms(_parent, %{locale: locale}, _resolution) do
|
||||
type = Config.instance_terms_type()
|
||||
@@ -94,10 +107,15 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
|
||||
registrations_allowlist: Config.instance_registrations_allowlist?(),
|
||||
contact: Config.contact(),
|
||||
demo_mode: Config.instance_demo_mode?(),
|
||||
long_events: Config.instance_long_events?(),
|
||||
description: Config.instance_description(),
|
||||
long_description: Config.instance_long_description(),
|
||||
slogan: Config.instance_slogan(),
|
||||
languages: Config.instance_languages(),
|
||||
instance_logo: Config.instance_logo(),
|
||||
primary_color: Config.primary_color(),
|
||||
secondary_color: Config.secondary_color(),
|
||||
default_picture: Config.default_picture(),
|
||||
anonymous: %{
|
||||
participation: %{
|
||||
allowed: Config.anonymous_participation?(),
|
||||
|
||||
@@ -18,6 +18,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Media do
|
||||
do_fetch_media(media_id)
|
||||
end
|
||||
|
||||
def media(%{media_id: media_id} = _parent, _args, _resolution) do
|
||||
do_fetch_media(media_id)
|
||||
end
|
||||
|
||||
def media(%{picture: media} = _parent, _args, _resolution), do: {:ok, media}
|
||||
def media(_parent, %{id: media_id}, _resolution), do: do_fetch_media(media_id)
|
||||
def media(_parent, _args, _resolution), do: {:ok, nil}
|
||||
@@ -133,8 +137,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Media do
|
||||
|
||||
def user_size(_parent, _args, _resolution), do: {:error, :unauthenticated}
|
||||
|
||||
@spec transform_media(Media.t()) :: map()
|
||||
defp transform_media(%Media{id: id, file: file, metadata: metadata}) do
|
||||
@spec transform_media(Media.t() | nil) :: map() | nil
|
||||
def transform_media(nil), do: nil
|
||||
|
||||
def transform_media(%Media{id: id, file: file, metadata: metadata}) do
|
||||
%{
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
|
||||
@@ -124,6 +124,24 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||
field(:instance_terms_type, :instance_terms_type, description: "The instance's terms type")
|
||||
field(:instance_terms_url, :string, description: "The instance's terms URL")
|
||||
|
||||
field(:instance_logo, :media,
|
||||
description: "The instance's logo",
|
||||
resolve: &Admin.get_instance_logo/3
|
||||
)
|
||||
|
||||
field(:instance_favicon, :media,
|
||||
description: "The instance's favicon",
|
||||
resolve: &Admin.get_instance_favicon/3
|
||||
)
|
||||
|
||||
field(:default_picture, :media,
|
||||
description: "The default picture",
|
||||
resolve: &Admin.get_default_picture/3
|
||||
)
|
||||
|
||||
field(:primary_color, :string, description: "The instance's primary color")
|
||||
field(:secondary_color, :string, description: "The instance's secondary color")
|
||||
|
||||
field(:instance_privacy_policy, :string,
|
||||
description: "The instance's privacy policy body text"
|
||||
)
|
||||
@@ -412,6 +430,25 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||
arg(:instance_long_description, :string, description: "The instance's long description")
|
||||
arg(:instance_slogan, :string, description: "The instance's slogan")
|
||||
arg(:contact, :string, description: "The instance's contact details")
|
||||
|
||||
arg(:instance_logo, :media_input,
|
||||
description:
|
||||
"The instance's logo, either as an object or directly the ID of an existing media"
|
||||
)
|
||||
|
||||
arg(:instance_favicon, :media_input,
|
||||
description:
|
||||
"The instance's favicon, either as an object or directly the ID of an existing media"
|
||||
)
|
||||
|
||||
arg(:default_picture, :media_input,
|
||||
description:
|
||||
"The default picture, either as an object or directly the ID of an existing media"
|
||||
)
|
||||
|
||||
arg(:primary_color, :string, description: "The instance's primary color")
|
||||
arg(:secondary_color, :string, description: "The instance's secondary color")
|
||||
|
||||
arg(:instance_terms, :string, description: "The instance's terms body text")
|
||||
arg(:instance_terms_type, :instance_terms_type, description: "The instance's terms type")
|
||||
arg(:instance_terms_url, :string, description: "The instance's terms URL")
|
||||
|
||||
@@ -31,6 +31,7 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
|
||||
)
|
||||
|
||||
field(:demo_mode, :boolean, description: "Whether the demo mode is enabled")
|
||||
field(:long_events, :boolean, description: "Whether the long events mode is enabled")
|
||||
field(:country_code, :string, description: "The country code from the IP")
|
||||
field(:location, :lonlat, description: "The IP's location")
|
||||
field(:geocoding, :geocoding, description: "The instance's geocoding settings")
|
||||
@@ -59,6 +60,17 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
|
||||
resolve(&Config.terms/3)
|
||||
end
|
||||
|
||||
field(:instance_logo, :media, description: "The instance's logo") do
|
||||
resolve(&Config.instance_logo/3)
|
||||
end
|
||||
|
||||
field(:default_picture, :media, description: "The default picture") do
|
||||
resolve(&Config.default_picture/3)
|
||||
end
|
||||
|
||||
field(:primary_color, :string, description: "The instance's primary color")
|
||||
field(:secondary_color, :string, description: "The instance's secondary color")
|
||||
|
||||
field(:privacy, :privacy, description: "The instance's privacy policy") do
|
||||
arg(:locale, :string,
|
||||
default_value: "en",
|
||||
|
||||
@@ -263,6 +263,10 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
description: "Whether or not to show the participation price"
|
||||
)
|
||||
|
||||
field(:hide_number_of_participants, :boolean,
|
||||
description: "Whether or not the number of participants is hidden"
|
||||
)
|
||||
|
||||
field(:show_start_time, :boolean, description: "Show event start time")
|
||||
field(:show_end_time, :boolean, description: "Show event end time")
|
||||
|
||||
@@ -316,6 +320,10 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
description: "Whether or not to show the participation price"
|
||||
)
|
||||
|
||||
field(:hide_number_of_participants, :boolean,
|
||||
description: "Whether or not the number of participants is hidden"
|
||||
)
|
||||
|
||||
field(:show_start_time, :boolean, description: "Show event start time")
|
||||
field(:show_end_time, :boolean, description: "Show event end time")
|
||||
|
||||
|
||||
@@ -52,8 +52,9 @@ defmodule Mobilizon.GraphQL.Schema.MediaType do
|
||||
input_object :media_input_object do
|
||||
field(:name, non_null(:string), description: "The media's name")
|
||||
field(:alt, :string, description: "The media's alternative text")
|
||||
field(:file, non_null(:upload), description: "The media file")
|
||||
field(:file, :upload, description: "The media file")
|
||||
field(:actor_id, :id, description: "The media owner")
|
||||
field(:url, :string, description: "The media URL")
|
||||
end
|
||||
|
||||
object :media_queries do
|
||||
|
||||
@@ -273,6 +273,8 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
description: "Radius around the location to search in"
|
||||
)
|
||||
|
||||
arg(:longevents, :boolean, description: "if mention filter in or out long events")
|
||||
|
||||
arg(:bbox, :string, description: "The bbox to search events into")
|
||||
arg(:zoom, :integer, description: "The zoom level for searching events")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user