Merge branch 'fix-credo' into 'master'

Fix Credo issues

See merge request framasoft/mobilizon!385
This commit is contained in:
Thomas Citharel 2020-01-29 09:02:43 +01:00
commit 17e0b3968f
69 changed files with 208 additions and 154 deletions

View File

@ -10,7 +10,7 @@ defmodule Mobilizon.Federation.ActivityPub do
import Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.{Actors, Config, Events, Reports, Users, Share}
alias Mobilizon.{Actors, Config, Events, Reports, Share, Users}
alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Reports.Report
@ -32,6 +32,7 @@ defmodule Mobilizon.Federation.ActivityPub do
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Email.{Admin, Mailer}
require Logger
@ -318,7 +319,7 @@ defmodule Mobilizon.Federation.ActivityPub do
Convertible.model_to_as(%{follow | actor: follower, target_actor: followed}),
{:ok, follow_activity} <- create_activity(follow_as_data, local),
activity_unfollow_id <-
activity_id || "#{Mobilizon.Web.Endpoint.url()}/unfollow/#{follow_id}/activity",
activity_id || "#{Endpoint.url()}/unfollow/#{follow_id}/activity",
unfollow_data <-
make_unfollow_data(follower, followed, follow_activity, activity_unfollow_id),
{: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
"actor" => actor_url,
"object" => event_url,
"id" => "#{Mobilizon.Web.Endpoint.url()}/leave/event/#{participant.id}"
"id" => "#{Endpoint.url()}/leave/event/#{participant.id}"
},
audience <-
Audience.calculate_to_and_cc_from_mentions(participant),
@ -778,7 +779,7 @@ defmodule Mobilizon.Federation.ActivityPub do
make_accept_join_data(
follower_as_data,
Map.merge(additional, %{
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/follow/#{follower.id}",
"id" => "#{Endpoint.url()}/accept/follow/#{follower.id}",
"to" => [follower.actor.url],
"cc" => [],
"actor" => follower.target_actor.url
@ -797,7 +798,7 @@ defmodule Mobilizon.Federation.ActivityPub do
defp accept_join(%Participant{} = participant, additional) do
with {:ok, %Participant{} = 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
),
participant_as_data <- Convertible.model_to_as(participant),
@ -807,7 +808,7 @@ defmodule Mobilizon.Federation.ActivityPub do
make_accept_join_data(
participant_as_data,
Map.merge(Map.merge(audience, additional), %{
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/join/#{participant.id}"
"id" => "#{Endpoint.url()}/accept/join/#{participant.id}"
})
) do
{:ok, participant, update_data}
@ -823,7 +824,7 @@ defmodule Mobilizon.Federation.ActivityPub do
defp reject_join(%Participant{} = participant, additional) do
with {:ok, %Participant{} = participant} <-
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
),
participant_as_data <- Convertible.model_to_as(participant),
@ -839,7 +840,7 @@ defmodule Mobilizon.Federation.ActivityPub do
reject_data
|> Map.merge(audience)
|> Map.merge(%{
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/join/#{participant.id}"
"id" => "#{Endpoint.url()}/reject/join/#{participant.id}"
}) do
{:ok, participant, update_data}
else
@ -866,7 +867,7 @@ defmodule Mobilizon.Federation.ActivityPub do
reject_data
|> Map.merge(audience)
|> Map.merge(%{
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/follow/#{follower.id}"
"id" => "#{Endpoint.url()}/reject/follow/#{follower.id}"
}) do
{:ok, follower, update_data}
else

View File

@ -7,6 +7,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Share
alias Mobilizon.Storage.Repo
require Logger
@ -108,7 +109,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
end
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 =
participant.event.id
@ -132,13 +133,13 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
defp add_event_author(nil), 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
defp add_comment_author(nil), do: nil
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}} ->
url

View File

@ -17,9 +17,11 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
alias Mobilizon.GraphQL.API.Follows
alias Mobilizon.Web.Endpoint
require Logger
def init() do
def init do
# Wait for everything to settle.
Process.sleep(1000 * 5)
get_actor()
@ -28,7 +30,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
@spec get_actor() :: Actor.t() | {:error, Ecto.Changeset.t()}
def get_actor do
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
end
end

View File

@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Web.MediaProxy
@behaviour Converter
defimpl Convertible, for: ActorModel do
@ -29,14 +31,14 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
data["icon"]["url"] &&
%{
"name" => data["icon"]["name"] || "avatar",
"url" => Mobilizon.Web.MediaProxy.url(data["icon"]["url"])
"url" => MediaProxy.url(data["icon"]["url"])
}
banner =
data["image"]["url"] &&
%{
"name" => data["image"]["name"] || "banner",
"url" => Mobilizon.Web.MediaProxy.url(data["image"]["url"])
"url" => MediaProxy.url(data["image"]["url"])
}
actor_data = %{

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
internal one, and back.
"""
alias Mobilizon.Addresses
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Media.Picture

View File

@ -6,8 +6,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do
internal one, and back.
"""
alias Mobilizon.Media
alias Mobilizon.Media.Picture, as: PictureModel
alias Mobilizon.Web.Upload
@doc """
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
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url),
{:ok, %{name: name, url: url, content_type: content_type, size: size}} <-
Mobilizon.Web.Upload.store(%{body: body, name: name}),
{:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do
Mobilizon.Media.create_picture(%{
Upload.store(%{body: body, name: name}),
{:picture_exists, nil} <- {:picture_exists, Media.get_picture_by_url(url)} do
Media.create_picture(%{
"file" => %{
"url" => url,
"name" => name,

View File

@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Web.Endpoint
require Logger
@spec fetch_tags([String.t()]) :: [Tag.t()]
@ -40,7 +42,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
def build_tags(tags) do
Enum.map(tags, fn %Tag{} = tag ->
%{
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/#{tag.slug}",
"href" => Endpoint.url() <> "/tags/#{tag.slug}",
"name" => "##{tag.title}",
"type" => "Hashtag"
}
@ -60,7 +62,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
defp build_mention(%Actor{} = actor) do
%{
"href" => actor.url,
"name" => "@#{Mobilizon.Actors.Actor.preferred_username_and_domain(actor)}",
"name" => "@#{Actor.preferred_username_and_domain(actor)}",
"type" => "Mention"
}
end

View File

@ -13,11 +13,13 @@ defmodule Mobilizon.Federation.WebFinger do
alias Mobilizon.Federation.WebFinger.XmlBuilder
alias Mobilizon.Web.Endpoint
require Jason
require Logger
def host_meta do
base_url = Mobilizon.Web.Endpoint.url()
base_url = Endpoint.url()
{
:XRD,
@ -35,7 +37,7 @@ defmodule Mobilizon.Federation.WebFinger do
end
def webfinger(resource, "JSON") do
host = Mobilizon.Web.Endpoint.host()
host = Endpoint.host()
regex = ~r/(acct:)?(?<name>\w+)@#{host}/
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()
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],
"links" => [
%{"rel" => "self", "type" => "application/activity+json", "href" => actor.url},

View File

@ -9,11 +9,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
alias Mobilizon.Actors.Actor
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias Mobilizon.Service.Statistics
alias Mobilizon.Storage.Page
alias Mobilizon.Users.User
alias Mobilizon.Federation.ActivityPub.Relay

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
alias Mobilizon.{Actors, Admin, Events}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
alias Mobilizon.Events.{Event, EventParticipantStats, Participant}
alias Mobilizon.Users.User
alias Mobilizon.GraphQL.API

View File

@ -12,6 +12,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Web.{MediaProxy, Upload}
@doc """
Get a person
"""
@ -157,7 +159,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
pic = args[key][:picture]
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})
end
else
@ -236,7 +238,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
@spec proxify_avatar(Actor.t()) :: Actor.t()
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
@spec proxify_avatar(Actor.t()) :: Actor.t()
@ -244,7 +246,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
@spec proxify_banner(Actor.t()) :: Actor.t()
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
@spec proxify_banner(Actor.t()) :: Actor.t()

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
import Mobilizon.Users.Guards
alias Mobilizon.{Actors, Config, Users, Events}
alias Mobilizon.{Actors, Config, Events, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
use Absinthe.Schema.Notation
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.GraphQL.Resolvers.Admin

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.GraphQL.Schema.ReportType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Reports
alias Mobilizon.GraphQL.Resolvers.Report
alias Mobilizon.Reports
@desc "A report object"
object :report do

View File

@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Actors do
@moduledoc """
Tasks to manage actors
"""
use Mix.Task
alias Mix.Tasks
@shortdoc "Manages Mobilizon actors"
@impl Mix.Task
def run(_) do
Mix.shell().info("\nAvailable tasks:")
Mix.Tasks.Help.run(["--search", "mobilizon.actors."])
Tasks.Help.run(["--search", "mobilizon.actors."])
end
end

View File

@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Users do
@moduledoc """
Tasks to manage users
"""
use Mix.Task
alias Mix.Tasks
@shortdoc "Manages Mobilizon users"
@impl Mix.Task
def run(_) do
Mix.shell().info("\nAvailable tasks:")
Mix.Tasks.Help.run(["--search", "mobilizon.users."])
Tasks.Help.run(["--search", "mobilizon.users."])
end
end

View File

@ -2,10 +2,12 @@ defmodule Mix.Tasks.Mobilizon.Users.Show do
@moduledoc """
Task to display an user details
"""
use Mix.Task
alias Mobilizon.Actors.Actor
alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor
@shortdoc "Show a Mobilizon user details"

View File

@ -14,7 +14,7 @@ defmodule Mobilizon do
import Cachex.Spec
alias Mobilizon.Config
alias Mobilizon.{Config, Storage, Web}
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Service.Export.{Feed, ICalendar}
@ -26,7 +26,7 @@ defmodule Mobilizon do
@spec user_agent :: String.t()
def user_agent do
info = "#{Mobilizon.Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
info = "#{Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
"#{named_version()}; #{info}"
end
@ -36,9 +36,9 @@ defmodule Mobilizon do
def start(_type, _args) do
children = [
# supervisors
Mobilizon.Storage.Repo,
Mobilizon.Web.Endpoint,
{Absinthe.Subscription, [Mobilizon.Web.Endpoint]},
Storage.Repo,
Web.Endpoint,
{Absinthe.Subscription, [Web.Endpoint]},
{Oban, Application.get_env(:mobilizon, Oban)},
# workers
Guardian.DB.Token.SweeperServer,
@ -55,7 +55,7 @@ defmodule Mobilizon do
@spec config_change(keyword, keyword, [atom]) :: :ok
def config_change(changed, _new, removed) do
Mobilizon.Web.Endpoint.config_change(changed, removed)
Web.Endpoint.config_change(changed, removed)
:ok
end
@ -92,7 +92,7 @@ defmodule Mobilizon do
defp fallback_options(nil), do: []
defp fallback_options(fallback), do: [fallback: fallback(default: fallback)]
defp internal_actor() do
defp internal_actor do
%{
id: :internal_actor_init,
start: {Task, :start_link, [&ActivityPub.Relay.init/0]},

View File

@ -7,13 +7,12 @@ defmodule Mobilizon.Actors.Actor do
import Ecto.Changeset
alias Mobilizon.{Actors, Config, Crypto, Share}
alias Mobilizon.{Actors, Config, Crypto, Mention, Share}
alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member}
alias Mobilizon.Events.{Event, FeedToken, Comment}
alias Mobilizon.Events.{Comment, Event, FeedToken}
alias Mobilizon.Media.File
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias Mobilizon.Mention
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
@ -336,7 +335,7 @@ defmodule Mobilizon.Actors.Actor do
|> put_change(:followers_url, build_url(username, :followers))
|> put_change(:following_url, build_url(username, :following))
|> 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))
end
@ -376,10 +375,10 @@ defmodule Mobilizon.Actors.Actor do
"keys" => Crypto.generate_rsa_2048_private_key(),
"preferred_username" => preferred_username,
"domain" => nil,
"inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox",
"inbox_url" => "#{Endpoint.url()}/inbox",
"followers_url" => "#{url}/followers",
"following_url" => "#{url}/following",
"shared_inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox",
"shared_inbox_url" => "#{Endpoint.url()}/inbox",
"type" => :Application
}
end

View File

@ -16,6 +16,8 @@ defmodule Mobilizon.Actors do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Web.Upload
require Logger
defenum(ActorType, :actor_type, [
@ -755,7 +757,7 @@ defmodule Mobilizon.Actors do
@spec safe_remove_file(String.t(), Actor.t()) :: {:ok, Actor.t()}
defp safe_remove_file(url, %Actor{} = actor) do
case Mobilizon.Web.Upload.remove(url) do
case Upload.remove(url) do
{:ok, _value} ->
{:ok, actor}
@ -774,7 +776,7 @@ defmodule Mobilizon.Actors do
with %Ecto.Changeset{changes: %{url: new_url}} <- changes[key],
%{url: old_url} <- data |> Map.from_struct() |> Map.get(key),
false <- new_url == old_url do
Mobilizon.Web.Upload.remove(old_url)
Upload.remove(old_url)
end
end
end)

View File

@ -9,6 +9,8 @@ defmodule Mobilizon.Actors.Follower do
alias Mobilizon.Actors.Actor
alias Mobilizon.Web.Endpoint
@type t :: %__MODULE__{
approved: boolean,
url: String.t(),
@ -65,6 +67,6 @@ defmodule Mobilizon.Actors.Follower do
changeset
|> put_change(:id, uuid)
|> put_change(:url, "#{Mobilizon.Web.Endpoint.url()}/follow/#{uuid}")
|> put_change(:url, "#{Endpoint.url()}/follow/#{uuid}")
end
end

View File

@ -9,6 +9,8 @@ defmodule Mobilizon.Addresses.Address do
alias Mobilizon.Events.Event
alias Mobilizon.Web.Endpoint
@type t :: %__MODULE__{
country: String.t(),
locality: String.t(),
@ -65,8 +67,7 @@ defmodule Mobilizon.Addresses.Address do
@spec set_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
defp set_url(%Ecto.Changeset{changes: changes} = changeset) do
url =
Map.get(changes, :url, "#{Mobilizon.Web.Endpoint.url()}/address/#{Ecto.UUID.generate()}")
url = Map.get(changes, :url, "#{Endpoint.url()}/address/#{Ecto.UUID.generate()}")
put_change(changeset, :url, url)
end

View File

@ -6,31 +6,27 @@ defmodule Mobilizon.Events.Event do
use Ecto.Schema
import Ecto.Changeset
alias Ecto.Changeset
alias Mobilizon.Actors.Actor
alias Mobilizon.{Addresses, Events, Media, Mention}
alias Mobilizon.Addresses.Address
alias Mobilizon.Addresses
alias Mobilizon.Events
alias Mobilizon.Events.{
Comment,
EventOptions,
EventParticipantStats,
EventStatus,
EventVisibility,
JoinOptions,
EventParticipantStats,
Participant,
Session,
Tag,
Track
}
alias Mobilizon.Media
alias Mobilizon.Media.Picture
alias Mobilizon.Mention
alias Mobilizon.Storage.Repo
alias Mobilizon.Web.Endpoint

View File

@ -10,7 +10,7 @@ defmodule Mobilizon.Events do
import Mobilizon.Storage.Ecto
alias Ecto.{Multi, Changeset}
alias Ecto.{Changeset, Multi}
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
@ -1078,7 +1078,7 @@ defmodule Mobilizon.Events do
|> Repo.all()
end
def data() do
def data do
Dataloader.Ecto.new(Repo, query: &query/2)
end

View File

@ -10,6 +10,8 @@ defmodule Mobilizon.Media do
alias Mobilizon.Media.{File, Picture}
alias Mobilizon.Storage.Repo
alias Mobilizon.Web.Upload
@doc """
Gets a single picture.
"""
@ -62,7 +64,7 @@ defmodule Mobilizon.Media do
Multi.new()
|> Multi.delete(:picture, picture)
|> Multi.run(:remove, fn _repo, %{picture: %Picture{file: %File{url: url}}} ->
Mobilizon.Web.Upload.remove(url)
Upload.remove(url)
end)
|> Repo.transaction()

View File

@ -6,8 +6,7 @@ defmodule Mobilizon.Mention do
use Ecto.Schema
import Ecto.Changeset
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Event
alias Mobilizon.Events.Comment
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Storage.Repo
@type t :: %__MODULE__{

View File

@ -11,6 +11,8 @@ defmodule Mobilizon.Reports.Report do
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Reports.{Note, ReportStatus}
alias Mobilizon.Web.Endpoint
@type t :: %__MODULE__{
content: String.t(),
status: ReportStatus.t(),
@ -71,7 +73,7 @@ defmodule Mobilizon.Reports.Report do
@spec maybe_generate_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
defp maybe_generate_url(%Ecto.Changeset{} = changeset) do
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)
else
_ -> changeset

View File

@ -4,10 +4,12 @@ defmodule Mobilizon.Share do
"""
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
alias Mobilizon.Storage.Repo
alias Mobilizon.Actors.Actor
alias Mobilizon.Storage.Repo
@type t :: %__MODULE__{
uri: String.t(),

View File

@ -5,8 +5,8 @@ defmodule Mobilizon.Service.Export.ICalendar do
alias Mobilizon.{Actors, Events, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Users.User
@doc """

View File

@ -12,6 +12,8 @@ defmodule Mobilizon.Service.Formatter do
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Formatter.HTML
alias Mobilizon.Web.Endpoint
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
@ -52,7 +54,7 @@ defmodule Mobilizon.Service.Formatter do
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
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, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}}

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Addok do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -10,8 +10,8 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -8,8 +8,8 @@ defmodule Mobilizon.Service.Geospatial.Mimirsbrunn do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.Pelias do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Photon do
"""
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger

View File

@ -5,10 +5,11 @@ defmodule Mobilizon.Service.Metadata.Instance do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Config
alias Mobilizon.Web.Endpoint
def build_tags() do
def build_tags do
description = process_description(Config.instance_description())
title = "#{Config.instance_name()} - Mobilizon"

View File

@ -3,10 +3,11 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
Worker to build search results
"""
alias Ecto.Adapters.SQL
alias Mobilizon.Events
alias Mobilizon.Events.Event
alias Mobilizon.Storage.Repo
alias Ecto.Adapters.SQL
use Mobilizon.Service.Workers.Helper, queue: "search"

View File

@ -13,11 +13,11 @@ defmodule Mobilizon.Web.Email.Admin do
alias Mobilizon.Reports.Report
alias Mobilizon.Users.User
alias Mobilizon.Web.Email
alias Mobilizon.Web.{Email, Gettext}
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
def report(%User{email: email}, %Report{} = report, locale \\ "en") do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(

View File

@ -3,8 +3,7 @@ defmodule Mobilizon.Web.Email.Checker do
Provides a function to test emails against a "not so bad" regex.
"""
# TODO: simplify me!
@email_regex ~r/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
@email_regex ~r/^[\w.!#$%&*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i
@doc """
Returns whether the email is valid.

View File

@ -7,6 +7,8 @@ defmodule Mobilizon.Web.Email do
alias Mobilizon.Config
alias Mobilizon.Web.EmailView
@spec base_email(keyword()) :: Bamboo.Email.t()
def base_email(args) do
instance = Config.instance_config()
@ -16,7 +18,7 @@ defmodule Mobilizon.Web.Email do
|> from({Config.instance_name(), Config.instance_email_from()})
|> put_header("Reply-To", Config.instance_email_reply_to())
|> assign(:instance, instance)
|> put_html_layout({Mobilizon.Web.EmailView, "email.html"})
|> put_text_layout({Mobilizon.Web.EmailView, "email.text"})
|> put_html_layout({EmailView, "email.html"})
|> put_text_layout({EmailView, "email.text"})
end
end

View File

@ -15,7 +15,7 @@ defmodule Mobilizon.Web.Email.Event do
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User
alias Mobilizon.Web.Email
alias Mobilizon.Web.{Email, Gettext}
@important_changes [:title, :begins_on, :ends_on, :status]
@ -29,7 +29,7 @@ defmodule Mobilizon.Web.Email.Event do
changes,
locale \\ "en"
) do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(

View File

@ -9,11 +9,11 @@ defmodule Mobilizon.Web.Email.Participation do
import Mobilizon.Web.Gettext
alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Participant
alias Mobilizon.Users.User
alias Mobilizon.Web.Email
alias Mobilizon.Web.{Email, Gettext}
@doc """
Send emails to local user
@ -46,7 +46,7 @@ defmodule Mobilizon.Web.Email.Participation do
%Participant{event: event, role: :rejected},
locale
) do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(
@ -67,7 +67,7 @@ defmodule Mobilizon.Web.Email.Participation do
%Participant{event: event, role: :participant},
locale
) do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(

View File

@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.User do
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User
alias Mobilizon.Web.Email
alias Mobilizon.Web.{Email, Gettext}
require Logger
@ -22,7 +22,7 @@ defmodule Mobilizon.Web.Email.User do
%User{email: email, confirmation_token: confirmation_token},
locale \\ "en"
) do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(
@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.User do
%User{email: email, reset_password_token: reset_password_token},
locale \\ "en"
) do
Mobilizon.Web.Gettext.put_locale(locale)
Gettext.put_locale(locale)
subject =
gettext(

View File

@ -14,6 +14,8 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
alias Mobilizon.Config
alias Mobilizon.Web.{ReverseProxy, Upload}
require Logger
# no slashes
@ -41,7 +43,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
conn
end
config = Config.get([Mobilizon.Web.Upload])
config = Config.get([Upload])
with uploader <- Keyword.fetch!(config, :uploader),
proxy_remote = Keyword.get(config, :proxy_remote, false),
@ -76,7 +78,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do
end
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
defp get_media(conn, {:url, url}, _, _) do

View File

@ -10,6 +10,8 @@ defmodule Mobilizon.Web.MediaProxy do
alias Mobilizon.Config
alias Mobilizon.Web.Endpoint
@base64_opts [padding: false]
def url(nil), do: nil
@ -22,7 +24,7 @@ defmodule Mobilizon.Web.MediaProxy do
config = Application.get_env(:mobilizon, :media_proxy, [])
if !Keyword.get(config, :enabled, false) or
String.starts_with?(url, Mobilizon.Web.Endpoint.url()) do
String.starts_with?(url, Endpoint.url()) do
url
else
encode_url(url)
@ -30,7 +32,7 @@ defmodule Mobilizon.Web.MediaProxy do
end
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
# https://git.pleroma.social/pleroma/pleroma/issues/580
@ -52,7 +54,7 @@ defmodule Mobilizon.Web.MediaProxy do
end
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)
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
[
Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()),
Config.get([:media_proxy, :base_url], Endpoint.url()),
"proxy",
sig_base64,
url_base64,

View File

@ -69,6 +69,8 @@ defmodule Mobilizon.Web.ReverseProxy do
alias Plug.Conn
alias Mobilizon.Web.MediaProxy
require Logger
@type option ::
@ -111,7 +113,7 @@ defmodule Mobilizon.Web.ReverseProxy do
req_headers = build_req_headers(conn.req_headers, opts)
opts =
if filename = Mobilizon.Web.MediaProxy.filename(url) do
if filename = MediaProxy.filename(url) do
Keyword.put_new(opts, :attachment_name, filename)
else
opts

View File

@ -36,6 +36,7 @@ defmodule Mobilizon.Web.Upload do
alias Mobilizon.Config
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Upload.{Filter, MIME, Uploader}
require Logger
@ -91,7 +92,7 @@ defmodule Mobilizon.Web.Upload do
def remove(url, opts \\ []) do
with opts <- get_opts(opts),
%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)
else
%URI{} = _uri ->
@ -129,7 +130,7 @@ defmodule Mobilizon.Web.Upload do
Keyword.get(
opts,
:base_url,
Config.get([__MODULE__, :base_url], Mobilizon.Web.Endpoint.url())
Config.get([__MODULE__, :base_url], Endpoint.url())
)
}
end

View File

@ -49,7 +49,7 @@ defmodule Mobilizon.Web.ErrorView do
render("500.html", assigns)
end
defp index_file_path() do
defp index_file_path do
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
end
end

View File

@ -22,6 +22,8 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
alias Mobilizon.GraphQL.API
alias Mobilizon.Web.Endpoint
setup_all do
HTTPoison.start()
end
@ -961,7 +963,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
}
expected_tag = %{
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu",
"href" => Endpoint.url() <> "/tags/2hu",
"type" => "Hashtag",
"name" => "#2hu"
}
@ -996,7 +998,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
expected_tag = %{
"href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu",
"href" => Endpoint.url() <> "/tags/2hu",
"type" => "Hashtag",
"name" => "#2hu"
}

View File

@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.WebFingerTest do
alias Mobilizon.Federation.WebFinger
alias Mobilizon.Web.Endpoint
@mastodon_account "tcit@social.tcit.fr"
@mastodon_account_username "tcit"
@pleroma_account "lain@pleroma.soykaf.com"
@ -24,7 +26,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
test "returns a link to the xml lrdd" do
host_info = WebFinger.host_meta()
assert String.contains?(host_info, Mobilizon.Web.Endpoint.url())
assert String.contains?(host_info, Endpoint.url())
end
end
@ -34,7 +36,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
{:ok, result} =
WebFinger.webfinger(
"#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}",
"#{actor.preferred_username}@#{Endpoint.host()}",
"JSON"
)

View File

@ -10,8 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.GraphQL.API
alias Mobilizon.GraphQL.AbsintheHelpers
alias Mobilizon.GraphQL.{AbsintheHelpers, API}
describe "Resolver: List the action logs" do
@note_content "This a note on a report"

View File

@ -9,6 +9,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
alias Mobilizon.GraphQL.AbsintheHelpers
alias Mobilizon.Web.Endpoint
@non_existent_username "nonexistent"
describe "Person Resolver" do
@ -120,8 +122,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
actor.preferred_username
assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~
Mobilizon.Web.Endpoint.url()
assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~ Endpoint.url()
end
test "create_person/3 creates a new identity", context do
@ -255,7 +256,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
"The beautiful atlantic way"
assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~
Mobilizon.Web.Endpoint.url() <> "/media/"
Endpoint.url() <> "/media/"
end
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"]["name"] == "The beautiful atlantic way"
assert res_person["banner"]["url"] =~ Mobilizon.Web.Endpoint.url() <> "/media/"
assert res_person["banner"]["url"] =~ Endpoint.url() <> "/media/"
end
test "update_person/3 should fail to update a not owned identity", context do

View File

@ -8,6 +8,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
alias Mobilizon.GraphQL.AbsintheHelpers
alias Mobilizon.Web.Endpoint
setup %{conn: conn} do
user = insert(: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"]["url"] =~
Mobilizon.Web.Endpoint.url()
assert json_response(res, 200)["data"]["picture"]["url"] =~ Endpoint.url()
end
test "picture/3 returns nothing on a non-existent picture", context do

View File

@ -5,9 +5,9 @@ defmodule Mobilizon.ActorsTest do
import Mobilizon.Factory
alias Mobilizon.{Actors, Config, Users, Events, Tombstone}
alias Mobilizon.{Actors, Config, Events, Tombstone, Users}
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Media.File, as: FileModel
alias Mobilizon.Service.Workers
alias Mobilizon.Storage.Page

View File

@ -1,12 +1,14 @@
defmodule Mobilizon.Service.ICalendarTest do
alias Mobilizon.Service.Export.ICalendar, as: ICalendarService
alias Mobilizon.Events.Event
alias Mobilizon.Addresses.Address
alias ICalendar.Value
use Mobilizon.DataCase
import Mobilizon.Factory
alias ICalendar.Value
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event
alias Mobilizon.Service.Export.ICalendar, as: ICalendarService
describe "export an event to ics" do
test "export basic infos" do
%Event{} = event = insert(:event)

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
import Mock
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Addok
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Addok
@httpoison_headers [
{"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.MapQuestTest do
import Mock
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.MapQuest
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.MapQuest
@httpoison_headers [
{"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
import Mock
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Nominatim
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Nominatim
@httpoison_headers [
{"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.PhotonTest do
import Mock
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Photon
alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Photon
@httpoison_headers [
{"User-Agent",

View File

@ -20,6 +20,8 @@ defmodule Mobilizon.Web.ConnCase do
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User
alias Mobilizon.Web.Auth
using do
quote do
# Import conveniences for testing with connections
@ -30,7 +32,7 @@ defmodule Mobilizon.Web.ConnCase do
@endpoint Mobilizon.Web.Endpoint
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
|> Plug.Conn.put_req_header("authorization", "Bearer #{token}")

View File

@ -8,9 +8,8 @@ defmodule Mobilizon.Factory do
alias Mobilizon.Actors.Actor
alias Mobilizon.Crypto
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.{Endpoint, Upload}
alias Mobilizon.Web.Router.Helpers, as: Routes
alias Mobilizon.Web.Upload
def user_factory do
%Mobilizon.Users.User{
@ -60,7 +59,7 @@ defmodule Mobilizon.Factory do
target_actor: build(:actor),
actor: build(:actor),
id: uuid,
url: "#{Mobilizon.Web.Endpoint.url()}/follows/#{uuid}"
url: "#{Endpoint.url()}/follows/#{uuid}"
}
end

View File

@ -1,10 +1,12 @@
defmodule Mix.Tasks.Mobilizon.ActorsTest do
use Mobilizon.DataCase
alias Mobilizon.Actors.Actor
alias Mix.Tasks.Mobilizon.Actors.Show
import Mobilizon.Factory
alias Mix.Tasks.Mobilizon.Actors.Show
alias Mobilizon.Actors.Actor
Mix.shell(Mix.Shell.Process)
@username "someone"

View File

@ -3,9 +3,10 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
import Mobilizon.Factory
alias Mix.Tasks.Mobilizon.Users.{Delete, Modify, New, Show}
alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mix.Tasks.Mobilizon.Users.{New, Delete, Show, Modify}
Mix.shell(Mix.Shell.Process)

View File

@ -16,8 +16,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Web.ActivityPub.ActorView
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.PageView
alias Mobilizon.Web.{Endpoint, PageView}
alias Mobilizon.Web.Router.Helpers, as: Routes
setup_all do
@ -104,7 +103,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
conn =
conn
|> assign(:valid_signature, true)
|> post("#{Mobilizon.Web.Endpoint.url()}/inbox", data)
|> post("#{Endpoint.url()}/inbox", data)
assert "ok" == json_response(conn, 200)
:timer.sleep(500)

View File

@ -11,6 +11,8 @@ defmodule Mobilizon.Web.WebFingerControllerTest do
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.WebFinger
alias Mobilizon.Web.Endpoint
setup_all do
Mobilizon.Config.put([:instance, :federating], true)
@ -22,7 +24,7 @@ defmodule Mobilizon.Web.WebFingerControllerTest do
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=\"#{
Mobilizon.Web.Endpoint.url()
Endpoint.url()
}/.well-known/webfinger?resource={uri}\" type=\"application/xrd+xml\" /></XRD>"
assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers

View File

@ -10,7 +10,7 @@ defmodule Mobilizon.Web.MediaProxyTest do
alias Mobilizon.Config
alias Mobilizon.Web.MediaProxyController
alias Mobilizon.Web.{Endpoint, MediaProxyController}
setup do
enabled = Config.get([:media_proxy, :enabled])
@ -35,8 +35,8 @@ defmodule Mobilizon.Web.MediaProxyTest do
end
test "ignores local url" do
local_url = Mobilizon.Web.Endpoint.url() <> "/hello"
local_root = Mobilizon.Web.Endpoint.url()
local_url = Endpoint.url() <> "/hello"
local_root = Endpoint.url()
assert url(local_url) == local_url
assert url(local_root) == local_root
end
@ -47,7 +47,7 @@ defmodule Mobilizon.Web.MediaProxyTest do
assert String.starts_with?(
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")
@ -84,16 +84,16 @@ defmodule Mobilizon.Web.MediaProxyTest do
end
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 ->
Config.put([Mobilizon.Web.Endpoint, :secret_key_base], secret_key_base)
Config.put([Endpoint, :secret_key_base], secret_key_base)
end)
encoded = url("https://pleroma.social")
Config.put(
[Mobilizon.Web.Endpoint, :secret_key_base],
[Endpoint, :secret_key_base],
"00000000000000000000000000000000000000000000000"
)

View File

@ -8,7 +8,7 @@ defmodule Mobilizon.UploadTest do
alias Mobilizon.Config
alias Mobilizon.Web.Upload
alias Mobilizon.Web.{Endpoint, Upload}
alias Mobilizon.Web.Upload.Uploader
describe "Storing a file with the Local uploader" do
@ -31,7 +31,7 @@ defmodule Mobilizon.UploadTest do
size: 13_227
} = data
assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/")
assert String.starts_with?(url, Endpoint.url() <> "/media/")
end
test "returns a media url with configured base_url" do
@ -59,10 +59,10 @@ defmodule Mobilizon.UploadTest do
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 ==
Mobilizon.Web.Endpoint.url() <>
Endpoint.url() <>
"/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg"
end
@ -88,7 +88,7 @@ defmodule Mobilizon.UploadTest do
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"
end
@ -140,7 +140,7 @@ defmodule Mobilizon.UploadTest do
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"
end
@ -212,7 +212,7 @@ defmodule Mobilizon.UploadTest do
content_type: "image/jpeg"
} = 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)
{Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url}

View File

@ -4,16 +4,18 @@ defmodule Mobilizon.Web.ErrorViewTest do
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
alias Mobilizon.Web.ErrorView
test "renders 404.html" do
assert render_to_string(Mobilizon.Web.ErrorView, "404.html", []) =~
assert render_to_string(ErrorView, "404.html", []) =~
"We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue."
end
test "render 500.html" do
assert render_to_string(Mobilizon.Web.ErrorView, "500.html", []) == "Internal server error"
assert render_to_string(ErrorView, "500.html", []) == "Internal server error"
end
test "render any other" do
assert render_to_string(Mobilizon.Web.ErrorView, "505.html", []) == "Internal server error"
assert render_to_string(ErrorView, "505.html", []) == "Internal server error"
end
end