From bf2a36314bd3fe7817c8982c8d341f873e1a5afb Mon Sep 17 00:00:00 2001 From: rustra Date: Tue, 28 Jan 2020 19:18:33 +0100 Subject: [PATCH 1/2] Implement Credo software design suggestions --- lib/federation/activity_pub/activity_pub.ex | 17 +++++++++-------- lib/federation/activity_pub/audience.ex | 7 ++++--- lib/federation/activity_pub/relay.ex | 4 +++- .../activity_stream/converter/actor.ex | 6 ++++-- .../activity_stream/converter/picture.ex | 9 ++++++--- .../activity_stream/converter/utils.ex | 6 ++++-- lib/federation/web_finger/web_finger.ex | 8 +++++--- lib/graphql/resolvers/person.ex | 8 +++++--- lib/mix/tasks/mobilizon/actors.ex | 5 ++++- lib/mix/tasks/mobilizon/users.ex | 5 ++++- lib/mobilizon.ex | 12 ++++++------ lib/mobilizon/actors/actor.ex | 6 +++--- lib/mobilizon/actors/actors.ex | 6 ++++-- lib/mobilizon/actors/follower.ex | 4 +++- lib/mobilizon/addresses/address.ex | 5 +++-- lib/mobilizon/media/media.ex | 4 +++- lib/mobilizon/reports/report.ex | 4 +++- lib/service/formatter/formatter.ex | 4 +++- lib/web/email/admin.ex | 4 ++-- lib/web/email/email.ex | 6 ++++-- lib/web/email/event.ex | 4 ++-- lib/web/email/participation.ex | 6 +++--- lib/web/email/user.ex | 6 +++--- lib/web/plugs/uploaded_media.ex | 6 ++++-- lib/web/proxy/media_proxy.ex | 10 ++++++---- lib/web/proxy/reverse_proxy.ex | 4 +++- lib/web/upload/upload.ex | 5 +++-- .../activity_pub/transmogrifier_test.exs | 6 ++++-- test/federation/web_finger/web_finger_test.exs | 6 ++++-- test/graphql/resolvers/person_test.exs | 9 +++++---- test/graphql/resolvers/picture_test.exs | 5 +++-- test/support/conn_case.ex | 4 +++- test/support/factory.ex | 5 ++--- .../activity_pub_controller_test.exs | 5 ++--- .../controllers/webfinger_controller_test.exs | 4 +++- test/web/proxy/media_proxy_test.exs | 14 +++++++------- test/web/upload/upload_test.exs | 14 +++++++------- 37 files changed, 146 insertions(+), 97 deletions(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index d97b9d538..5bbced443 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -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 diff --git a/lib/federation/activity_pub/audience.ex b/lib/federation/activity_pub/audience.ex index 7f7566865..d8992f2b8 100644 --- a/lib/federation/activity_pub/audience.ex +++ b/lib/federation/activity_pub/audience.ex @@ -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 diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index 800fe98d2..682a498a6 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -17,6 +17,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do alias Mobilizon.GraphQL.API.Follows + alias Mobilizon.Web.Endpoint + require Logger def init() do @@ -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 diff --git a/lib/federation/activity_stream/converter/actor.ex b/lib/federation/activity_stream/converter/actor.ex index f3bcf00a6..17c04880b 100644 --- a/lib/federation/activity_stream/converter/actor.ex +++ b/lib/federation/activity_stream/converter/actor.ex @@ -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 = %{ diff --git a/lib/federation/activity_stream/converter/picture.ex b/lib/federation/activity_stream/converter/picture.ex index 6fdc01736..fc7d69792 100644 --- a/lib/federation/activity_stream/converter/picture.ex +++ b/lib/federation/activity_stream/converter/picture.ex @@ -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, diff --git a/lib/federation/activity_stream/converter/utils.ex b/lib/federation/activity_stream/converter/utils.ex index 7cd7203d2..a47cc6f79 100644 --- a/lib/federation/activity_stream/converter/utils.ex +++ b/lib/federation/activity_stream/converter/utils.ex @@ -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 diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index 1aec9a27a..4f3d28599 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -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:)?(?\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}, diff --git a/lib/graphql/resolvers/person.ex b/lib/graphql/resolvers/person.ex index b16a1f76d..899c996ca 100644 --- a/lib/graphql/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -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() diff --git a/lib/mix/tasks/mobilizon/actors.ex b/lib/mix/tasks/mobilizon/actors.ex index ec032daa2..1e3bb1ce2 100644 --- a/lib/mix/tasks/mobilizon/actors.ex +++ b/lib/mix/tasks/mobilizon/actors.ex @@ -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 diff --git a/lib/mix/tasks/mobilizon/users.ex b/lib/mix/tasks/mobilizon/users.ex index 6365b5519..e61a4e77a 100644 --- a/lib/mix/tasks/mobilizon/users.ex +++ b/lib/mix/tasks/mobilizon/users.ex @@ -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 diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index b5f0589b6..1cd2529c8 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -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 diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 6857039b1..52d55790b 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -336,7 +336,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 +376,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 diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 5b43d3bc0..be0945793 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -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) diff --git a/lib/mobilizon/actors/follower.ex b/lib/mobilizon/actors/follower.ex index a397677d8..e77bc0154 100644 --- a/lib/mobilizon/actors/follower.ex +++ b/lib/mobilizon/actors/follower.ex @@ -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 diff --git a/lib/mobilizon/addresses/address.ex b/lib/mobilizon/addresses/address.ex index c7a4f2fdb..5706748a6 100644 --- a/lib/mobilizon/addresses/address.ex +++ b/lib/mobilizon/addresses/address.ex @@ -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 diff --git a/lib/mobilizon/media/media.ex b/lib/mobilizon/media/media.ex index ccb336a74..549f84bd6 100644 --- a/lib/mobilizon/media/media.ex +++ b/lib/mobilizon/media/media.ex @@ -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() diff --git a/lib/mobilizon/reports/report.ex b/lib/mobilizon/reports/report.ex index 8aa90840c..c766c1ac5 100644 --- a/lib/mobilizon/reports/report.ex +++ b/lib/mobilizon/reports/report.ex @@ -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 diff --git a/lib/service/formatter/formatter.ex b/lib/service/formatter/formatter.ex index 6cfc4dcea..a15b1c2b8 100644 --- a/lib/service/formatter/formatter.ex +++ b/lib/service/formatter/formatter.ex @@ -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 = "" {link, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}} diff --git a/lib/web/email/admin.ex b/lib/web/email/admin.ex index b17349471..00268acc8 100644 --- a/lib/web/email/admin.ex +++ b/lib/web/email/admin.ex @@ -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( diff --git a/lib/web/email/email.ex b/lib/web/email/email.ex index c0e1b788c..f61395bba 100644 --- a/lib/web/email/email.ex +++ b/lib/web/email/email.ex @@ -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 diff --git a/lib/web/email/event.ex b/lib/web/email/event.ex index 3b8150e0b..ee069b564 100644 --- a/lib/web/email/event.ex +++ b/lib/web/email/event.ex @@ -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.{Gettext, Email} @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( diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index df9096ccc..83464dd2c 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.Participation do alias Mobilizon.Actors.Actor alias Mobilizon.Events.Participant - 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( diff --git a/lib/web/email/user.ex b/lib/web/email/user.ex index de6091d63..33b04621e 100644 --- a/lib/web/email/user.ex +++ b/lib/web/email/user.ex @@ -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( diff --git a/lib/web/plugs/uploaded_media.ex b/lib/web/plugs/uploaded_media.ex index 53b9e43a5..7f592aa02 100644 --- a/lib/web/plugs/uploaded_media.ex +++ b/lib/web/plugs/uploaded_media.ex @@ -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 diff --git a/lib/web/proxy/media_proxy.ex b/lib/web/proxy/media_proxy.ex index 35611c844..7fbd9d59b 100644 --- a/lib/web/proxy/media_proxy.ex +++ b/lib/web/proxy/media_proxy.ex @@ -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, diff --git a/lib/web/proxy/reverse_proxy.ex b/lib/web/proxy/reverse_proxy.ex index f0f68c08b..46a488ccb 100644 --- a/lib/web/proxy/reverse_proxy.ex +++ b/lib/web/proxy/reverse_proxy.ex @@ -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 diff --git a/lib/web/upload/upload.ex b/lib/web/upload/upload.ex index ae2845d7b..bfb636aaa 100644 --- a/lib/web/upload/upload.ex +++ b/lib/web/upload/upload.ex @@ -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 diff --git a/test/federation/activity_pub/transmogrifier_test.exs b/test/federation/activity_pub/transmogrifier_test.exs index f2f57be3e..fd65c52ea 100644 --- a/test/federation/activity_pub/transmogrifier_test.exs +++ b/test/federation/activity_pub/transmogrifier_test.exs @@ -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" } diff --git a/test/federation/web_finger/web_finger_test.exs b/test/federation/web_finger/web_finger_test.exs index a995c4d39..6aba2c594 100644 --- a/test/federation/web_finger/web_finger_test.exs +++ b/test/federation/web_finger/web_finger_test.exs @@ -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" ) diff --git a/test/graphql/resolvers/person_test.exs b/test/graphql/resolvers/person_test.exs index 200944263..1f576c684 100644 --- a/test/graphql/resolvers/person_test.exs +++ b/test/graphql/resolvers/person_test.exs @@ -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 diff --git a/test/graphql/resolvers/picture_test.exs b/test/graphql/resolvers/picture_test.exs index b2a61538e..c4ab3858d 100644 --- a/test/graphql/resolvers/picture_test.exs +++ b/test/graphql/resolvers/picture_test.exs @@ -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 diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index ee76c8fa9..8b1862108 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -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}") diff --git a/test/support/factory.ex b/test/support/factory.ex index 00674c50e..87bd5f935 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -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 diff --git a/test/web/controllers/activity_pub_controller_test.exs b/test/web/controllers/activity_pub_controller_test.exs index bd4ad85f9..8de6fa884 100644 --- a/test/web/controllers/activity_pub_controller_test.exs +++ b/test/web/controllers/activity_pub_controller_test.exs @@ -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) diff --git a/test/web/controllers/webfinger_controller_test.exs b/test/web/controllers/webfinger_controller_test.exs index 03a26b6c6..5d407bdbe 100644 --- a/test/web/controllers/webfinger_controller_test.exs +++ b/test/web/controllers/webfinger_controller_test.exs @@ -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) == "" assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers diff --git a/test/web/proxy/media_proxy_test.exs b/test/web/proxy/media_proxy_test.exs index 60363db66..ced609d9f 100644 --- a/test/web/proxy/media_proxy_test.exs +++ b/test/web/proxy/media_proxy_test.exs @@ -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" ) diff --git a/test/web/upload/upload_test.exs b/test/web/upload/upload_test.exs index b2845a929..f5cc995be 100644 --- a/test/web/upload/upload_test.exs +++ b/test/web/upload/upload_test.exs @@ -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} From ca5a4fd83c6dd317dbd61565e443e8b92ebc1ece Mon Sep 17 00:00:00 2001 From: rustra Date: Tue, 28 Jan 2020 20:15:59 +0100 Subject: [PATCH 2/2] Fix Credo code readability issues --- lib/federation/activity_pub/activity_pub.ex | 2 +- lib/federation/activity_pub/relay.ex | 2 +- lib/federation/activity_stream/converter/event.ex | 2 +- lib/graphql/resolvers/admin.ex | 4 ++-- lib/graphql/resolvers/event.ex | 2 +- lib/graphql/resolvers/user.ex | 2 +- lib/graphql/schema/admin.ex | 2 +- lib/graphql/schema/report.ex | 2 +- lib/mix/tasks/mobilizon/users/show.ex | 4 +++- lib/mobilizon.ex | 2 +- lib/mobilizon/actors/actor.ex | 5 ++--- lib/mobilizon/events/event.ex | 10 +++------- lib/mobilizon/events/events.ex | 4 ++-- lib/mobilizon/mentions/mention.ex | 3 +-- lib/mobilizon/share.ex | 4 +++- lib/service/export/icalendar.ex | 2 +- lib/service/geospatial/addok.ex | 2 +- lib/service/geospatial/map_quest.ex | 2 +- lib/service/geospatial/mimirsbrunn.ex | 2 +- lib/service/geospatial/nominatim.ex | 2 +- lib/service/geospatial/pelias.ex | 2 +- lib/service/geospatial/photon.ex | 2 +- lib/service/metadata/instance.ex | 3 ++- lib/service/workers/build_search.ex | 3 ++- lib/web/email/checker.ex | 3 +-- lib/web/email/event.ex | 2 +- lib/web/email/participation.ex | 2 +- lib/web/views/error_view.ex | 2 +- test/graphql/resolvers/admin_test.exs | 3 +-- test/mobilizon/actors/actors_test.exs | 4 ++-- test/service/export/icalendar_test.exs | 10 ++++++---- test/service/geospatial/addok_test.exs | 2 +- test/service/geospatial/map_quest_test.exs | 2 +- test/service/geospatial/nominatim_test.exs | 2 +- test/service/geospatial/photon_test.exs | 2 +- test/tasks/actors_test.exs | 6 ++++-- test/tasks/users_test.exs | 3 ++- test/web/views/error_view_test.exs | 8 +++++--- 38 files changed, 63 insertions(+), 58 deletions(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 5bbced443..285057e1f 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -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 diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index 682a498a6..38b239594 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -21,7 +21,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do require Logger - def init() do + def init do # Wait for everything to settle. Process.sleep(1000 * 5) get_actor() diff --git a/lib/federation/activity_stream/converter/event.ex b/lib/federation/activity_stream/converter/event.ex index 0a6adfd7b..86fd06321 100644 --- a/lib/federation/activity_stream/converter/event.ex +++ b/lib/federation/activity_stream/converter/event.ex @@ -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 diff --git a/lib/graphql/resolvers/admin.ex b/lib/graphql/resolvers/admin.ex index 9a99421d5..094bf9d56 100644 --- a/lib/graphql/resolvers/admin.ex +++ b/lib/graphql/resolvers/admin.ex @@ -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 diff --git a/lib/graphql/resolvers/event.ex b/lib/graphql/resolvers/event.ex index 8864091c5..15a20123e 100644 --- a/lib/graphql/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -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 diff --git a/lib/graphql/resolvers/user.ex b/lib/graphql/resolvers/user.ex index 2194f41fd..f70a62d01 100644 --- a/lib/graphql/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -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 diff --git a/lib/graphql/schema/admin.ex b/lib/graphql/schema/admin.ex index b7dc5cb96..60e23a63b 100644 --- a/lib/graphql/schema/admin.ex +++ b/lib/graphql/schema/admin.ex @@ -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 diff --git a/lib/graphql/schema/report.ex b/lib/graphql/schema/report.ex index db3890f4d..41245c87c 100644 --- a/lib/graphql/schema/report.ex +++ b/lib/graphql/schema/report.ex @@ -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 diff --git a/lib/mix/tasks/mobilizon/users/show.ex b/lib/mix/tasks/mobilizon/users/show.ex index 515c62caa..bd1405fda 100644 --- a/lib/mix/tasks/mobilizon/users/show.ex +++ b/lib/mix/tasks/mobilizon/users/show.ex @@ -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" diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index 1cd2529c8..15101ae80 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -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]}, diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 52d55790b..a6790f8e8 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -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 diff --git a/lib/mobilizon/events/event.ex b/lib/mobilizon/events/event.ex index 2702100b6..13172705d 100644 --- a/lib/mobilizon/events/event.ex +++ b/lib/mobilizon/events/event.ex @@ -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 diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index c26d615f2..372b99a51 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -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 diff --git a/lib/mobilizon/mentions/mention.ex b/lib/mobilizon/mentions/mention.ex index dfded3463..cab57fe2e 100644 --- a/lib/mobilizon/mentions/mention.ex +++ b/lib/mobilizon/mentions/mention.ex @@ -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__{ diff --git a/lib/mobilizon/share.ex b/lib/mobilizon/share.ex index a6408fd91..734628340 100644 --- a/lib/mobilizon/share.ex +++ b/lib/mobilizon/share.ex @@ -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(), diff --git a/lib/service/export/icalendar.ex b/lib/service/export/icalendar.ex index 32ec1625e..cb5fad32a 100644 --- a/lib/service/export/icalendar.ex +++ b/lib/service/export/icalendar.ex @@ -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 """ diff --git a/lib/service/geospatial/addok.ex b/lib/service/geospatial/addok.ex index 8428973b9..ab4111746 100644 --- a/lib/service/geospatial/addok.ex +++ b/lib/service/geospatial/addok.ex @@ -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 diff --git a/lib/service/geospatial/map_quest.ex b/lib/service/geospatial/map_quest.ex index 5f567224d..838d1ce87 100644 --- a/lib/service/geospatial/map_quest.ex +++ b/lib/service/geospatial/map_quest.ex @@ -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 diff --git a/lib/service/geospatial/mimirsbrunn.ex b/lib/service/geospatial/mimirsbrunn.ex index cb4156bd1..8449aa129 100644 --- a/lib/service/geospatial/mimirsbrunn.ex +++ b/lib/service/geospatial/mimirsbrunn.ex @@ -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 diff --git a/lib/service/geospatial/nominatim.ex b/lib/service/geospatial/nominatim.ex index f9953c082..58b4bed3d 100644 --- a/lib/service/geospatial/nominatim.ex +++ b/lib/service/geospatial/nominatim.ex @@ -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 diff --git a/lib/service/geospatial/pelias.ex b/lib/service/geospatial/pelias.ex index 386b7d1fb..12603a232 100644 --- a/lib/service/geospatial/pelias.ex +++ b/lib/service/geospatial/pelias.ex @@ -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 diff --git a/lib/service/geospatial/photon.ex b/lib/service/geospatial/photon.ex index 364a6c147..7b9e66fbc 100644 --- a/lib/service/geospatial/photon.ex +++ b/lib/service/geospatial/photon.ex @@ -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 diff --git a/lib/service/metadata/instance.ex b/lib/service/metadata/instance.ex index a6b71efcf..cfa15f9da 100644 --- a/lib/service/metadata/instance.ex +++ b/lib/service/metadata/instance.ex @@ -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" diff --git a/lib/service/workers/build_search.ex b/lib/service/workers/build_search.ex index 21a4bce8d..184f5ad39 100644 --- a/lib/service/workers/build_search.ex +++ b/lib/service/workers/build_search.ex @@ -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" diff --git a/lib/web/email/checker.ex b/lib/web/email/checker.ex index 9a2aec50f..e99fbcd64 100644 --- a/lib/web/email/checker.ex +++ b/lib/web/email/checker.ex @@ -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. diff --git a/lib/web/email/event.ex b/lib/web/email/event.ex index ee069b564..e1ae50eb1 100644 --- a/lib/web/email/event.ex +++ b/lib/web/email/event.ex @@ -15,7 +15,7 @@ defmodule Mobilizon.Web.Email.Event do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias Mobilizon.Web.{Gettext, Email} + alias Mobilizon.Web.{Email, Gettext} @important_changes [:title, :begins_on, :ends_on, :status] diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index 83464dd2c..5bf7d7e83 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -9,9 +9,9 @@ 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, Gettext} diff --git a/lib/web/views/error_view.ex b/lib/web/views/error_view.ex index 848b8aa0d..f5ad17bd6 100644 --- a/lib/web/views/error_view.ex +++ b/lib/web/views/error_view.ex @@ -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 diff --git a/test/graphql/resolvers/admin_test.exs b/test/graphql/resolvers/admin_test.exs index e8a1c699d..affb40fb1 100644 --- a/test/graphql/resolvers/admin_test.exs +++ b/test/graphql/resolvers/admin_test.exs @@ -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" diff --git a/test/mobilizon/actors/actors_test.exs b/test/mobilizon/actors/actors_test.exs index 2a2db0921..820eb1c7c 100644 --- a/test/mobilizon/actors/actors_test.exs +++ b/test/mobilizon/actors/actors_test.exs @@ -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 diff --git a/test/service/export/icalendar_test.exs b/test/service/export/icalendar_test.exs index aae737b63..94c170654 100644 --- a/test/service/export/icalendar_test.exs +++ b/test/service/export/icalendar_test.exs @@ -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) diff --git a/test/service/geospatial/addok_test.exs b/test/service/geospatial/addok_test.exs index 7dbf948dc..8680c65bb 100644 --- a/test/service/geospatial/addok_test.exs +++ b/test/service/geospatial/addok_test.exs @@ -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", diff --git a/test/service/geospatial/map_quest_test.exs b/test/service/geospatial/map_quest_test.exs index 00d535cae..2aeb7c016 100644 --- a/test/service/geospatial/map_quest_test.exs +++ b/test/service/geospatial/map_quest_test.exs @@ -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", diff --git a/test/service/geospatial/nominatim_test.exs b/test/service/geospatial/nominatim_test.exs index b64bcb935..eeb4dbb51 100644 --- a/test/service/geospatial/nominatim_test.exs +++ b/test/service/geospatial/nominatim_test.exs @@ -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", diff --git a/test/service/geospatial/photon_test.exs b/test/service/geospatial/photon_test.exs index 009bccdb4..8154f37c3 100644 --- a/test/service/geospatial/photon_test.exs +++ b/test/service/geospatial/photon_test.exs @@ -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", diff --git a/test/tasks/actors_test.exs b/test/tasks/actors_test.exs index 05fc460c0..a67c69468 100644 --- a/test/tasks/actors_test.exs +++ b/test/tasks/actors_test.exs @@ -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" diff --git a/test/tasks/users_test.exs b/test/tasks/users_test.exs index d5165405f..7b537b98c 100644 --- a/test/tasks/users_test.exs +++ b/test/tasks/users_test.exs @@ -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) diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs index 7a4656f4e..66920509c 100644 --- a/test/web/views/error_view_test.exs +++ b/test/web/views/error_view_test.exs @@ -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