Implement Credo software design suggestions
This commit is contained in:
parent
a781c2d3e2
commit
97651e88e9
|
@ -32,6 +32,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
|
|
||||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
alias Mobilizon.Web.Email.{Admin, Mailer}
|
alias Mobilizon.Web.Email.{Admin, Mailer}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -318,7 +319,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
Convertible.model_to_as(%{follow | actor: follower, target_actor: followed}),
|
Convertible.model_to_as(%{follow | actor: follower, target_actor: followed}),
|
||||||
{:ok, follow_activity} <- create_activity(follow_as_data, local),
|
{:ok, follow_activity} <- create_activity(follow_as_data, local),
|
||||||
activity_unfollow_id <-
|
activity_unfollow_id <-
|
||||||
activity_id || "#{Mobilizon.Web.Endpoint.url()}/unfollow/#{follow_id}/activity",
|
activity_id || "#{Endpoint.url()}/unfollow/#{follow_id}/activity",
|
||||||
unfollow_data <-
|
unfollow_data <-
|
||||||
make_unfollow_data(follower, followed, follow_activity, activity_unfollow_id),
|
make_unfollow_data(follower, followed, follow_activity, activity_unfollow_id),
|
||||||
{:ok, activity} <- create_activity(unfollow_data, local),
|
{:ok, activity} <- create_activity(unfollow_data, local),
|
||||||
|
@ -483,7 +484,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
# If it's an exclusion it should be something else
|
# If it's an exclusion it should be something else
|
||||||
"actor" => actor_url,
|
"actor" => actor_url,
|
||||||
"object" => event_url,
|
"object" => event_url,
|
||||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/leave/event/#{participant.id}"
|
"id" => "#{Endpoint.url()}/leave/event/#{participant.id}"
|
||||||
},
|
},
|
||||||
audience <-
|
audience <-
|
||||||
Audience.calculate_to_and_cc_from_mentions(participant),
|
Audience.calculate_to_and_cc_from_mentions(participant),
|
||||||
|
@ -778,7 +779,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
make_accept_join_data(
|
make_accept_join_data(
|
||||||
follower_as_data,
|
follower_as_data,
|
||||||
Map.merge(additional, %{
|
Map.merge(additional, %{
|
||||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/follow/#{follower.id}",
|
"id" => "#{Endpoint.url()}/accept/follow/#{follower.id}",
|
||||||
"to" => [follower.actor.url],
|
"to" => [follower.actor.url],
|
||||||
"cc" => [],
|
"cc" => [],
|
||||||
"actor" => follower.target_actor.url
|
"actor" => follower.target_actor.url
|
||||||
|
@ -797,7 +798,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
defp accept_join(%Participant{} = participant, additional) do
|
defp accept_join(%Participant{} = participant, additional) do
|
||||||
with {:ok, %Participant{} = participant} <-
|
with {:ok, %Participant{} = participant} <-
|
||||||
Events.update_participant(participant, %{role: :participant}),
|
Events.update_participant(participant, %{role: :participant}),
|
||||||
Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor,
|
Absinthe.Subscription.publish(Endpoint, participant.actor,
|
||||||
event_person_participation_changed: participant.actor.id
|
event_person_participation_changed: participant.actor.id
|
||||||
),
|
),
|
||||||
participant_as_data <- Convertible.model_to_as(participant),
|
participant_as_data <- Convertible.model_to_as(participant),
|
||||||
|
@ -807,7 +808,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
make_accept_join_data(
|
make_accept_join_data(
|
||||||
participant_as_data,
|
participant_as_data,
|
||||||
Map.merge(Map.merge(audience, additional), %{
|
Map.merge(Map.merge(audience, additional), %{
|
||||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/join/#{participant.id}"
|
"id" => "#{Endpoint.url()}/accept/join/#{participant.id}"
|
||||||
})
|
})
|
||||||
) do
|
) do
|
||||||
{:ok, participant, update_data}
|
{:ok, participant, update_data}
|
||||||
|
@ -823,7 +824,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
defp reject_join(%Participant{} = participant, additional) do
|
defp reject_join(%Participant{} = participant, additional) do
|
||||||
with {:ok, %Participant{} = participant} <-
|
with {:ok, %Participant{} = participant} <-
|
||||||
Events.update_participant(participant, %{approved: false, role: :rejected}),
|
Events.update_participant(participant, %{approved: false, role: :rejected}),
|
||||||
Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor,
|
Absinthe.Subscription.publish(Endpoint, participant.actor,
|
||||||
event_person_participation_changed: participant.actor.id
|
event_person_participation_changed: participant.actor.id
|
||||||
),
|
),
|
||||||
participant_as_data <- Convertible.model_to_as(participant),
|
participant_as_data <- Convertible.model_to_as(participant),
|
||||||
|
@ -839,7 +840,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
reject_data
|
reject_data
|
||||||
|> Map.merge(audience)
|
|> Map.merge(audience)
|
||||||
|> Map.merge(%{
|
|> Map.merge(%{
|
||||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/join/#{participant.id}"
|
"id" => "#{Endpoint.url()}/reject/join/#{participant.id}"
|
||||||
}) do
|
}) do
|
||||||
{:ok, participant, update_data}
|
{:ok, participant, update_data}
|
||||||
else
|
else
|
||||||
|
@ -866,7 +867,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
reject_data
|
reject_data
|
||||||
|> Map.merge(audience)
|
|> Map.merge(audience)
|
||||||
|> Map.merge(%{
|
|> Map.merge(%{
|
||||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/follow/#{follower.id}"
|
"id" => "#{Endpoint.url()}/reject/follow/#{follower.id}"
|
||||||
}) do
|
}) do
|
||||||
{:ok, follower, update_data}
|
{:ok, follower, update_data}
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
alias Mobilizon.Share
|
alias Mobilizon.Share
|
||||||
|
alias Mobilizon.Storage.Repo
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_to_and_cc_from_mentions(%Participant{} = participant) do
|
def calculate_to_and_cc_from_mentions(%Participant{} = participant) do
|
||||||
participant = Mobilizon.Storage.Repo.preload(participant, [:actor, :event])
|
participant = Repo.preload(participant, [:actor, :event])
|
||||||
|
|
||||||
actor_participants_urls =
|
actor_participants_urls =
|
||||||
participant.event.id
|
participant.event.id
|
||||||
|
@ -132,13 +133,13 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||||
defp add_event_author(nil), do: []
|
defp add_event_author(nil), do: []
|
||||||
|
|
||||||
defp add_event_author(%Event{} = event) do
|
defp add_event_author(%Event{} = event) do
|
||||||
[Mobilizon.Storage.Repo.preload(event, [:organizer_actor]).organizer_actor.url]
|
[Repo.preload(event, [:organizer_actor]).organizer_actor.url]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_comment_author(nil), do: nil
|
defp add_comment_author(nil), do: nil
|
||||||
|
|
||||||
defp add_comment_author(%Comment{} = comment) do
|
defp add_comment_author(%Comment{} = comment) do
|
||||||
case Mobilizon.Storage.Repo.preload(comment, [:actor]) do
|
case Repo.preload(comment, [:actor]) do
|
||||||
%Comment{actor: %Actor{url: url}} ->
|
%Comment{actor: %Actor{url: url}} ->
|
||||||
url
|
url
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||||
|
|
||||||
alias Mobilizon.GraphQL.API.Follows
|
alias Mobilizon.GraphQL.API.Follows
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def init() do
|
def init() do
|
||||||
|
@ -28,7 +30,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||||
@spec get_actor() :: Actor.t() | {:error, Ecto.Changeset.t()}
|
@spec get_actor() :: Actor.t() | {:error, Ecto.Changeset.t()}
|
||||||
def get_actor do
|
def get_actor do
|
||||||
with {:ok, %Actor{} = actor} <-
|
with {:ok, %Actor{} = actor} <-
|
||||||
Actors.get_or_create_instance_actor_by_url("#{Mobilizon.Web.Endpoint.url()}/relay") do
|
Actors.get_or_create_instance_actor_by_url("#{Endpoint.url()}/relay") do
|
||||||
actor
|
actor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||||
alias Mobilizon.Federation.ActivityPub.Utils
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
|
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
|
||||||
|
|
||||||
|
alias Mobilizon.Web.MediaProxy
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: ActorModel do
|
defimpl Convertible, for: ActorModel do
|
||||||
|
@ -29,14 +31,14 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||||
data["icon"]["url"] &&
|
data["icon"]["url"] &&
|
||||||
%{
|
%{
|
||||||
"name" => data["icon"]["name"] || "avatar",
|
"name" => data["icon"]["name"] || "avatar",
|
||||||
"url" => Mobilizon.Web.MediaProxy.url(data["icon"]["url"])
|
"url" => MediaProxy.url(data["icon"]["url"])
|
||||||
}
|
}
|
||||||
|
|
||||||
banner =
|
banner =
|
||||||
data["image"]["url"] &&
|
data["image"]["url"] &&
|
||||||
%{
|
%{
|
||||||
"name" => data["image"]["name"] || "banner",
|
"name" => data["image"]["name"] || "banner",
|
||||||
"url" => Mobilizon.Web.MediaProxy.url(data["image"]["url"])
|
"url" => MediaProxy.url(data["image"]["url"])
|
||||||
}
|
}
|
||||||
|
|
||||||
actor_data = %{
|
actor_data = %{
|
||||||
|
|
|
@ -6,8 +6,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do
|
||||||
internal one, and back.
|
internal one, and back.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Mobilizon.Media
|
||||||
alias Mobilizon.Media.Picture, as: PictureModel
|
alias Mobilizon.Media.Picture, as: PictureModel
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Upload
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Convert a picture struct to an ActivityStream representation.
|
Convert a picture struct to an ActivityStream representation.
|
||||||
"""
|
"""
|
||||||
|
@ -34,9 +37,9 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do
|
||||||
when is_bitstring(picture_url) do
|
when is_bitstring(picture_url) do
|
||||||
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url),
|
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url),
|
||||||
{:ok, %{name: name, url: url, content_type: content_type, size: size}} <-
|
{:ok, %{name: name, url: url, content_type: content_type, size: size}} <-
|
||||||
Mobilizon.Web.Upload.store(%{body: body, name: name}),
|
Upload.store(%{body: body, name: name}),
|
||||||
{:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do
|
{:picture_exists, nil} <- {:picture_exists, Media.get_picture_by_url(url)} do
|
||||||
Mobilizon.Media.create_picture(%{
|
Media.create_picture(%{
|
||||||
"file" => %{
|
"file" => %{
|
||||||
"url" => url,
|
"url" => url,
|
||||||
"name" => name,
|
"name" => name,
|
||||||
|
|
|
@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@spec fetch_tags([String.t()]) :: [Tag.t()]
|
@spec fetch_tags([String.t()]) :: [Tag.t()]
|
||||||
|
@ -40,7 +42,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
|
||||||
def build_tags(tags) do
|
def build_tags(tags) do
|
||||||
Enum.map(tags, fn %Tag{} = tag ->
|
Enum.map(tags, fn %Tag{} = tag ->
|
||||||
%{
|
%{
|
||||||
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/#{tag.slug}",
|
"href" => Endpoint.url() <> "/tags/#{tag.slug}",
|
||||||
"name" => "##{tag.title}",
|
"name" => "##{tag.title}",
|
||||||
"type" => "Hashtag"
|
"type" => "Hashtag"
|
||||||
}
|
}
|
||||||
|
@ -60,7 +62,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
|
||||||
defp build_mention(%Actor{} = actor) do
|
defp build_mention(%Actor{} = actor) do
|
||||||
%{
|
%{
|
||||||
"href" => actor.url,
|
"href" => actor.url,
|
||||||
"name" => "@#{Mobilizon.Actors.Actor.preferred_username_and_domain(actor)}",
|
"name" => "@#{Actor.preferred_username_and_domain(actor)}",
|
||||||
"type" => "Mention"
|
"type" => "Mention"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,11 +13,13 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||||
|
|
||||||
alias Mobilizon.Federation.WebFinger.XmlBuilder
|
alias Mobilizon.Federation.WebFinger.XmlBuilder
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
require Jason
|
require Jason
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def host_meta do
|
def host_meta do
|
||||||
base_url = Mobilizon.Web.Endpoint.url()
|
base_url = Endpoint.url()
|
||||||
|
|
||||||
{
|
{
|
||||||
:XRD,
|
:XRD,
|
||||||
|
@ -35,7 +37,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||||
end
|
end
|
||||||
|
|
||||||
def webfinger(resource, "JSON") do
|
def webfinger(resource, "JSON") do
|
||||||
host = Mobilizon.Web.Endpoint.host()
|
host = Endpoint.host()
|
||||||
regex = ~r/(acct:)?(?<name>\w+)@#{host}/
|
regex = ~r/(acct:)?(?<name>\w+)@#{host}/
|
||||||
|
|
||||||
with %{"name" => name} <- Regex.named_captures(regex, resource),
|
with %{"name" => name} <- Regex.named_captures(regex, resource),
|
||||||
|
@ -59,7 +61,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||||
@spec represent_actor(Actor.t(), String.t()) :: struct()
|
@spec represent_actor(Actor.t(), String.t()) :: struct()
|
||||||
def represent_actor(actor, "JSON") do
|
def represent_actor(actor, "JSON") do
|
||||||
%{
|
%{
|
||||||
"subject" => "acct:#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}",
|
"subject" => "acct:#{actor.preferred_username}@#{Endpoint.host()}",
|
||||||
"aliases" => [actor.url],
|
"aliases" => [actor.url],
|
||||||
"links" => [
|
"links" => [
|
||||||
%{"rel" => "self", "type" => "application/activity+json", "href" => actor.url},
|
%{"rel" => "self", "type" => "application/activity+json", "href" => actor.url},
|
||||||
|
|
|
@ -12,6 +12,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
|
alias Mobilizon.Web.{MediaProxy, Upload}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Get a person
|
Get a person
|
||||||
"""
|
"""
|
||||||
|
@ -157,7 +159,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||||
pic = args[key][:picture]
|
pic = args[key][:picture]
|
||||||
|
|
||||||
with {:ok, %{name: name, url: url, content_type: content_type, size: _size}} <-
|
with {:ok, %{name: name, url: url, content_type: content_type, size: _size}} <-
|
||||||
Mobilizon.Web.Upload.store(pic.file, type: key, description: pic.alt) do
|
Upload.store(pic.file, type: key, description: pic.alt) do
|
||||||
Map.put(args, key, %{"name" => name, "url" => url, "mediaType" => content_type})
|
Map.put(args, key, %{"name" => name, "url" => url, "mediaType" => content_type})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -236,7 +238,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||||
|
|
||||||
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
||||||
defp proxify_avatar(%Actor{avatar: %{url: avatar_url} = avatar} = actor) do
|
defp proxify_avatar(%Actor{avatar: %{url: avatar_url} = avatar} = actor) do
|
||||||
actor |> Map.put(:avatar, avatar |> Map.put(:url, Mobilizon.Web.MediaProxy.url(avatar_url)))
|
actor |> Map.put(:avatar, avatar |> Map.put(:url, MediaProxy.url(avatar_url)))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
||||||
|
@ -244,7 +246,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||||
|
|
||||||
@spec proxify_banner(Actor.t()) :: Actor.t()
|
@spec proxify_banner(Actor.t()) :: Actor.t()
|
||||||
defp proxify_banner(%Actor{banner: %{url: banner_url} = banner} = actor) do
|
defp proxify_banner(%Actor{banner: %{url: banner_url} = banner} = actor) do
|
||||||
actor |> Map.put(:banner, banner |> Map.put(:url, Mobilizon.Web.MediaProxy.url(banner_url)))
|
actor |> Map.put(:banner, banner |> Map.put(:url, MediaProxy.url(banner_url)))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec proxify_banner(Actor.t()) :: Actor.t()
|
@spec proxify_banner(Actor.t()) :: Actor.t()
|
||||||
|
|
|
@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Actors do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Tasks to manage actors
|
Tasks to manage actors
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
|
alias Mix.Tasks
|
||||||
|
|
||||||
@shortdoc "Manages Mobilizon actors"
|
@shortdoc "Manages Mobilizon actors"
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(_) do
|
def run(_) do
|
||||||
Mix.shell().info("\nAvailable tasks:")
|
Mix.shell().info("\nAvailable tasks:")
|
||||||
Mix.Tasks.Help.run(["--search", "mobilizon.actors."])
|
Tasks.Help.run(["--search", "mobilizon.actors."])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Users do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Tasks to manage users
|
Tasks to manage users
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
|
alias Mix.Tasks
|
||||||
|
|
||||||
@shortdoc "Manages Mobilizon users"
|
@shortdoc "Manages Mobilizon users"
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(_) do
|
def run(_) do
|
||||||
Mix.shell().info("\nAvailable tasks:")
|
Mix.shell().info("\nAvailable tasks:")
|
||||||
Mix.Tasks.Help.run(["--search", "mobilizon.users."])
|
Tasks.Help.run(["--search", "mobilizon.users."])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule Mobilizon do
|
||||||
|
|
||||||
import Cachex.Spec
|
import Cachex.Spec
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.{Config, Storage, Web}
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ defmodule Mobilizon do
|
||||||
|
|
||||||
@spec user_agent :: String.t()
|
@spec user_agent :: String.t()
|
||||||
def user_agent do
|
def user_agent do
|
||||||
info = "#{Mobilizon.Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
|
info = "#{Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
|
||||||
|
|
||||||
"#{named_version()}; #{info}"
|
"#{named_version()}; #{info}"
|
||||||
end
|
end
|
||||||
|
@ -36,9 +36,9 @@ defmodule Mobilizon do
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
children = [
|
children = [
|
||||||
# supervisors
|
# supervisors
|
||||||
Mobilizon.Storage.Repo,
|
Storage.Repo,
|
||||||
Mobilizon.Web.Endpoint,
|
Web.Endpoint,
|
||||||
{Absinthe.Subscription, [Mobilizon.Web.Endpoint]},
|
{Absinthe.Subscription, [Web.Endpoint]},
|
||||||
{Oban, Application.get_env(:mobilizon, Oban)},
|
{Oban, Application.get_env(:mobilizon, Oban)},
|
||||||
# workers
|
# workers
|
||||||
Guardian.DB.Token.SweeperServer,
|
Guardian.DB.Token.SweeperServer,
|
||||||
|
@ -55,7 +55,7 @@ defmodule Mobilizon do
|
||||||
|
|
||||||
@spec config_change(keyword, keyword, [atom]) :: :ok
|
@spec config_change(keyword, keyword, [atom]) :: :ok
|
||||||
def config_change(changed, _new, removed) do
|
def config_change(changed, _new, removed) do
|
||||||
Mobilizon.Web.Endpoint.config_change(changed, removed)
|
Web.Endpoint.config_change(changed, removed)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
|
@ -336,7 +336,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
|> put_change(:followers_url, build_url(username, :followers))
|
|> put_change(:followers_url, build_url(username, :followers))
|
||||||
|> put_change(:following_url, build_url(username, :following))
|
|> put_change(:following_url, build_url(username, :following))
|
||||||
|> put_change(:inbox_url, build_url(username, :inbox))
|
|> put_change(:inbox_url, build_url(username, :inbox))
|
||||||
|> put_change(:shared_inbox_url, "#{Mobilizon.Web.Endpoint.url()}/inbox")
|
|> put_change(:shared_inbox_url, "#{Endpoint.url()}/inbox")
|
||||||
|> put_change(:url, build_url(username, :page))
|
|> put_change(:url, build_url(username, :page))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -376,10 +376,10 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
"keys" => Crypto.generate_rsa_2048_private_key(),
|
"keys" => Crypto.generate_rsa_2048_private_key(),
|
||||||
"preferred_username" => preferred_username,
|
"preferred_username" => preferred_username,
|
||||||
"domain" => nil,
|
"domain" => nil,
|
||||||
"inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox",
|
"inbox_url" => "#{Endpoint.url()}/inbox",
|
||||||
"followers_url" => "#{url}/followers",
|
"followers_url" => "#{url}/followers",
|
||||||
"following_url" => "#{url}/following",
|
"following_url" => "#{url}/following",
|
||||||
"shared_inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox",
|
"shared_inbox_url" => "#{Endpoint.url()}/inbox",
|
||||||
"type" => :Application
|
"type" => :Application
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,8 @@ defmodule Mobilizon.Actors do
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Upload
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
defenum(ActorType, :actor_type, [
|
defenum(ActorType, :actor_type, [
|
||||||
|
@ -755,7 +757,7 @@ defmodule Mobilizon.Actors do
|
||||||
|
|
||||||
@spec safe_remove_file(String.t(), Actor.t()) :: {:ok, Actor.t()}
|
@spec safe_remove_file(String.t(), Actor.t()) :: {:ok, Actor.t()}
|
||||||
defp safe_remove_file(url, %Actor{} = actor) do
|
defp safe_remove_file(url, %Actor{} = actor) do
|
||||||
case Mobilizon.Web.Upload.remove(url) do
|
case Upload.remove(url) do
|
||||||
{:ok, _value} ->
|
{:ok, _value} ->
|
||||||
{:ok, actor}
|
{:ok, actor}
|
||||||
|
|
||||||
|
@ -774,7 +776,7 @@ defmodule Mobilizon.Actors do
|
||||||
with %Ecto.Changeset{changes: %{url: new_url}} <- changes[key],
|
with %Ecto.Changeset{changes: %{url: new_url}} <- changes[key],
|
||||||
%{url: old_url} <- data |> Map.from_struct() |> Map.get(key),
|
%{url: old_url} <- data |> Map.from_struct() |> Map.get(key),
|
||||||
false <- new_url == old_url do
|
false <- new_url == old_url do
|
||||||
Mobilizon.Web.Upload.remove(old_url)
|
Upload.remove(old_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -9,6 +9,8 @@ defmodule Mobilizon.Actors.Follower do
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
approved: boolean,
|
approved: boolean,
|
||||||
url: String.t(),
|
url: String.t(),
|
||||||
|
@ -65,6 +67,6 @@ defmodule Mobilizon.Actors.Follower do
|
||||||
|
|
||||||
changeset
|
changeset
|
||||||
|> put_change(:id, uuid)
|
|> put_change(:id, uuid)
|
||||||
|> put_change(:url, "#{Mobilizon.Web.Endpoint.url()}/follow/#{uuid}")
|
|> put_change(:url, "#{Endpoint.url()}/follow/#{uuid}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,8 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
|
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
country: String.t(),
|
country: String.t(),
|
||||||
locality: String.t(),
|
locality: String.t(),
|
||||||
|
@ -65,8 +67,7 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
|
|
||||||
@spec set_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
@spec set_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
||||||
defp set_url(%Ecto.Changeset{changes: changes} = changeset) do
|
defp set_url(%Ecto.Changeset{changes: changes} = changeset) do
|
||||||
url =
|
url = Map.get(changes, :url, "#{Endpoint.url()}/address/#{Ecto.UUID.generate()}")
|
||||||
Map.get(changes, :url, "#{Mobilizon.Web.Endpoint.url()}/address/#{Ecto.UUID.generate()}")
|
|
||||||
|
|
||||||
put_change(changeset, :url, url)
|
put_change(changeset, :url, url)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,8 @@ defmodule Mobilizon.Media do
|
||||||
alias Mobilizon.Media.{File, Picture}
|
alias Mobilizon.Media.{File, Picture}
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Upload
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a single picture.
|
Gets a single picture.
|
||||||
"""
|
"""
|
||||||
|
@ -62,7 +64,7 @@ defmodule Mobilizon.Media do
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|> Multi.delete(:picture, picture)
|
|> Multi.delete(:picture, picture)
|
||||||
|> Multi.run(:remove, fn _repo, %{picture: %Picture{file: %File{url: url}}} ->
|
|> Multi.run(:remove, fn _repo, %{picture: %Picture{file: %File{url: url}}} ->
|
||||||
Mobilizon.Web.Upload.remove(url)
|
Upload.remove(url)
|
||||||
end)
|
end)
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ defmodule Mobilizon.Reports.Report do
|
||||||
alias Mobilizon.Events.{Comment, Event}
|
alias Mobilizon.Events.{Comment, Event}
|
||||||
alias Mobilizon.Reports.{Note, ReportStatus}
|
alias Mobilizon.Reports.{Note, ReportStatus}
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
content: String.t(),
|
content: String.t(),
|
||||||
status: ReportStatus.t(),
|
status: ReportStatus.t(),
|
||||||
|
@ -71,7 +73,7 @@ defmodule Mobilizon.Reports.Report do
|
||||||
@spec maybe_generate_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
@spec maybe_generate_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
||||||
defp maybe_generate_url(%Ecto.Changeset{} = changeset) do
|
defp maybe_generate_url(%Ecto.Changeset{} = changeset) do
|
||||||
with res when res in [:error, {:data, nil}] <- fetch_field(changeset, :url),
|
with res when res in [:error, {:data, nil}] <- fetch_field(changeset, :url),
|
||||||
url <- "#{Mobilizon.Web.Endpoint.url()}/report/#{Ecto.UUID.generate()}" do
|
url <- "#{Endpoint.url()}/report/#{Ecto.UUID.generate()}" do
|
||||||
put_change(changeset, :url, url)
|
put_change(changeset, :url, url)
|
||||||
else
|
else
|
||||||
_ -> changeset
|
_ -> changeset
|
||||||
|
|
|
@ -12,6 +12,8 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.Formatter.HTML
|
alias Mobilizon.Service.Formatter.HTML
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
||||||
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
|
|
||||||
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
|
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
|
||||||
tag = String.downcase(tag)
|
tag = String.downcase(tag)
|
||||||
url = "#{Mobilizon.Web.Endpoint.url()}/tag/#{tag}"
|
url = "#{Endpoint.url()}/tag/#{tag}"
|
||||||
link = "<a class='hashtag' data-tag='#{tag}' href='#{url}' rel='tag'>#{tag_text}</a>"
|
link = "<a class='hashtag' data-tag='#{tag}' href='#{url}' rel='tag'>#{tag_text}</a>"
|
||||||
|
|
||||||
{link, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}}
|
{link, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}}
|
||||||
|
|
|
@ -13,11 +13,11 @@ defmodule Mobilizon.Web.Email.Admin do
|
||||||
alias Mobilizon.Reports.Report
|
alias Mobilizon.Reports.Report
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
alias Mobilizon.Web.Email
|
alias Mobilizon.Web.{Email, Gettext}
|
||||||
|
|
||||||
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
|
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
|
||||||
def report(%User{email: email}, %Report{} = report, locale \\ "en") do
|
def report(%User{email: email}, %Report{} = report, locale \\ "en") do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
|
|
@ -7,6 +7,8 @@ defmodule Mobilizon.Web.Email do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
|
alias Mobilizon.Web.EmailView
|
||||||
|
|
||||||
@spec base_email(keyword()) :: Bamboo.Email.t()
|
@spec base_email(keyword()) :: Bamboo.Email.t()
|
||||||
def base_email(args) do
|
def base_email(args) do
|
||||||
instance = Config.instance_config()
|
instance = Config.instance_config()
|
||||||
|
@ -16,7 +18,7 @@ defmodule Mobilizon.Web.Email do
|
||||||
|> from({Config.instance_name(), Config.instance_email_from()})
|
|> from({Config.instance_name(), Config.instance_email_from()})
|
||||||
|> put_header("Reply-To", Config.instance_email_reply_to())
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
||||||
|> assign(:instance, instance)
|
|> assign(:instance, instance)
|
||||||
|> put_html_layout({Mobilizon.Web.EmailView, "email.html"})
|
|> put_html_layout({EmailView, "email.html"})
|
||||||
|> put_text_layout({Mobilizon.Web.EmailView, "email.text"})
|
|> put_text_layout({EmailView, "email.text"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ defmodule Mobilizon.Web.Email.Event do
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
alias Mobilizon.Web.Email
|
alias Mobilizon.Web.{Gettext, Email}
|
||||||
|
|
||||||
@important_changes [:title, :begins_on, :ends_on, :status]
|
@important_changes [:title, :begins_on, :ends_on, :status]
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ defmodule Mobilizon.Web.Email.Event do
|
||||||
changes,
|
changes,
|
||||||
locale \\ "en"
|
locale \\ "en"
|
||||||
) do
|
) do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
|
|
@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.Participant
|
alias Mobilizon.Events.Participant
|
||||||
|
|
||||||
alias Mobilizon.Web.Email
|
alias Mobilizon.Web.{Email, Gettext}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Send emails to local user
|
Send emails to local user
|
||||||
|
@ -46,7 +46,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||||
%Participant{event: event, role: :rejected},
|
%Participant{event: event, role: :rejected},
|
||||||
locale
|
locale
|
||||||
) do
|
) do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
@ -67,7 +67,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||||
%Participant{event: event, role: :participant},
|
%Participant{event: event, role: :participant},
|
||||||
locale
|
locale
|
||||||
) do
|
) do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
|
|
@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.User do
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
alias Mobilizon.Web.Email
|
alias Mobilizon.Web.{Email, Gettext}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ defmodule Mobilizon.Web.Email.User do
|
||||||
%User{email: email, confirmation_token: confirmation_token},
|
%User{email: email, confirmation_token: confirmation_token},
|
||||||
locale \\ "en"
|
locale \\ "en"
|
||||||
) do
|
) do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.User do
|
||||||
%User{email: email, reset_password_token: reset_password_token},
|
%User{email: email, reset_password_token: reset_password_token},
|
||||||
locale \\ "en"
|
locale \\ "en"
|
||||||
) do
|
) do
|
||||||
Mobilizon.Web.Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
subject =
|
subject =
|
||||||
gettext(
|
gettext(
|
||||||
|
|
|
@ -14,6 +14,8 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
|
alias Mobilizon.Web.{ReverseProxy, Upload}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
# no slashes
|
# no slashes
|
||||||
|
@ -41,7 +43,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
|
||||||
conn
|
conn
|
||||||
end
|
end
|
||||||
|
|
||||||
config = Config.get([Mobilizon.Web.Upload])
|
config = Config.get([Upload])
|
||||||
|
|
||||||
with uploader <- Keyword.fetch!(config, :uploader),
|
with uploader <- Keyword.fetch!(config, :uploader),
|
||||||
proxy_remote = Keyword.get(config, :proxy_remote, false),
|
proxy_remote = Keyword.get(config, :proxy_remote, false),
|
||||||
|
@ -76,7 +78,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_media(conn, {:url, url}, true, _) do
|
defp get_media(conn, {:url, url}, true, _) do
|
||||||
Mobilizon.Web.ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], []))
|
ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], []))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_media(conn, {:url, url}, _, _) do
|
defp get_media(conn, {:url, url}, _, _) do
|
||||||
|
|
|
@ -10,6 +10,8 @@ defmodule Mobilizon.Web.MediaProxy do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@base64_opts [padding: false]
|
@base64_opts [padding: false]
|
||||||
|
|
||||||
def url(nil), do: nil
|
def url(nil), do: nil
|
||||||
|
@ -22,7 +24,7 @@ defmodule Mobilizon.Web.MediaProxy do
|
||||||
config = Application.get_env(:mobilizon, :media_proxy, [])
|
config = Application.get_env(:mobilizon, :media_proxy, [])
|
||||||
|
|
||||||
if !Keyword.get(config, :enabled, false) or
|
if !Keyword.get(config, :enabled, false) or
|
||||||
String.starts_with?(url, Mobilizon.Web.Endpoint.url()) do
|
String.starts_with?(url, Endpoint.url()) do
|
||||||
url
|
url
|
||||||
else
|
else
|
||||||
encode_url(url)
|
encode_url(url)
|
||||||
|
@ -30,7 +32,7 @@ defmodule Mobilizon.Web.MediaProxy do
|
||||||
end
|
end
|
||||||
|
|
||||||
def encode_url(url) do
|
def encode_url(url) do
|
||||||
secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base]
|
secret = Application.get_env(:mobilizon, Endpoint)[:secret_key_base]
|
||||||
|
|
||||||
# Must preserve `%2F` for compatibility with S3
|
# Must preserve `%2F` for compatibility with S3
|
||||||
# https://git.pleroma.social/pleroma/pleroma/issues/580
|
# https://git.pleroma.social/pleroma/pleroma/issues/580
|
||||||
|
@ -52,7 +54,7 @@ defmodule Mobilizon.Web.MediaProxy do
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode_url(sig, url) do
|
def decode_url(sig, url) do
|
||||||
secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base]
|
secret = Application.get_env(:mobilizon, Endpoint)[:secret_key_base]
|
||||||
sig = Base.url_decode64!(sig, @base64_opts)
|
sig = Base.url_decode64!(sig, @base64_opts)
|
||||||
local_sig = :crypto.hmac(:sha, secret, url)
|
local_sig = :crypto.hmac(:sha, secret, url)
|
||||||
|
|
||||||
|
@ -69,7 +71,7 @@ defmodule Mobilizon.Web.MediaProxy do
|
||||||
|
|
||||||
def build_url(sig_base64, url_base64, filename \\ nil) do
|
def build_url(sig_base64, url_base64, filename \\ nil) do
|
||||||
[
|
[
|
||||||
Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()),
|
Config.get([:media_proxy, :base_url], Endpoint.url()),
|
||||||
"proxy",
|
"proxy",
|
||||||
sig_base64,
|
sig_base64,
|
||||||
url_base64,
|
url_base64,
|
||||||
|
|
|
@ -69,6 +69,8 @@ defmodule Mobilizon.Web.ReverseProxy do
|
||||||
|
|
||||||
alias Plug.Conn
|
alias Plug.Conn
|
||||||
|
|
||||||
|
alias Mobilizon.Web.MediaProxy
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@type option ::
|
@type option ::
|
||||||
|
@ -111,7 +113,7 @@ defmodule Mobilizon.Web.ReverseProxy do
|
||||||
req_headers = build_req_headers(conn.req_headers, opts)
|
req_headers = build_req_headers(conn.req_headers, opts)
|
||||||
|
|
||||||
opts =
|
opts =
|
||||||
if filename = Mobilizon.Web.MediaProxy.filename(url) do
|
if filename = MediaProxy.filename(url) do
|
||||||
Keyword.put_new(opts, :attachment_name, filename)
|
Keyword.put_new(opts, :attachment_name, filename)
|
||||||
else
|
else
|
||||||
opts
|
opts
|
||||||
|
|
|
@ -36,6 +36,7 @@ defmodule Mobilizon.Web.Upload do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
alias Mobilizon.Web.Upload.{Filter, MIME, Uploader}
|
alias Mobilizon.Web.Upload.{Filter, MIME, Uploader}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -91,7 +92,7 @@ defmodule Mobilizon.Web.Upload do
|
||||||
def remove(url, opts \\ []) do
|
def remove(url, opts \\ []) do
|
||||||
with opts <- get_opts(opts),
|
with opts <- get_opts(opts),
|
||||||
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
|
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
|
||||||
{:same_host, true} <- {:same_host, host == Mobilizon.Web.Endpoint.host()} do
|
{:same_host, true} <- {:same_host, host == Endpoint.host()} do
|
||||||
Uploader.remove_file(opts.uploader, path)
|
Uploader.remove_file(opts.uploader, path)
|
||||||
else
|
else
|
||||||
%URI{} = _uri ->
|
%URI{} = _uri ->
|
||||||
|
@ -129,7 +130,7 @@ defmodule Mobilizon.Web.Upload do
|
||||||
Keyword.get(
|
Keyword.get(
|
||||||
opts,
|
opts,
|
||||||
:base_url,
|
:base_url,
|
||||||
Config.get([__MODULE__, :base_url], Mobilizon.Web.Endpoint.url())
|
Config.get([__MODULE__, :base_url], Endpoint.url())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,8 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||||
|
|
||||||
alias Mobilizon.GraphQL.API
|
alias Mobilizon.GraphQL.API
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
HTTPoison.start()
|
HTTPoison.start()
|
||||||
end
|
end
|
||||||
|
@ -961,7 +963,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_tag = %{
|
expected_tag = %{
|
||||||
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu",
|
"href" => Endpoint.url() <> "/tags/2hu",
|
||||||
"type" => "Hashtag",
|
"type" => "Hashtag",
|
||||||
"name" => "#2hu"
|
"name" => "#2hu"
|
||||||
}
|
}
|
||||||
|
@ -996,7 +998,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||||
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
||||||
|
|
||||||
expected_tag = %{
|
expected_tag = %{
|
||||||
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu",
|
"href" => Endpoint.url() <> "/tags/2hu",
|
||||||
"type" => "Hashtag",
|
"type" => "Hashtag",
|
||||||
"name" => "#2hu"
|
"name" => "#2hu"
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.WebFingerTest do
|
||||||
|
|
||||||
alias Mobilizon.Federation.WebFinger
|
alias Mobilizon.Federation.WebFinger
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@mastodon_account "tcit@social.tcit.fr"
|
@mastodon_account "tcit@social.tcit.fr"
|
||||||
@mastodon_account_username "tcit"
|
@mastodon_account_username "tcit"
|
||||||
@pleroma_account "lain@pleroma.soykaf.com"
|
@pleroma_account "lain@pleroma.soykaf.com"
|
||||||
|
@ -24,7 +26,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
|
||||||
test "returns a link to the xml lrdd" do
|
test "returns a link to the xml lrdd" do
|
||||||
host_info = WebFinger.host_meta()
|
host_info = WebFinger.host_meta()
|
||||||
|
|
||||||
assert String.contains?(host_info, Mobilizon.Web.Endpoint.url())
|
assert String.contains?(host_info, Endpoint.url())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
|
||||||
|
|
||||||
{:ok, result} =
|
{:ok, result} =
|
||||||
WebFinger.webfinger(
|
WebFinger.webfinger(
|
||||||
"#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}",
|
"#{actor.preferred_username}@#{Endpoint.host()}",
|
||||||
"JSON"
|
"JSON"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||||
|
|
||||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
@non_existent_username "nonexistent"
|
@non_existent_username "nonexistent"
|
||||||
|
|
||||||
describe "Person Resolver" do
|
describe "Person Resolver" do
|
||||||
|
@ -120,8 +122,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||||
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
||||||
actor.preferred_username
|
actor.preferred_username
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~
|
assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~ Endpoint.url()
|
||||||
Mobilizon.Web.Endpoint.url()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_person/3 creates a new identity", context do
|
test "create_person/3 creates a new identity", context do
|
||||||
|
@ -255,7 +256,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||||
"The beautiful atlantic way"
|
"The beautiful atlantic way"
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~
|
assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~
|
||||||
Mobilizon.Web.Endpoint.url() <> "/media/"
|
Endpoint.url() <> "/media/"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_person/3 updates an existing identity", context do
|
test "update_person/3 updates an existing identity", context do
|
||||||
|
@ -325,7 +326,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||||
|
|
||||||
assert res_person["banner"]["id"]
|
assert res_person["banner"]["id"]
|
||||||
assert res_person["banner"]["name"] == "The beautiful atlantic way"
|
assert res_person["banner"]["name"] == "The beautiful atlantic way"
|
||||||
assert res_person["banner"]["url"] =~ Mobilizon.Web.Endpoint.url() <> "/media/"
|
assert res_person["banner"]["url"] =~ Endpoint.url() <> "/media/"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_person/3 should fail to update a not owned identity", context do
|
test "update_person/3 should fail to update a not owned identity", context do
|
||||||
|
|
|
@ -8,6 +8,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
|
||||||
|
|
||||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
actor = insert(:actor, user: user)
|
actor = insert(:actor, user: user)
|
||||||
|
@ -42,8 +44,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["picture"]["size"] == 13_120
|
assert json_response(res, 200)["data"]["picture"]["size"] == 13_120
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["picture"]["url"] =~
|
assert json_response(res, 200)["data"]["picture"]["url"] =~ Endpoint.url()
|
||||||
Mobilizon.Web.Endpoint.url()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "picture/3 returns nothing on a non-existent picture", context do
|
test "picture/3 returns nothing on a non-existent picture", context do
|
||||||
|
|
|
@ -20,6 +20,8 @@ defmodule Mobilizon.Web.ConnCase do
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Auth
|
||||||
|
|
||||||
using do
|
using do
|
||||||
quote do
|
quote do
|
||||||
# Import conveniences for testing with connections
|
# Import conveniences for testing with connections
|
||||||
|
@ -30,7 +32,7 @@ defmodule Mobilizon.Web.ConnCase do
|
||||||
@endpoint Mobilizon.Web.Endpoint
|
@endpoint Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
def auth_conn(%Plug.Conn{} = conn, %User{} = user) do
|
def auth_conn(%Plug.Conn{} = conn, %User{} = user) do
|
||||||
{:ok, token, _claims} = Mobilizon.Web.Auth.Guardian.encode_and_sign(user)
|
{:ok, token, _claims} = Auth.Guardian.encode_and_sign(user)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> Plug.Conn.put_req_header("authorization", "Bearer #{token}")
|
|> Plug.Conn.put_req_header("authorization", "Bearer #{token}")
|
||||||
|
|
|
@ -8,9 +8,8 @@ defmodule Mobilizon.Factory do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Crypto
|
alias Mobilizon.Crypto
|
||||||
|
|
||||||
alias Mobilizon.Web.Endpoint
|
alias Mobilizon.Web.{Endpoint, Upload}
|
||||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||||
alias Mobilizon.Web.Upload
|
|
||||||
|
|
||||||
def user_factory do
|
def user_factory do
|
||||||
%Mobilizon.Users.User{
|
%Mobilizon.Users.User{
|
||||||
|
@ -60,7 +59,7 @@ defmodule Mobilizon.Factory do
|
||||||
target_actor: build(:actor),
|
target_actor: build(:actor),
|
||||||
actor: build(:actor),
|
actor: build(:actor),
|
||||||
id: uuid,
|
id: uuid,
|
||||||
url: "#{Mobilizon.Web.Endpoint.url()}/follows/#{uuid}"
|
url: "#{Endpoint.url()}/follows/#{uuid}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias Mobilizon.Web.ActivityPub.ActorView
|
alias Mobilizon.Web.ActivityPub.ActorView
|
||||||
alias Mobilizon.Web.Endpoint
|
alias Mobilizon.Web.{Endpoint, PageView}
|
||||||
alias Mobilizon.Web.PageView
|
|
||||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
|
@ -104,7 +103,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:valid_signature, true)
|
|> assign(:valid_signature, true)
|
||||||
|> post("#{Mobilizon.Web.Endpoint.url()}/inbox", data)
|
|> post("#{Endpoint.url()}/inbox", data)
|
||||||
|
|
||||||
assert "ok" == json_response(conn, 200)
|
assert "ok" == json_response(conn, 200)
|
||||||
:timer.sleep(500)
|
:timer.sleep(500)
|
||||||
|
|
|
@ -11,6 +11,8 @@ defmodule Mobilizon.Web.WebFingerControllerTest do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Federation.WebFinger
|
alias Mobilizon.Federation.WebFinger
|
||||||
|
|
||||||
|
alias Mobilizon.Web.Endpoint
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Mobilizon.Config.put([:instance, :federating], true)
|
Mobilizon.Config.put([:instance, :federating], true)
|
||||||
|
|
||||||
|
@ -22,7 +24,7 @@ defmodule Mobilizon.Web.WebFingerControllerTest do
|
||||||
|
|
||||||
assert response(conn, 200) ==
|
assert response(conn, 200) ==
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\"><Link rel=\"lrdd\" template=\"#{
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\"><Link rel=\"lrdd\" template=\"#{
|
||||||
Mobilizon.Web.Endpoint.url()
|
Endpoint.url()
|
||||||
}/.well-known/webfinger?resource={uri}\" type=\"application/xrd+xml\" /></XRD>"
|
}/.well-known/webfinger?resource={uri}\" type=\"application/xrd+xml\" /></XRD>"
|
||||||
|
|
||||||
assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers
|
assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers
|
||||||
|
|
|
@ -10,7 +10,7 @@ defmodule Mobilizon.Web.MediaProxyTest do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
alias Mobilizon.Web.MediaProxyController
|
alias Mobilizon.Web.{Endpoint, MediaProxyController}
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
enabled = Config.get([:media_proxy, :enabled])
|
enabled = Config.get([:media_proxy, :enabled])
|
||||||
|
@ -35,8 +35,8 @@ defmodule Mobilizon.Web.MediaProxyTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ignores local url" do
|
test "ignores local url" do
|
||||||
local_url = Mobilizon.Web.Endpoint.url() <> "/hello"
|
local_url = Endpoint.url() <> "/hello"
|
||||||
local_root = Mobilizon.Web.Endpoint.url()
|
local_root = Endpoint.url()
|
||||||
assert url(local_url) == local_url
|
assert url(local_url) == local_url
|
||||||
assert url(local_root) == local_root
|
assert url(local_root) == local_root
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ defmodule Mobilizon.Web.MediaProxyTest do
|
||||||
|
|
||||||
assert String.starts_with?(
|
assert String.starts_with?(
|
||||||
encoded,
|
encoded,
|
||||||
Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url())
|
Config.get([:media_proxy, :base_url], Endpoint.url())
|
||||||
)
|
)
|
||||||
|
|
||||||
assert String.ends_with?(encoded, "/logo.png")
|
assert String.ends_with?(encoded, "/logo.png")
|
||||||
|
@ -84,16 +84,16 @@ defmodule Mobilizon.Web.MediaProxyTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "validates signature" do
|
test "validates signature" do
|
||||||
secret_key_base = Config.get([Mobilizon.Web.Endpoint, :secret_key_base])
|
secret_key_base = Config.get([Endpoint, :secret_key_base])
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Config.put([Mobilizon.Web.Endpoint, :secret_key_base], secret_key_base)
|
Config.put([Endpoint, :secret_key_base], secret_key_base)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
encoded = url("https://pleroma.social")
|
encoded = url("https://pleroma.social")
|
||||||
|
|
||||||
Config.put(
|
Config.put(
|
||||||
[Mobilizon.Web.Endpoint, :secret_key_base],
|
[Endpoint, :secret_key_base],
|
||||||
"00000000000000000000000000000000000000000000000"
|
"00000000000000000000000000000000000000000000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule Mobilizon.UploadTest do
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.{Endpoint, Upload}
|
||||||
alias Mobilizon.Web.Upload.Uploader
|
alias Mobilizon.Web.Upload.Uploader
|
||||||
|
|
||||||
describe "Storing a file with the Local uploader" do
|
describe "Storing a file with the Local uploader" do
|
||||||
|
@ -31,7 +31,7 @@ defmodule Mobilizon.UploadTest do
|
||||||
size: 13_227
|
size: 13_227
|
||||||
} = data
|
} = data
|
||||||
|
|
||||||
assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/")
|
assert String.starts_with?(url, Endpoint.url() <> "/media/")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns a media url with configured base_url" do
|
test "returns a media url with configured base_url" do
|
||||||
|
@ -59,10 +59,10 @@ defmodule Mobilizon.UploadTest do
|
||||||
filename: "an [image.jpg"
|
filename: "an [image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.Dedupe])
|
{:ok, data} = Upload.store(file, filters: [Upload.Filter.Dedupe])
|
||||||
|
|
||||||
assert data.url ==
|
assert data.url ==
|
||||||
Mobilizon.Web.Endpoint.url() <>
|
Endpoint.url() <>
|
||||||
"/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg"
|
"/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ defmodule Mobilizon.UploadTest do
|
||||||
filename: "an [image.jpg"
|
filename: "an [image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.Dedupe])
|
{:ok, data} = Upload.store(file, filters: [Upload.Filter.Dedupe])
|
||||||
assert data.content_type == "image/jpeg"
|
assert data.content_type == "image/jpeg"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ defmodule Mobilizon.UploadTest do
|
||||||
filename: "an [image.jpg"
|
filename: "an [image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.AnonymizeFilename])
|
{:ok, data} = Upload.store(file, filters: [Upload.Filter.AnonymizeFilename])
|
||||||
|
|
||||||
refute data.name == "an [image.jpg"
|
refute data.name == "an [image.jpg"
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,7 @@ defmodule Mobilizon.UploadTest do
|
||||||
content_type: "image/jpeg"
|
content_type: "image/jpeg"
|
||||||
} = data
|
} = data
|
||||||
|
|
||||||
assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/")
|
assert String.starts_with?(url, Endpoint.url() <> "/media/")
|
||||||
|
|
||||||
%URI{path: "/media/" <> path} = URI.parse(url)
|
%URI{path: "/media/" <> path} = URI.parse(url)
|
||||||
{Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url}
|
{Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url}
|
||||||
|
|
Loading…
Reference in a new issue