From ba3ad713c01b5fc8919b4a52203165ea311d41db Mon Sep 17 00:00:00 2001 From: rustra Date: Sun, 26 Jan 2020 20:34:25 +0100 Subject: [PATCH 1/5] Split GraphQL as separate context --- .../utils.ex => graphql/helpers/error.ex} | 4 +- .../resolvers/address.ex | 14 ++-- .../resolvers/admin.ex | 56 +++++++-------- .../resolvers/comment.ex | 18 +++-- .../resolvers/config.ex | 6 +- .../resolvers/event.ex | 16 ++--- .../resolvers/feed_token.ex | 32 +++++---- .../resolvers/group.ex | 13 ++-- .../resolvers/member.ex | 2 +- .../resolvers/person.ex | 10 +-- .../resolvers/picture.ex | 4 +- .../resolvers/report.ex | 2 +- .../resolvers/search.ex | 2 +- .../resolvers/tag.ex | 5 +- .../resolvers/user.ex | 71 ++++++++----------- lib/{mobilizon_web => graphql}/schema.ex | 29 ++++---- .../schema/actor.ex | 10 +-- .../schema/actors/application.ex | 2 +- .../schema/actors/follower.ex | 2 +- .../schema/actors/group.ex | 8 +-- .../schema/actors/member.ex | 8 +-- .../schema/actors/person.ex | 15 ++-- .../schema/address.ex | 9 +-- .../schema/admin.ex | 4 +- .../schema/comment.ex | 8 ++- .../schema/config.ex | 4 +- .../schema/custom/point.ex | 4 +- .../schema/custom/uuid4.ex | 4 +- .../schema/event.ex | 14 ++-- .../schema/events/feed_token.ex | 9 ++- .../schema/events/participant.ex | 11 ++- .../schema/picture.ex | 5 +- .../schema/report.ex | 9 +-- .../schema/search.ex | 10 +-- lib/{mobilizon_web => graphql}/schema/sort.ex | 2 +- lib/{mobilizon_web => graphql}/schema/tag.ex | 9 +-- lib/{mobilizon_web => graphql}/schema/user.ex | 15 ++-- lib/mobilizon_web/api/events.ex | 4 +- lib/mobilizon_web/router.ex | 2 +- .../resolvers/address_test.exs | 6 +- .../resolvers/admin_test.exs | 4 +- .../resolvers/comment_test.exs | 6 +- .../resolvers/config_test.exs | 5 +- .../resolvers/event_test.exs | 6 +- .../resolvers/feed_token_test.exs | 6 +- .../resolvers/group_test.exs | 6 +- .../resolvers/member_test.exs | 6 +- .../resolvers/participant_test.exs | 10 ++- .../resolvers/person_test.exs | 6 +- .../resolvers/picture_test.exs | 9 ++- .../resolvers/report_test.exs | 4 +- .../resolvers/search_test.exs | 5 +- .../resolvers/tag_test.exs | 6 +- .../resolvers/user_test.exs | 9 +-- test/support/abinthe_helpers.ex | 15 ++-- 55 files changed, 292 insertions(+), 269 deletions(-) rename lib/{mobilizon_web/schema/utils.ex => graphql/helpers/error.ex} (86%) rename lib/{mobilizon_web => graphql}/resolvers/address.ex (72%) rename lib/{mobilizon_web => graphql}/resolvers/admin.ex (83%) rename lib/{mobilizon_web => graphql}/resolvers/comment.ex (84%) rename lib/{mobilizon_web => graphql}/resolvers/config.ex (91%) rename lib/{mobilizon_web => graphql}/resolvers/event.ex (97%) rename lib/{mobilizon_web => graphql}/resolvers/feed_token.ex (69%) rename lib/{mobilizon_web => graphql}/resolvers/group.ex (95%) rename lib/{mobilizon_web => graphql}/resolvers/member.ex (86%) rename lib/{mobilizon_web => graphql}/resolvers/person.ex (97%) rename lib/{mobilizon_web => graphql}/resolvers/picture.ex (94%) rename lib/{mobilizon_web => graphql}/resolvers/report.ex (98%) rename lib/{mobilizon_web => graphql}/resolvers/search.ex (93%) rename lib/{mobilizon_web => graphql}/resolvers/tag.ex (92%) rename lib/{mobilizon_web => graphql}/resolvers/user.ex (86%) rename lib/{mobilizon_web => graphql}/schema.ex (84%) rename lib/{mobilizon_web => graphql}/schema/actor.ex (92%) rename lib/{mobilizon_web => graphql}/schema/actors/application.ex (96%) rename lib/{mobilizon_web => graphql}/schema/actors/follower.ex (93%) rename lib/{mobilizon_web => graphql}/schema/actors/group.ex (95%) rename lib/{mobilizon_web => graphql}/schema/actors/member.ex (83%) rename lib/{mobilizon_web => graphql}/schema/actors/person.ex (96%) rename lib/{mobilizon_web => graphql}/schema/address.ex (91%) rename lib/{mobilizon_web => graphql}/schema/admin.ex (97%) rename lib/{mobilizon_web => graphql}/schema/comment.ex (95%) rename lib/{mobilizon_web => graphql}/schema/config.ex (91%) rename lib/{mobilizon_web => graphql}/schema/custom/point.ex (94%) rename lib/{mobilizon_web => graphql}/schema/custom/uuid4.ex (93%) rename lib/{mobilizon_web => graphql}/schema/event.ex (97%) rename lib/{mobilizon_web => graphql}/schema/events/feed_token.ex (84%) rename lib/{mobilizon_web => graphql}/schema/events/participant.ex (86%) rename lib/{mobilizon_web => graphql}/schema/picture.ex (93%) rename lib/{mobilizon_web => graphql}/schema/report.ex (97%) rename lib/{mobilizon_web => graphql}/schema/search.ex (85%) rename lib/{mobilizon_web => graphql}/schema/sort.ex (81%) rename lib/{mobilizon_web => graphql}/schema/tag.ex (78%) rename lib/{mobilizon_web => graphql}/schema/user.ex (96%) rename test/{mobilizon_web => graphql}/resolvers/address_test.exs (94%) rename test/{mobilizon_web => graphql}/resolvers/admin_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/comment_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/config_test.exs (85%) rename test/{mobilizon_web => graphql}/resolvers/event_test.exs (99%) rename test/{mobilizon_web => graphql}/resolvers/feed_token_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/group_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/member_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/participant_test.exs (99%) rename test/{mobilizon_web => graphql}/resolvers/person_test.exs (99%) rename test/{mobilizon_web => graphql}/resolvers/picture_test.exs (97%) rename test/{mobilizon_web => graphql}/resolvers/report_test.exs (99%) rename test/{mobilizon_web => graphql}/resolvers/search_test.exs (98%) rename test/{mobilizon_web => graphql}/resolvers/tag_test.exs (92%) rename test/{mobilizon_web => graphql}/resolvers/user_test.exs (99%) diff --git a/lib/mobilizon_web/schema/utils.ex b/lib/graphql/helpers/error.ex similarity index 86% rename from lib/mobilizon_web/schema/utils.ex rename to lib/graphql/helpers/error.ex index 2619e7fb..ae70f819 100644 --- a/lib/mobilizon_web/schema/utils.ex +++ b/lib/graphql/helpers/error.ex @@ -1,6 +1,6 @@ -defmodule MobilizonWeb.Schema.Utils do +defmodule Mobilizon.GraphQL.Helpers.Error do @moduledoc """ - Helper functions for MobilizonWeb.Schema + Helper functions for Mobilizon.GraphQL """ def handle_errors(fun) do diff --git a/lib/mobilizon_web/resolvers/address.ex b/lib/graphql/resolvers/address.ex similarity index 72% rename from lib/mobilizon_web/resolvers/address.ex rename to lib/graphql/resolvers/address.ex index eefc35cf..f2d5fc40 100644 --- a/lib/mobilizon_web/resolvers/address.ex +++ b/lib/graphql/resolvers/address.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Address do +defmodule Mobilizon.GraphQL.Resolvers.Address do @moduledoc """ Handles the comment-related GraphQL calls """ @@ -11,10 +11,12 @@ defmodule MobilizonWeb.Resolvers.Address do @doc """ Search an address """ - @spec search(map(), map(), map()) :: {:ok, list(Address.t())} - def search(_parent, %{query: query, locale: locale, page: _page, limit: _limit}, %{ - context: %{ip: ip} - }) do + @spec search(map, map, map) :: {:ok, [Address.t()]} + def search( + _parent, + %{query: query, locale: locale, page: _page, limit: _limit}, + %{context: %{ip: ip}} + ) do geolix = Geolix.lookup(ip) country_code = @@ -31,7 +33,7 @@ defmodule MobilizonWeb.Resolvers.Address do @doc """ Reverse geocode some coordinates """ - @spec reverse_geocode(map(), map(), map()) :: {:ok, list(Address.t())} + @spec reverse_geocode(map, map, map) :: {:ok, [Address.t()]} def reverse_geocode( _parent, %{longitude: longitude, latitude: latitude, zoom: zoom, locale: locale}, diff --git a/lib/mobilizon_web/resolvers/admin.ex b/lib/graphql/resolvers/admin.ex similarity index 83% rename from lib/mobilizon_web/resolvers/admin.ex rename to lib/graphql/resolvers/admin.ex index 8ea664bc..9a99421d 100644 --- a/lib/mobilizon_web/resolvers/admin.ex +++ b/lib/graphql/resolvers/admin.ex @@ -1,13 +1,13 @@ -defmodule MobilizonWeb.Resolvers.Admin do +defmodule Mobilizon.GraphQL.Resolvers.Admin do @moduledoc """ Handles the report-related GraphQL calls. """ import Mobilizon.Users.Guards - alias Mobilizon.Admin.ActionLog alias Mobilizon.Actors alias Mobilizon.Actors.Actor + alias Mobilizon.Admin.ActionLog alias Mobilizon.Events alias Mobilizon.Events.{Event, Comment} alias Mobilizon.Reports.{Note, Report} @@ -68,36 +68,28 @@ defmodule MobilizonWeb.Resolvers.Admin do end end - defp transform_action_log(Note, :create, %ActionLog{ - changes: changes - }) do + defp transform_action_log(Note, :create, %ActionLog{changes: changes}) do %{ action: :note_creation, object: convert_changes_to_struct(Note, changes) } end - defp transform_action_log(Note, :delete, %ActionLog{ - changes: changes - }) do + defp transform_action_log(Note, :delete, %ActionLog{changes: changes}) do %{ action: :note_deletion, object: convert_changes_to_struct(Note, changes) } end - defp transform_action_log(Event, :delete, %ActionLog{ - changes: changes - }) do + defp transform_action_log(Event, :delete, %ActionLog{changes: changes}) do %{ action: :event_deletion, object: convert_changes_to_struct(Event, changes) } end - defp transform_action_log(Comment, :delete, %ActionLog{ - changes: changes - }) do + defp transform_action_log(Comment, :delete, %ActionLog{changes: changes}) do %{ action: :comment_deletion, object: convert_changes_to_struct(Comment, changes) @@ -118,9 +110,7 @@ defmodule MobilizonWeb.Resolvers.Admin do end end - def get_dashboard(_parent, _args, %{ - context: %{current_user: %User{role: role}} - }) + def get_dashboard(_parent, _args, %{context: %{current_user: %User{role: role}}}) when is_admin(role) do last_public_event_published = case Events.list_events(1, 1, :inserted_at, :desc) do @@ -142,9 +132,11 @@ defmodule MobilizonWeb.Resolvers.Admin do {:error, "You need to be logged-in and an administrator to access dashboard statistics"} end - def list_relay_followers(_parent, %{page: page, limit: limit}, %{ - context: %{current_user: %User{role: role}} - }) + def list_relay_followers( + _parent, + %{page: page, limit: limit}, + %{context: %{current_user: %User{role: role}}} + ) when is_admin(role) do with %Actor{} = relay_actor <- Relay.get_actor() do %Page{} = @@ -154,9 +146,11 @@ defmodule MobilizonWeb.Resolvers.Admin do end end - def list_relay_followings(_parent, %{page: page, limit: limit}, %{ - context: %{current_user: %User{role: role}} - }) + def list_relay_followings( + _parent, + %{page: page, limit: limit}, + %{context: %{current_user: %User{role: role}}} + ) when is_admin(role) do with %Actor{} = relay_actor <- Relay.get_actor() do %Page{} = @@ -188,9 +182,11 @@ defmodule MobilizonWeb.Resolvers.Admin do end end - def accept_subscription(_parent, %{address: address}, %{ - context: %{current_user: %User{role: role}} - }) + def accept_subscription( + _parent, + %{address: address}, + %{context: %{current_user: %User{role: role}}} + ) when is_admin(role) do case Relay.accept(address) do {:ok, _activity, follow} -> @@ -201,9 +197,11 @@ defmodule MobilizonWeb.Resolvers.Admin do end end - def reject_subscription(_parent, %{address: address}, %{ - context: %{current_user: %User{role: role}} - }) + def reject_subscription( + _parent, + %{address: address}, + %{context: %{current_user: %User{role: role}}} + ) when is_admin(role) do case Relay.reject(address) do {:ok, _activity, follow} -> diff --git a/lib/mobilizon_web/resolvers/comment.ex b/lib/graphql/resolvers/comment.ex similarity index 84% rename from lib/mobilizon_web/resolvers/comment.ex rename to lib/graphql/resolvers/comment.ex index 0810c3a9..002e1f7d 100644 --- a/lib/mobilizon_web/resolvers/comment.ex +++ b/lib/graphql/resolvers/comment.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Comment do +defmodule Mobilizon.GraphQL.Resolvers.Comment do @moduledoc """ Handles the comment-related GraphQL calls. """ @@ -17,9 +17,11 @@ defmodule MobilizonWeb.Resolvers.Comment do {:ok, Events.get_thread_replies(thread_id)} end - def create_comment(_parent, %{actor_id: actor_id} = args, %{ - context: %{current_user: %User{} = user} - }) do + def create_comment( + _parent, + %{actor_id: actor_id} = args, + %{context: %{current_user: %User{} = user}} + ) do with {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id), {:ok, _, %CommentModel{} = comment} <- Comments.create_comment(args) do @@ -34,9 +36,11 @@ defmodule MobilizonWeb.Resolvers.Comment do {:error, "You are not allowed to create a comment if not connected"} end - def delete_comment(_parent, %{actor_id: actor_id, comment_id: comment_id}, %{ - context: %{current_user: %User{role: role} = user} - }) do + def delete_comment( + _parent, + %{actor_id: actor_id, comment_id: comment_id}, + %{context: %{current_user: %User{role: role} = user}} + ) do with {actor_id, ""} <- Integer.parse(actor_id), {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id), %CommentModel{} = comment <- Events.get_comment_with_preload(comment_id) do diff --git a/lib/mobilizon_web/resolvers/config.ex b/lib/graphql/resolvers/config.ex similarity index 91% rename from lib/mobilizon_web/resolvers/config.ex rename to lib/graphql/resolvers/config.ex index a3a4d448..dbfbbbe2 100644 --- a/lib/mobilizon_web/resolvers/config.ex +++ b/lib/graphql/resolvers/config.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Config do +defmodule Mobilizon.GraphQL.Resolvers.Config do @moduledoc """ Handles the config-related GraphQL calls. """ @@ -10,9 +10,7 @@ defmodule MobilizonWeb.Resolvers.Config do @doc """ Gets config. """ - def get_config(_parent, _params, %{ - context: %{ip: ip} - }) do + def get_config(_parent, _params, %{context: %{ip: ip}}) do geolix = Geolix.lookup(ip) country_code = diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/graphql/resolvers/event.ex similarity index 97% rename from lib/mobilizon_web/resolvers/event.ex rename to lib/graphql/resolvers/event.ex index 59a0100e..a502e1cf 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Event do +defmodule Mobilizon.GraphQL.Resolvers.Event do @moduledoc """ Handles the event-related GraphQL calls. """ @@ -8,10 +8,11 @@ defmodule MobilizonWeb.Resolvers.Event do alias Mobilizon.Events.{Event, Participant, EventParticipantStats} alias Mobilizon.Users.User + alias Mobilizon.GraphQL.Resolvers.Person + alias Mobilizon.Federation.ActivityPub.Activity alias MobilizonWeb.API - alias MobilizonWeb.Resolvers.Person # We limit the max number of events that can be retrieved @event_max_limit 100 @@ -40,8 +41,9 @@ defmodule MobilizonWeb.Resolvers.Event do end end - defp find_private_event(_parent, %{uuid: uuid}, _resolution), - do: {:error, "Event with UUID #{uuid} not found"} + defp find_private_event(_parent, %{uuid: uuid}, _resolution) do + {:error, "Event with UUID #{uuid} not found"} + end def find_event(parent, %{uuid: uuid} = args, resolution) do case {:has_event, Mobilizon.Events.get_public_event_by_uuid_with_preload(uuid)} do @@ -216,11 +218,7 @@ defmodule MobilizonWeb.Resolvers.Event do def update_participation( _parent, %{id: participation_id, moderator_actor_id: moderator_actor_id, role: new_role}, - %{ - context: %{ - current_user: user - } - } + %{context: %{current_user: user}} ) do # Check that moderator provided is rightly authenticated with {:is_owned, moderator_actor} <- User.owns_actor(user, moderator_actor_id), diff --git a/lib/mobilizon_web/resolvers/feed_token.ex b/lib/graphql/resolvers/feed_token.ex similarity index 69% rename from lib/mobilizon_web/resolvers/feed_token.ex rename to lib/graphql/resolvers/feed_token.ex index 53004443..8546677e 100644 --- a/lib/mobilizon_web/resolvers/feed_token.ex +++ b/lib/graphql/resolvers/feed_token.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.FeedToken do +defmodule Mobilizon.GraphQL.Resolvers.FeedToken do @moduledoc """ Handles the feed tokens-related GraphQL calls. """ @@ -13,10 +13,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do @doc """ Create an feed token for an user and a defined actor """ - @spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()} | {:error, String.t()} - def create_feed_token(_parent, %{actor_id: actor_id}, %{ - context: %{current_user: %User{id: id} = user} - }) do + @spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()} + def create_feed_token( + _parent, + %{actor_id: actor_id}, + %{context: %{current_user: %User{id: id} = user}} + ) do with {:is_owned, %Actor{}} <- User.owns_actor(user, actor_id), {:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id, "actor_id" => actor_id}) do {:ok, feed_token} @@ -29,16 +31,14 @@ defmodule MobilizonWeb.Resolvers.FeedToken do @doc """ Create an feed token for an user """ - @spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()} - def create_feed_token(_parent, %{}, %{ - context: %{current_user: %User{id: id}} - }) do + @spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} + def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do with {:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id}) do {:ok, feed_token} end end - @spec create_feed_token(any(), map(), map()) :: {:error, String.t()} + @spec create_feed_token(any, map, map) :: {:error, String.t()} def create_feed_token(_parent, _args, %{}) do {:error, "You are not allowed to create a feed token if not connected"} end @@ -46,10 +46,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do @doc """ Delete a feed token """ - @spec delete_feed_token(any(), map(), map()) :: {:ok, map()} | {:error, String.t()} - def delete_feed_token(_parent, %{token: token}, %{ - context: %{current_user: %User{id: id} = _user} - }) do + @spec delete_feed_token(any, map, map) :: {:ok, map} | {:error, String.t()} + def delete_feed_token( + _parent, + %{token: token}, + %{context: %{current_user: %User{id: id} = _user}} + ) do with {:ok, token} <- Ecto.UUID.cast(token), {:no_token, %FeedToken{actor: actor, user: %User{} = user} = feed_token} <- {:no_token, Events.get_feed_token(token)}, @@ -73,7 +75,7 @@ defmodule MobilizonWeb.Resolvers.FeedToken do end end - @spec delete_feed_token(any(), map(), map()) :: {:error, String.t()} + @spec delete_feed_token(any, map, map) :: {:error, String.t()} def delete_feed_token(_parent, _args, %{}) do {:error, "You are not allowed to delete a feed token if not connected"} end diff --git a/lib/mobilizon_web/resolvers/group.ex b/lib/graphql/resolvers/group.ex similarity index 95% rename from lib/mobilizon_web/resolvers/group.ex rename to lib/graphql/resolvers/group.ex index 98220d67..c2ff0409 100644 --- a/lib/mobilizon_web/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Group do +defmodule Mobilizon.GraphQL.Resolvers.Group do @moduledoc """ Handles the group-related GraphQL calls. """ @@ -7,10 +7,11 @@ defmodule MobilizonWeb.Resolvers.Group do alias Mobilizon.Actors.{Actor, Member} alias Mobilizon.Users.User + alias Mobilizon.GraphQL.Resolvers.Person + alias Mobilizon.Federation.ActivityPub alias MobilizonWeb.API - alias MobilizonWeb.Resolvers.Person require Logger @@ -42,11 +43,7 @@ defmodule MobilizonWeb.Resolvers.Group do @doc """ Create a new group. The creator is automatically added as admin """ - def create_group( - _parent, - args, - %{context: %{current_user: user}} - ) do + def create_group(_parent, args, %{context: %{current_user: user}}) do with creator_actor_id <- Map.get(args, :creator_actor_id), {:is_owned, %Actor{} = creator_actor} <- User.owns_actor(user, creator_actor_id), args <- Map.put(args, :creator_actor, creator_actor), @@ -180,7 +177,7 @@ defmodule MobilizonWeb.Resolvers.Group do # We check that the actor asking to leave the group is not it's only administrator # We start by fetching the list of administrator or creators and if there's only one of them # and that it's the actor requesting leaving the group we return true - @spec check_that_member_is_not_last_administrator(integer(), integer()) :: boolean() + @spec check_that_member_is_not_last_administrator(integer, integer) :: boolean defp check_that_member_is_not_last_administrator(group_id, actor_id) do case Actors.list_administrator_members_for_group(group_id) do [%Member{actor: %Actor{id: member_actor_id}}] -> diff --git a/lib/mobilizon_web/resolvers/member.ex b/lib/graphql/resolvers/member.ex similarity index 86% rename from lib/mobilizon_web/resolvers/member.ex rename to lib/graphql/resolvers/member.ex index 1cfd320a..65cdd249 100644 --- a/lib/mobilizon_web/resolvers/member.ex +++ b/lib/graphql/resolvers/member.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Member do +defmodule Mobilizon.GraphQL.Resolvers.Member do @moduledoc """ Handles the member-related GraphQL calls """ diff --git a/lib/mobilizon_web/resolvers/person.ex b/lib/graphql/resolvers/person.ex similarity index 97% rename from lib/mobilizon_web/resolvers/person.ex rename to lib/graphql/resolvers/person.ex index 82d9b172..8ec9241b 100644 --- a/lib/mobilizon_web/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Person do +defmodule Mobilizon.GraphQL.Resolvers.Person do @moduledoc """ Handles the person-related GraphQL calls """ @@ -191,9 +191,11 @@ defmodule MobilizonWeb.Resolvers.Person do @doc """ Returns the participation for a specific event """ - def person_participations(%Actor{id: actor_id}, %{event_id: event_id}, %{ - context: %{current_user: user} - }) do + def person_participations( + %Actor{id: actor_id}, + %{event_id: event_id}, + %{context: %{current_user: user}} + ) do with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id), {:no_participant, {:ok, %Participant{} = participant}} <- {:no_participant, Events.get_participant(event_id, actor_id)} do diff --git a/lib/mobilizon_web/resolvers/picture.ex b/lib/graphql/resolvers/picture.ex similarity index 94% rename from lib/mobilizon_web/resolvers/picture.ex rename to lib/graphql/resolvers/picture.ex index 1b5c73c2..941ef6fd 100644 --- a/lib/mobilizon_web/resolvers/picture.ex +++ b/lib/graphql/resolvers/picture.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Picture do +defmodule Mobilizon.GraphQL.Resolvers.Picture do @moduledoc """ Handles the picture-related GraphQL calls """ @@ -44,7 +44,7 @@ defmodule MobilizonWeb.Resolvers.Picture do end end - @spec upload_picture(map(), map(), map()) :: {:ok, Picture.t()} | {:error, any()} + @spec upload_picture(map, map, map) :: {:ok, Picture.t()} | {:error, any} def upload_picture( _parent, %{file: %Plug.Upload{} = file, actor_id: actor_id} = args, diff --git a/lib/mobilizon_web/resolvers/report.ex b/lib/graphql/resolvers/report.ex similarity index 98% rename from lib/mobilizon_web/resolvers/report.ex rename to lib/graphql/resolvers/report.ex index 823e58a3..e8b78199 100644 --- a/lib/mobilizon_web/resolvers/report.ex +++ b/lib/graphql/resolvers/report.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Report do +defmodule Mobilizon.GraphQL.Resolvers.Report do @moduledoc """ Handles the report-related GraphQL calls. """ diff --git a/lib/mobilizon_web/resolvers/search.ex b/lib/graphql/resolvers/search.ex similarity index 93% rename from lib/mobilizon_web/resolvers/search.ex rename to lib/graphql/resolvers/search.ex index f6b7995a..acb74b96 100644 --- a/lib/mobilizon_web/resolvers/search.ex +++ b/lib/graphql/resolvers/search.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.Search do +defmodule Mobilizon.GraphQL.Resolvers.Search do @moduledoc """ Handles the event-related GraphQL calls """ diff --git a/lib/mobilizon_web/resolvers/tag.ex b/lib/graphql/resolvers/tag.ex similarity index 92% rename from lib/mobilizon_web/resolvers/tag.ex rename to lib/graphql/resolvers/tag.ex index 75f26a6c..b7a5dd11 100644 --- a/lib/mobilizon_web/resolvers/tag.ex +++ b/lib/graphql/resolvers/tag.ex @@ -1,10 +1,9 @@ -defmodule MobilizonWeb.Resolvers.Tag do +defmodule Mobilizon.GraphQL.Resolvers.Tag do @moduledoc """ Handles the tag-related GraphQL calls """ alias Mobilizon.Events - alias Mobilizon.Events.Event - alias Mobilizon.Events.Tag + alias Mobilizon.Events.{Event, Tag} def list_tags(_parent, %{page: page, limit: limit}, _resolution) do tags = Mobilizon.Events.list_tags(page, limit) diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/graphql/resolvers/user.ex similarity index 86% rename from lib/mobilizon_web/resolvers/user.ex rename to lib/graphql/resolvers/user.ex index c9ab7c2b..4b4993ed 100644 --- a/lib/mobilizon_web/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.User do +defmodule Mobilizon.GraphQL.Resolvers.User do @moduledoc """ Handles the user-related GraphQL calls. """ @@ -24,15 +24,7 @@ defmodule MobilizonWeb.Resolvers.User do @doc """ Return current logged-in user """ - def get_current_user( - _parent, - _args, - %{ - context: %{ - current_user: user - } - } - ) do + def get_current_user(_parent, _args, %{context: %{current_user: user}}) do {:ok, user} end @@ -46,13 +38,7 @@ defmodule MobilizonWeb.Resolvers.User do def list_and_count_users( _parent, %{page: page, limit: limit, sort: sort, direction: direction}, - %{ - context: %{ - current_user: %User{ - role: role - } - } - } + %{context: %{current_user: %User{role: role}}} ) when is_moderator(role) do total = Task.async(&Users.count_users/0) @@ -61,8 +47,9 @@ defmodule MobilizonWeb.Resolvers.User do {:ok, %{total: Task.await(total), elements: Task.await(elements)}} end - def list_and_count_users(_parent, _args, _resolution), - do: {:error, "You need to have admin access to list users"} + def list_and_count_users(_parent, _args, _resolution) do + {:error, "You need to have admin access to list users"} + end @doc """ Login an user. Returns a token and the user @@ -87,13 +74,7 @@ defmodule MobilizonWeb.Resolvers.User do @doc """ Refresh a token """ - def refresh_token( - _parent, - %{ - refresh_token: refresh_token - }, - _context - ) do + def refresh_token(_parent, %{refresh_token: refresh_token}, _context) do with {:ok, user, _claims} <- Auth.Guardian.resource_from_token(refresh_token), {:ok, _old, {exchanged_token, _claims}} <- Auth.Guardian.exchange(refresh_token, ["access", "refresh"], "access"), @@ -106,8 +87,9 @@ defmodule MobilizonWeb.Resolvers.User do end end - def refresh_token(_parent, _params, _context), - do: {:error, "You need to have an existing token to get a refresh token"} + def refresh_token(_parent, _params, _context) do + {:error, "You need to have an existing token to get a refresh token"} + end @doc """ Register an user: @@ -115,7 +97,7 @@ defmodule MobilizonWeb.Resolvers.User do - create the user - send a validation email to the user """ - @spec create_user(any(), map(), any()) :: tuple() + @spec create_user(any, map, any) :: tuple def create_user(_parent, args, _resolution) do with :registration_ok <- check_registration_config(args), {:ok, %User{} = user} <- Users.register(args) do @@ -133,7 +115,7 @@ defmodule MobilizonWeb.Resolvers.User do end end - @spec check_registration_config(map()) :: atom() + @spec check_registration_config(map) :: atom defp check_registration_config(%{email: email}) do cond do Config.instance_registrations_open?() -> @@ -176,6 +158,7 @@ defmodule MobilizonWeb.Resolvers.User do error -> Logger.info("Unable to validate user with token #{token}") Logger.debug(inspect(error)) + {:error, "Unable to validate user"} end end @@ -253,9 +236,11 @@ defmodule MobilizonWeb.Resolvers.User do @doc """ Returns the list of events for all of this user's identities are going to """ - def user_participations(%User{id: user_id}, args, %{ - context: %{current_user: %User{id: logged_user_id}} - }) do + def user_participations( + %User{id: user_id}, + args, + %{context: %{current_user: %User{id: logged_user_id}}} + ) do with true <- user_id == logged_user_id, participations <- Events.list_participations_for_user( @@ -272,9 +257,11 @@ defmodule MobilizonWeb.Resolvers.User do @doc """ Returns the list of draft events for the current user """ - def user_drafted_events(%User{id: user_id}, args, %{ - context: %{current_user: %User{id: logged_user_id}} - }) do + def user_drafted_events( + %User{id: user_id}, + args, + %{context: %{current_user: %User{id: logged_user_id}}} + ) do with {:same_user, true} <- {:same_user, user_id == logged_user_id}, events <- Events.list_drafts_for_user(user_id, Map.get(args, :page), Map.get(args, :limit)) do @@ -282,17 +269,17 @@ defmodule MobilizonWeb.Resolvers.User do end end - def change_password(_parent, %{old_password: old_password, new_password: new_password}, %{ - context: %{current_user: %User{password_hash: old_password_hash} = user} - }) do + def change_password( + _parent, + %{old_password: old_password, new_password: new_password}, + %{context: %{current_user: %User{password_hash: old_password_hash} = user}} + ) do with {:current_password, true} <- {:current_password, Argon2.verify_pass(old_password, old_password_hash)}, {:same_password, false} <- {:same_password, old_password == new_password}, {:ok, %User{} = user} <- user - |> User.password_change_changeset(%{ - "password" => new_password - }) + |> User.password_change_changeset(%{"password" => new_password}) |> Repo.update() do {:ok, user} else diff --git a/lib/mobilizon_web/schema.ex b/lib/graphql/schema.ex similarity index 84% rename from lib/mobilizon_web/schema.ex rename to lib/graphql/schema.ex index c78bd3f7..eb2c882e 100644 --- a/lib/mobilizon_web/schema.ex +++ b/lib/graphql/schema.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema do +defmodule Mobilizon.GraphQL.Schema do @moduledoc """ GraphQL schema representation. """ @@ -8,24 +8,25 @@ defmodule MobilizonWeb.Schema do alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users} alias Mobilizon.Actors.{Actor, Follower, Member} alias Mobilizon.Events.{Comment, Event, Participant} + alias Mobilizon.GraphQL.Schema alias Mobilizon.Storage.Repo - import_types(MobilizonWeb.Schema.Custom.UUID) - import_types(MobilizonWeb.Schema.Custom.Point) import_types(Absinthe.Type.Custom) import_types(Absinthe.Plug.Types) + import_types(Schema.Custom.UUID) + import_types(Schema.Custom.Point) - import_types(MobilizonWeb.Schema.UserType) - import_types(MobilizonWeb.Schema.PictureType) - import_types(MobilizonWeb.Schema.ActorInterface) - import_types(MobilizonWeb.Schema.Actors.PersonType) - import_types(MobilizonWeb.Schema.Actors.GroupType) - import_types(MobilizonWeb.Schema.Actors.ApplicationType) - import_types(MobilizonWeb.Schema.CommentType) - import_types(MobilizonWeb.Schema.SearchType) - import_types(MobilizonWeb.Schema.ConfigType) - import_types(MobilizonWeb.Schema.ReportType) - import_types(MobilizonWeb.Schema.AdminType) + import_types(Schema.UserType) + import_types(Schema.PictureType) + import_types(Schema.ActorInterface) + import_types(Schema.Actors.PersonType) + import_types(Schema.Actors.GroupType) + import_types(Schema.Actors.ApplicationType) + import_types(Schema.CommentType) + import_types(Schema.SearchType) + import_types(Schema.ConfigType) + import_types(Schema.ReportType) + import_types(Schema.AdminType) @desc "A struct containing the id of the deleted object" object :deleted_object do diff --git a/lib/mobilizon_web/schema/actor.ex b/lib/graphql/schema/actor.ex similarity index 92% rename from lib/mobilizon_web/schema/actor.ex rename to lib/graphql/schema/actor.ex index 2b21f1a2..162b9c60 100644 --- a/lib/mobilizon_web/schema/actor.ex +++ b/lib/graphql/schema/actor.ex @@ -1,12 +1,14 @@ -defmodule MobilizonWeb.Schema.ActorInterface do +defmodule Mobilizon.GraphQL.Schema.ActorInterface do @moduledoc """ Schema representation for Actor """ use Absinthe.Schema.Notation - alias Mobilizon.Actors.Actor - import_types(MobilizonWeb.Schema.Actors.FollowerType) - import_types(MobilizonWeb.Schema.EventType) + alias Mobilizon.Actors.Actor + alias Mobilizon.GraphQL.Schema + + import_types(Schema.Actors.FollowerType) + import_types(Schema.EventType) @desc "An ActivityPub actor" interface :actor do diff --git a/lib/mobilizon_web/schema/actors/application.ex b/lib/graphql/schema/actors/application.ex similarity index 96% rename from lib/mobilizon_web/schema/actors/application.ex rename to lib/graphql/schema/actors/application.ex index 8bfdf41f..33999198 100644 --- a/lib/mobilizon_web/schema/actors/application.ex +++ b/lib/graphql/schema/actors/application.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Actors.ApplicationType do +defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do @moduledoc """ Schema representation for Group. """ diff --git a/lib/mobilizon_web/schema/actors/follower.ex b/lib/graphql/schema/actors/follower.ex similarity index 93% rename from lib/mobilizon_web/schema/actors/follower.ex rename to lib/graphql/schema/actors/follower.ex index 258103c1..efa297a0 100644 --- a/lib/mobilizon_web/schema/actors/follower.ex +++ b/lib/graphql/schema/actors/follower.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Actors.FollowerType do +defmodule Mobilizon.GraphQL.Schema.Actors.FollowerType do @moduledoc """ Schema representation for Follower """ diff --git a/lib/mobilizon_web/schema/actors/group.ex b/lib/graphql/schema/actors/group.ex similarity index 95% rename from lib/mobilizon_web/schema/actors/group.ex rename to lib/graphql/schema/actors/group.ex index a243ef6b..de764242 100644 --- a/lib/mobilizon_web/schema/actors/group.ex +++ b/lib/graphql/schema/actors/group.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Actors.GroupType do +defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do @moduledoc """ Schema representation for Group. """ @@ -8,10 +8,10 @@ defmodule MobilizonWeb.Schema.Actors.GroupType do import Absinthe.Resolution.Helpers, only: [dataloader: 1] alias Mobilizon.Events + alias Mobilizon.GraphQL.Resolvers.{Group, Member} + alias Mobilizon.GraphQL.Schema - alias MobilizonWeb.Resolvers.{Group, Member} - - import_types(MobilizonWeb.Schema.Actors.MemberType) + import_types(Schema.Actors.MemberType) @desc """ Represents a group of actors diff --git a/lib/mobilizon_web/schema/actors/member.ex b/lib/graphql/schema/actors/member.ex similarity index 83% rename from lib/mobilizon_web/schema/actors/member.ex rename to lib/graphql/schema/actors/member.ex index 92013889..90778513 100644 --- a/lib/mobilizon_web/schema/actors/member.ex +++ b/lib/graphql/schema/actors/member.ex @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.Schema.Actors.MemberType do +defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do @moduledoc """ Schema representation for Member """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers + alias Mobilizon.GraphQL.Resolvers.Group @desc """ Represents a member of a group @@ -27,7 +27,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do arg(:group_id, non_null(:id)) arg(:actor_id, non_null(:id)) - resolve(&Resolvers.Group.join_group/3) + resolve(&Group.join_group/3) end @desc "Leave an event" @@ -35,7 +35,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do arg(:group_id, non_null(:id)) arg(:actor_id, non_null(:id)) - resolve(&Resolvers.Group.leave_group/3) + resolve(&Group.leave_group/3) end end end diff --git a/lib/mobilizon_web/schema/actors/person.ex b/lib/graphql/schema/actors/person.ex similarity index 96% rename from lib/mobilizon_web/schema/actors/person.ex rename to lib/graphql/schema/actors/person.ex index 2cbc4c78..c4c145b4 100644 --- a/lib/mobilizon_web/schema/actors/person.ex +++ b/lib/graphql/schema/actors/person.ex @@ -1,14 +1,17 @@ -defmodule MobilizonWeb.Schema.Actors.PersonType do +defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do @moduledoc """ Schema representation for Person """ use Absinthe.Schema.Notation - import Absinthe.Resolution.Helpers, only: [dataloader: 1] - alias Mobilizon.Events - alias MobilizonWeb.Resolvers.Person - import MobilizonWeb.Schema.Utils - import_types(MobilizonWeb.Schema.Events.FeedTokenType) + import Absinthe.Resolution.Helpers, only: [dataloader: 1] + import Mobilizon.GraphQL.Helpers.Error + + alias Mobilizon.Events + alias Mobilizon.GraphQL.Resolvers.Person + alias Mobilizon.GraphQL.Schema + + import_types(Schema.Events.FeedTokenType) @desc """ Represents a person identity diff --git a/lib/mobilizon_web/schema/address.ex b/lib/graphql/schema/address.ex similarity index 91% rename from lib/mobilizon_web/schema/address.ex rename to lib/graphql/schema/address.ex index aea2a815..13ce2244 100644 --- a/lib/mobilizon_web/schema/address.ex +++ b/lib/graphql/schema/address.ex @@ -1,9 +1,10 @@ -defmodule MobilizonWeb.Schema.AddressType do +defmodule Mobilizon.GraphQL.Schema.AddressType do @moduledoc """ Schema representation for Address """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers + + alias Mobilizon.GraphQL.Resolvers.Address object :address do field(:geom, :point, description: "The geocoordinates for the point where this address is") @@ -52,7 +53,7 @@ defmodule MobilizonWeb.Schema.AddressType do arg(:page, :integer, default_value: 1) arg(:limit, :integer, default_value: 10) - resolve(&Resolvers.Address.search/3) + resolve(&Address.search/3) end @desc "Reverse geocode coordinates" @@ -62,7 +63,7 @@ defmodule MobilizonWeb.Schema.AddressType do arg(:zoom, :integer, default_value: 15) arg(:locale, :string, default_value: "en") - resolve(&Resolvers.Address.reverse_geocode/3) + resolve(&Address.reverse_geocode/3) end end end diff --git a/lib/mobilizon_web/schema/admin.ex b/lib/graphql/schema/admin.ex similarity index 97% rename from lib/mobilizon_web/schema/admin.ex rename to lib/graphql/schema/admin.ex index f1e7543f..b7dc5cb9 100644 --- a/lib/mobilizon_web/schema/admin.ex +++ b/lib/graphql/schema/admin.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.AdminType do +defmodule Mobilizon.GraphQL.Schema.AdminType do @moduledoc """ Schema representation for ActionLog. """ @@ -8,7 +8,7 @@ defmodule MobilizonWeb.Schema.AdminType do alias Mobilizon.Events.{Event, Comment} alias Mobilizon.Reports.{Note, Report} - alias MobilizonWeb.Resolvers.Admin + alias Mobilizon.GraphQL.Resolvers.Admin @desc "An action log" object :action_log do diff --git a/lib/mobilizon_web/schema/comment.ex b/lib/graphql/schema/comment.ex similarity index 95% rename from lib/mobilizon_web/schema/comment.ex rename to lib/graphql/schema/comment.ex index 8f68d16d..8794a7f4 100644 --- a/lib/mobilizon_web/schema/comment.ex +++ b/lib/graphql/schema/comment.ex @@ -1,12 +1,14 @@ -defmodule MobilizonWeb.Schema.CommentType do +defmodule Mobilizon.GraphQL.Schema.CommentType do @moduledoc """ Schema representation for Comment """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers.Comment - alias Mobilizon.{Actors, Events} + import Absinthe.Resolution.Helpers, only: [dataloader: 1] + alias Mobilizon.{Actors, Events} + alias Mobilizon.GraphQL.Resolvers.Comment + @desc "A comment" object :comment do interfaces([:action_log_object]) diff --git a/lib/mobilizon_web/schema/config.ex b/lib/graphql/schema/config.ex similarity index 91% rename from lib/mobilizon_web/schema/config.ex rename to lib/graphql/schema/config.ex index 46f9fa23..95116de8 100644 --- a/lib/mobilizon_web/schema/config.ex +++ b/lib/graphql/schema/config.ex @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.Schema.ConfigType do +defmodule Mobilizon.GraphQL.Schema.ConfigType do @moduledoc """ Schema representation for User """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers.Config + alias Mobilizon.GraphQL.Resolvers.Config @desc "A config object" object :config do diff --git a/lib/mobilizon_web/schema/custom/point.ex b/lib/graphql/schema/custom/point.ex similarity index 94% rename from lib/mobilizon_web/schema/custom/point.ex rename to lib/graphql/schema/custom/point.ex index 7bd3cf97..432aa85f 100644 --- a/lib/mobilizon_web/schema/custom/point.ex +++ b/lib/graphql/schema/custom/point.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Custom.Point do +defmodule Mobilizon.GraphQL.Schema.Custom.Point do @moduledoc """ The geom scalar type allows Geo.PostGIS.Geometry strings to be passed in and out. Requires `{:geo, "~> 3.0"},` package: https://github.com/elixir-ecto/ecto @@ -15,7 +15,7 @@ defmodule MobilizonWeb.Schema.Custom.Point do parse(&decode/1) end - @spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error + @spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error @spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} defp decode(%Absinthe.Blueprint.Input.String{value: value}) do with [_, _] = lonlat <- String.split(value, ";", trim: true), diff --git a/lib/mobilizon_web/schema/custom/uuid4.ex b/lib/graphql/schema/custom/uuid4.ex similarity index 93% rename from lib/mobilizon_web/schema/custom/uuid4.ex rename to lib/graphql/schema/custom/uuid4.ex index 4540e334..11201177 100644 --- a/lib/mobilizon_web/schema/custom/uuid4.ex +++ b/lib/graphql/schema/custom/uuid4.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Custom.UUID do +defmodule Mobilizon.GraphQL.Schema.Custom.UUID do @moduledoc """ The UUID4 scalar type allows UUID compliant strings to be passed in and out. Requires `{ :ecto, ">= 0.0.0" }` package: https://github.com/elixir-ecto/ecto @@ -18,7 +18,7 @@ defmodule MobilizonWeb.Schema.Custom.UUID do parse(&decode/1) end - @spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error + @spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error @spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} defp decode(%Absinthe.Blueprint.Input.String{value: value}) do UUID.cast(value) diff --git a/lib/mobilizon_web/schema/event.ex b/lib/graphql/schema/event.ex similarity index 97% rename from lib/mobilizon_web/schema/event.ex rename to lib/graphql/schema/event.ex index b0c61722..9c816476 100644 --- a/lib/mobilizon_web/schema/event.ex +++ b/lib/graphql/schema/event.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.EventType do +defmodule Mobilizon.GraphQL.Schema.EventType do @moduledoc """ Schema representation for Event. """ @@ -6,15 +6,15 @@ defmodule MobilizonWeb.Schema.EventType do use Absinthe.Schema.Notation import Absinthe.Resolution.Helpers, only: [dataloader: 1] - import MobilizonWeb.Schema.Utils + import Mobilizon.GraphQL.Helpers.Error alias Mobilizon.{Actors, Addresses, Events} + alias Mobilizon.GraphQL.Resolvers.{Event, Picture, Tag} + alias Mobilizon.GraphQL.Schema - alias MobilizonWeb.Resolvers.{Event, Picture, Tag} - - import_types(MobilizonWeb.Schema.AddressType) - import_types(MobilizonWeb.Schema.Events.ParticipantType) - import_types(MobilizonWeb.Schema.TagType) + import_types(Schema.AddressType) + import_types(Schema.Events.ParticipantType) + import_types(Schema.TagType) @desc "An event" object :event do diff --git a/lib/mobilizon_web/schema/events/feed_token.ex b/lib/graphql/schema/events/feed_token.ex similarity index 84% rename from lib/mobilizon_web/schema/events/feed_token.ex rename to lib/graphql/schema/events/feed_token.ex index ac8ba8b5..8c9dc438 100644 --- a/lib/mobilizon_web/schema/events/feed_token.ex +++ b/lib/graphql/schema/events/feed_token.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Events.FeedTokenType do +defmodule Mobilizon.GraphQL.Schema.Events.FeedTokenType do @moduledoc """ Schema representation for Participant. """ @@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do import Absinthe.Resolution.Helpers, only: [dataloader: 1] alias Mobilizon.{Actors, Users} - - alias MobilizonWeb.Resolvers + alias Mobilizon.GraphQL.Resolvers.FeedToken @desc "Represents a participant to an event" object :feed_token do @@ -41,14 +40,14 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do field :create_feed_token, :feed_token do arg(:actor_id, :id) - resolve(&Resolvers.FeedToken.create_feed_token/3) + resolve(&FeedToken.create_feed_token/3) end @desc "Delete a feed token" field :delete_feed_token, :deleted_feed_token do arg(:token, non_null(:string)) - resolve(&Resolvers.FeedToken.delete_feed_token/3) + resolve(&FeedToken.delete_feed_token/3) end end end diff --git a/lib/mobilizon_web/schema/events/participant.ex b/lib/graphql/schema/events/participant.ex similarity index 86% rename from lib/mobilizon_web/schema/events/participant.ex rename to lib/graphql/schema/events/participant.ex index 7873d433..7136f699 100644 --- a/lib/mobilizon_web/schema/events/participant.ex +++ b/lib/graphql/schema/events/participant.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.Events.ParticipantType do +defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do @moduledoc """ Schema representation for Participant. """ @@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do import Absinthe.Resolution.Helpers, only: [dataloader: 1] alias Mobilizon.{Actors, Events} - - alias MobilizonWeb.Resolvers + alias Mobilizon.GraphQL.Resolvers.Event @desc "Represents a participant to an event" object :participant do @@ -54,7 +53,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do arg(:event_id, non_null(:id)) arg(:actor_id, non_null(:id)) - resolve(&Resolvers.Event.actor_join_event/3) + resolve(&Event.actor_join_event/3) end @desc "Leave an event" @@ -62,7 +61,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do arg(:event_id, non_null(:id)) arg(:actor_id, non_null(:id)) - resolve(&Resolvers.Event.actor_leave_event/3) + resolve(&Event.actor_leave_event/3) end @desc "Accept a participation" @@ -71,7 +70,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do arg(:role, non_null(:participant_role_enum)) arg(:moderator_actor_id, non_null(:id)) - resolve(&Resolvers.Event.update_participation/3) + resolve(&Event.update_participation/3) end end end diff --git a/lib/mobilizon_web/schema/picture.ex b/lib/graphql/schema/picture.ex similarity index 93% rename from lib/mobilizon_web/schema/picture.ex rename to lib/graphql/schema/picture.ex index 5290505d..fb94517b 100644 --- a/lib/mobilizon_web/schema/picture.ex +++ b/lib/graphql/schema/picture.ex @@ -1,9 +1,10 @@ -defmodule MobilizonWeb.Schema.PictureType do +defmodule Mobilizon.GraphQL.Schema.PictureType do @moduledoc """ Schema representation for Pictures """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers.Picture + + alias Mobilizon.GraphQL.Resolvers.Picture @desc "A picture" object :picture do diff --git a/lib/mobilizon_web/schema/report.ex b/lib/graphql/schema/report.ex similarity index 97% rename from lib/mobilizon_web/schema/report.ex rename to lib/graphql/schema/report.ex index e0edc07e..db3890f4 100644 --- a/lib/mobilizon_web/schema/report.ex +++ b/lib/graphql/schema/report.ex @@ -1,12 +1,13 @@ -defmodule MobilizonWeb.Schema.ReportType do +defmodule Mobilizon.GraphQL.Schema.ReportType do @moduledoc """ Schema representation for User """ use Absinthe.Schema.Notation - import Absinthe.Resolution.Helpers, only: [dataloader: 1] - alias Mobilizon.Reports - alias MobilizonWeb.Resolvers.Report + import Absinthe.Resolution.Helpers, only: [dataloader: 1] + + alias Mobilizon.Reports + alias Mobilizon.GraphQL.Resolvers.Report @desc "A report object" object :report do diff --git a/lib/mobilizon_web/schema/search.ex b/lib/graphql/schema/search.ex similarity index 85% rename from lib/mobilizon_web/schema/search.ex rename to lib/graphql/schema/search.ex index a752c0ff..fbba6a91 100644 --- a/lib/mobilizon_web/schema/search.ex +++ b/lib/graphql/schema/search.ex @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.Schema.SearchType do +defmodule Mobilizon.GraphQL.Schema.SearchType do @moduledoc """ Schema representation for Search """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers + alias Mobilizon.GraphQL.Resolvers.Search @desc "Search persons result" object :persons do @@ -31,7 +31,7 @@ defmodule MobilizonWeb.Schema.SearchType do arg(:page, :integer, default_value: 1) arg(:limit, :integer, default_value: 10) - resolve(&Resolvers.Search.search_persons/3) + resolve(&Search.search_persons/3) end @desc "Search groups" @@ -40,7 +40,7 @@ defmodule MobilizonWeb.Schema.SearchType do arg(:page, :integer, default_value: 1) arg(:limit, :integer, default_value: 10) - resolve(&Resolvers.Search.search_groups/3) + resolve(&Search.search_groups/3) end @desc "Search events" @@ -49,7 +49,7 @@ defmodule MobilizonWeb.Schema.SearchType do arg(:page, :integer, default_value: 1) arg(:limit, :integer, default_value: 10) - resolve(&Resolvers.Search.search_events/3) + resolve(&Search.search_events/3) end end end diff --git a/lib/mobilizon_web/schema/sort.ex b/lib/graphql/schema/sort.ex similarity index 81% rename from lib/mobilizon_web/schema/sort.ex rename to lib/graphql/schema/sort.ex index 2f44e786..21770955 100644 --- a/lib/mobilizon_web/schema/sort.ex +++ b/lib/graphql/schema/sort.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Schema.SortType do +defmodule Mobilizon.GraphQL.Schema.SortType do @moduledoc """ Allows sorting a collection of elements """ diff --git a/lib/mobilizon_web/schema/tag.ex b/lib/graphql/schema/tag.ex similarity index 78% rename from lib/mobilizon_web/schema/tag.ex rename to lib/graphql/schema/tag.ex index 7c4237cc..eee428c6 100644 --- a/lib/mobilizon_web/schema/tag.ex +++ b/lib/graphql/schema/tag.ex @@ -1,9 +1,10 @@ -defmodule MobilizonWeb.Schema.TagType do +defmodule Mobilizon.GraphQL.Schema.TagType do @moduledoc """ Schema representation for Tags """ use Absinthe.Schema.Notation - alias MobilizonWeb.Resolvers + + alias Mobilizon.GraphQL.Resolvers.Tag @desc "A tag" object :tag do @@ -14,7 +15,7 @@ defmodule MobilizonWeb.Schema.TagType do field( :related, list_of(:tag), - resolve: &Resolvers.Tag.get_related_tags/3, + resolve: &Tag.get_related_tags/3, description: "Related tags to this tag" ) end @@ -24,7 +25,7 @@ defmodule MobilizonWeb.Schema.TagType do field :tags, non_null(list_of(:tag)) do arg(:page, :integer, default_value: 1) arg(:limit, :integer, default_value: 10) - resolve(&Resolvers.Tag.list_tags/3) + resolve(&Tag.list_tags/3) end end end diff --git a/lib/mobilizon_web/schema/user.ex b/lib/graphql/schema/user.ex similarity index 96% rename from lib/mobilizon_web/schema/user.ex rename to lib/graphql/schema/user.ex index d23547e2..d5ca3e6a 100644 --- a/lib/mobilizon_web/schema/user.ex +++ b/lib/graphql/schema/user.ex @@ -1,14 +1,17 @@ -defmodule MobilizonWeb.Schema.UserType do +defmodule Mobilizon.GraphQL.Schema.UserType do @moduledoc """ Schema representation for User """ use Absinthe.Schema.Notation - import Absinthe.Resolution.Helpers, only: [dataloader: 1] - alias Mobilizon.Events - alias MobilizonWeb.Resolvers.User - import MobilizonWeb.Schema.Utils - import_types(MobilizonWeb.Schema.SortType) + import Absinthe.Resolution.Helpers, only: [dataloader: 1] + import Mobilizon.GraphQL.Helpers.Error + + alias Mobilizon.Events + alias Mobilizon.GraphQL.Resolvers.User + alias Mobilizon.GraphQL.Schema + + import_types(Schema.SortType) @desc "A local user of Mobilizon" object :user do diff --git a/lib/mobilizon_web/api/events.ex b/lib/mobilizon_web/api/events.ex index 2db2b798..b3a7b58b 100644 --- a/lib/mobilizon_web/api/events.ex +++ b/lib/mobilizon_web/api/events.ex @@ -53,7 +53,9 @@ defmodule MobilizonWeb.API.Events do defp process_picture(%{picture: picture}, %Actor{id: actor_id}) do %{ file: - picture |> Map.get(:file) |> Utils.make_picture_data(description: Map.get(picture, :name)), + picture + |> Map.get(:file) + |> Utils.make_picture_data(description: Map.get(picture, :name)), actor_id: actor_id } end diff --git a/lib/mobilizon_web/router.ex b/lib/mobilizon_web/router.ex index 1f20cf16..caff1d7f 100644 --- a/lib/mobilizon_web/router.ex +++ b/lib/mobilizon_web/router.ex @@ -52,7 +52,7 @@ defmodule MobilizonWeb.Router do pipe_through(:graphql) forward("/", Absinthe.Plug, - schema: MobilizonWeb.Schema, + schema: Mobilizon.GraphQL.Schema, analyze_complexity: true, max_complexity: 200 ) diff --git a/test/mobilizon_web/resolvers/address_test.exs b/test/graphql/resolvers/address_test.exs similarity index 94% rename from test/mobilizon_web/resolvers/address_test.exs rename to test/graphql/resolvers/address_test.exs index 47a944c3..f55eb743 100644 --- a/test/mobilizon_web/resolvers/address_test.exs +++ b/test/graphql/resolvers/address_test.exs @@ -1,8 +1,10 @@ -defmodule MobilizonWeb.Resolvers.AddressResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.AddressTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers + import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + describe "Address Resolver" do test "search/3 search for addresses", %{conn: conn} do address = insert(:address, description: "10 rue Jangot, Lyon") diff --git a/test/mobilizon_web/resolvers/admin_test.exs b/test/graphql/resolvers/admin_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/admin_test.exs rename to test/graphql/resolvers/admin_test.exs index 30c9d036..7bc2d857 100644 --- a/test/mobilizon_web/resolvers/admin_test.exs +++ b/test/graphql/resolvers/admin_test.exs @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.AdminResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.AdminTest do use MobilizonWeb.ConnCase import Mobilizon.Factory @@ -10,7 +10,7 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do alias Mobilizon.Federation.ActivityPub.Relay - alias MobilizonWeb.AbsintheHelpers + alias Mobilizon.GraphQL.AbsintheHelpers alias MobilizonWeb.API describe "Resolver: List the action logs" do diff --git a/test/mobilizon_web/resolvers/comment_test.exs b/test/graphql/resolvers/comment_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/comment_test.exs rename to test/graphql/resolvers/comment_test.exs index 3465ecb9..d4469253 100644 --- a/test/mobilizon_web/resolvers/comment_test.exs +++ b/test/graphql/resolvers/comment_test.exs @@ -1,8 +1,10 @@ -defmodule MobilizonWeb.Resolvers.CommentResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.CommentTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers + import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + @comment %{text: "I love this event"} setup %{conn: conn} do diff --git a/test/mobilizon_web/resolvers/config_test.exs b/test/graphql/resolvers/config_test.exs similarity index 85% rename from test/mobilizon_web/resolvers/config_test.exs rename to test/graphql/resolvers/config_test.exs index d9cb1bc9..a126df97 100644 --- a/test/mobilizon_web/resolvers/config_test.exs +++ b/test/graphql/resolvers/config_test.exs @@ -1,8 +1,9 @@ -defmodule MobilizonWeb.Resolvers.ConfigResolverTest do - alias MobilizonWeb.AbsintheHelpers +defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do use MobilizonWeb.ConnCase use Bamboo.Test + alias Mobilizon.GraphQL.AbsintheHelpers + describe "Resolver: Get config" do test "get_config/3 returns the instance config", context do query = """ diff --git a/test/mobilizon_web/resolvers/event_test.exs b/test/graphql/resolvers/event_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/event_test.exs rename to test/graphql/resolvers/event_test.exs index efa54a9e..b1ebd9d3 100644 --- a/test/mobilizon_web/resolvers/event_test.exs +++ b/test/graphql/resolvers/event_test.exs @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.EventResolverTest do +defmodule MobilizonWeb.Resolvers.EventTest do use MobilizonWeb.ConnCase use Bamboo.Test use Oban.Testing, repo: Mobilizon.Storage.Repo @@ -8,7 +8,9 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do alias Mobilizon.Events alias Mobilizon.Service.Workers - alias MobilizonWeb.{AbsintheHelpers, Email} + alias Mobilizon.GraphQL.AbsintheHelpers + + alias MobilizonWeb.Email @event %{ description: "some body", diff --git a/test/mobilizon_web/resolvers/feed_token_test.exs b/test/graphql/resolvers/feed_token_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/feed_token_test.exs rename to test/graphql/resolvers/feed_token_test.exs index 01b277e2..2810ed73 100644 --- a/test/mobilizon_web/resolvers/feed_token_test.exs +++ b/test/graphql/resolvers/feed_token_test.exs @@ -1,8 +1,10 @@ -defmodule MobilizonWeb.Resolvers.FeedTokenResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.FeedTokenTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers + import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + setup %{conn: conn} do user = insert(:user) actor = insert(:actor, user: user, preferred_username: "test") diff --git a/test/mobilizon_web/resolvers/group_test.exs b/test/graphql/resolvers/group_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/group_test.exs rename to test/graphql/resolvers/group_test.exs index 6ad4c22c..4c0b29cf 100644 --- a/test/mobilizon_web/resolvers/group_test.exs +++ b/test/graphql/resolvers/group_test.exs @@ -1,8 +1,10 @@ -defmodule MobilizonWeb.Resolvers.GroupResolverTest do +defmodule MobilizonWeb.Resolvers.GroupTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers + import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + @non_existent_username "nonexistent" @new_group_params %{groupname: "new group"} diff --git a/test/mobilizon_web/resolvers/member_test.exs b/test/graphql/resolvers/member_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/member_test.exs rename to test/graphql/resolvers/member_test.exs index cda9c181..b98906ce 100644 --- a/test/mobilizon_web/resolvers/member_test.exs +++ b/test/graphql/resolvers/member_test.exs @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.Resolvers.MemberResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.MemberTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers - import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + setup %{conn: conn} do user = insert(:user) actor = insert(:actor, user: user, preferred_username: "test") diff --git a/test/mobilizon_web/resolvers/participant_test.exs b/test/graphql/resolvers/participant_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/participant_test.exs rename to test/graphql/resolvers/participant_test.exs index 7aadfd4a..66e74475 100644 --- a/test/mobilizon_web/resolvers/participant_test.exs +++ b/test/graphql/resolvers/participant_test.exs @@ -1,10 +1,14 @@ -defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do use MobilizonWeb.ConnCase use Bamboo.Test - alias Mobilizon.Events - alias MobilizonWeb.{AbsintheHelpers, Email} + import Mobilizon.Factory + alias Mobilizon.Events + alias Mobilizon.GraphQL.AbsintheHelpers + + alias MobilizonWeb.Email + @event %{ description: "some body", title: "some title", diff --git a/test/mobilizon_web/resolvers/person_test.exs b/test/graphql/resolvers/person_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/person_test.exs rename to test/graphql/resolvers/person_test.exs index f2af5cc0..730d3d51 100644 --- a/test/mobilizon_web/resolvers/person_test.exs +++ b/test/graphql/resolvers/person_test.exs @@ -1,13 +1,13 @@ -defmodule MobilizonWeb.Resolvers.PersonResolverTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.GraphQL.Resolvers.PersonTest do use Oban.Testing, repo: Mobilizon.Storage.Repo + use MobilizonWeb.ConnCase import Mobilizon.Factory alias Mobilizon.Actors.Actor alias Mobilizon.Service.Workers - alias MobilizonWeb.AbsintheHelpers + alias Mobilizon.GraphQL.AbsintheHelpers @non_existent_username "nonexistent" diff --git a/test/mobilizon_web/resolvers/picture_test.exs b/test/graphql/resolvers/picture_test.exs similarity index 97% rename from test/mobilizon_web/resolvers/picture_test.exs rename to test/graphql/resolvers/picture_test.exs index e1dde528..a8daeca0 100644 --- a/test/mobilizon_web/resolvers/picture_test.exs +++ b/test/graphql/resolvers/picture_test.exs @@ -1,10 +1,13 @@ -defmodule MobilizonWeb.Resolvers.PictureResolverTest do - alias MobilizonWeb.AbsintheHelpers +defmodule Mobilizon.GraphQL.Resolvers.PictureTest do use MobilizonWeb.ConnCase use Bamboo.Test - alias Mobilizon.Media.Picture + import Mobilizon.Factory + alias Mobilizon.Media.Picture + + alias Mobilizon.GraphQL.AbsintheHelpers + setup %{conn: conn} do user = insert(:user) actor = insert(:actor, user: user) diff --git a/test/mobilizon_web/resolvers/report_test.exs b/test/graphql/resolvers/report_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/report_test.exs rename to test/graphql/resolvers/report_test.exs index e068c735..2a083845 100644 --- a/test/mobilizon_web/resolvers/report_test.exs +++ b/test/graphql/resolvers/report_test.exs @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Resolvers.ReportResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.ReportTest do use MobilizonWeb.ConnCase import Mobilizon.Factory @@ -8,7 +8,7 @@ defmodule MobilizonWeb.Resolvers.ReportResolverTest do alias Mobilizon.Reports.{Note, Report} alias Mobilizon.Users.User - alias MobilizonWeb.AbsintheHelpers + alias Mobilizon.GraphQL.AbsintheHelpers describe "Resolver: Report a content" do test "create_report/3 creates a report", %{conn: conn} do diff --git a/test/mobilizon_web/resolvers/search_test.exs b/test/graphql/resolvers/search_test.exs similarity index 98% rename from test/mobilizon_web/resolvers/search_test.exs rename to test/graphql/resolvers/search_test.exs index 9e3d89b0..6f8d436d 100644 --- a/test/mobilizon_web/resolvers/search_test.exs +++ b/test/graphql/resolvers/search_test.exs @@ -1,10 +1,11 @@ -defmodule MobilizonWeb.Resolvers.SearchResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.SearchTest do use MobilizonWeb.ConnCase import Mobilizon.Factory alias Mobilizon.Service.Workers - alias MobilizonWeb.AbsintheHelpers + + alias Mobilizon.GraphQL.AbsintheHelpers setup %{conn: conn} do user = insert(:user) diff --git a/test/mobilizon_web/resolvers/tag_test.exs b/test/graphql/resolvers/tag_test.exs similarity index 92% rename from test/mobilizon_web/resolvers/tag_test.exs rename to test/graphql/resolvers/tag_test.exs index ac288027..3ef15f95 100644 --- a/test/mobilizon_web/resolvers/tag_test.exs +++ b/test/graphql/resolvers/tag_test.exs @@ -1,8 +1,10 @@ -defmodule MobilizonWeb.Resolvers.TagResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.TagTest do use MobilizonWeb.ConnCase - alias MobilizonWeb.AbsintheHelpers + import Mobilizon.Factory + alias Mobilizon.GraphQL.AbsintheHelpers + describe "Tag Resolver" do test "list_tags/3 returns the list of tags", context do tag1 = insert(:tag) diff --git a/test/mobilizon_web/resolvers/user_test.exs b/test/graphql/resolvers/user_test.exs similarity index 99% rename from test/mobilizon_web/resolvers/user_test.exs rename to test/graphql/resolvers/user_test.exs index e0dd8194..74ee6397 100644 --- a/test/mobilizon_web/resolvers/user_test.exs +++ b/test/graphql/resolvers/user_test.exs @@ -1,15 +1,16 @@ -defmodule MobilizonWeb.Resolvers.UserResolverTest do +defmodule Mobilizon.GraphQL.Resolvers.UserTest do use MobilizonWeb.ConnCase + use Bamboo.Test import Mobilizon.Factory - use Bamboo.Test - alias Mobilizon.{Actors, Config, Users} alias Mobilizon.Actors.Actor alias Mobilizon.Users.User - alias MobilizonWeb.{AbsintheHelpers, Email} + alias Mobilizon.GraphQL.AbsintheHelpers + + alias MobilizonWeb.Email @valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"} @valid_single_actor_params %{preferred_username: "test2", keys: "yolo"} diff --git a/test/support/abinthe_helpers.ex b/test/support/abinthe_helpers.ex index d9c8a0c1..8bf05438 100644 --- a/test/support/abinthe_helpers.ex +++ b/test/support/abinthe_helpers.ex @@ -1,10 +1,12 @@ -defmodule MobilizonWeb.AbsintheHelpers do - use Phoenix.ConnTest - @endpoint MobilizonWeb.Endpoint - +defmodule Mobilizon.GraphQL.AbsintheHelpers do @moduledoc """ Absinthe helpers for tests """ + + use Phoenix.ConnTest + + @endpoint MobilizonWeb.Endpoint + def query_skeleton(query, query_name) do %{ "operationName" => "#{query_name}", @@ -23,10 +25,7 @@ defmodule MobilizonWeb.AbsintheHelpers do def graphql_query(conn, options) do conn - |> post( - "/api", - build_query(options[:query], Keyword.get(options, :variables, %{})) - ) + |> post("/api", build_query(options[:query], Keyword.get(options, :variables, %{}))) |> json_response(200) end From b3f8d52bc961852ac5d2faa37513ba00239aa9c3 Mon Sep 17 00:00:00 2001 From: rustra Date: Sun, 26 Jan 2020 21:11:16 +0100 Subject: [PATCH 2/5] Move API under GraphQL context --- lib/federation/activity_pub/activity_pub.ex | 3 ++- lib/federation/activity_pub/relay.ex | 2 +- lib/{mobilizon_web => graphql}/api/comments.ex | 9 ++++----- lib/{mobilizon_web => graphql}/api/events.ex | 6 +++--- lib/{mobilizon_web => graphql}/api/follows.ex | 2 +- lib/{mobilizon_web => graphql}/api/groups.ex | 4 ++-- .../api/participations.ex | 12 +++++++----- lib/{mobilizon_web => graphql}/api/reports.ex | 2 +- lib/{mobilizon_web => graphql}/api/search.ex | 2 +- lib/{mobilizon_web => graphql}/api/utils.ex | 12 +++--------- lib/graphql/resolvers/comment.ex | 2 +- lib/graphql/resolvers/event.ex | 11 +++++------ lib/graphql/resolvers/group.ex | 3 +-- lib/graphql/resolvers/member.ex | 1 + lib/graphql/resolvers/picture.ex | 1 + lib/graphql/resolvers/report.ex | 13 +++++-------- lib/graphql/resolvers/search.ex | 3 ++- lib/graphql/resolvers/tag.ex | 1 + lib/mix/tasks/mobilizon/move_participant_stats.ex | 5 +++-- lib/mix/tasks/mobilizon/relay.ex | 1 + lib/mix/tasks/mobilizon/toot.ex | 3 ++- .../federation/activity_pub/transmogrifier_test.exs | 2 +- test/{mobilizon_web => graphql}/api/report_test.exs | 6 +++--- test/{mobilizon_web => graphql}/api/search_test.exs | 6 +++--- test/graphql/resolvers/admin_test.exs | 2 +- 25 files changed, 56 insertions(+), 58 deletions(-) rename lib/{mobilizon_web => graphql}/api/comments.ex (69%) rename lib/{mobilizon_web => graphql}/api/events.ex (89%) rename lib/{mobilizon_web => graphql}/api/follows.ex (97%) rename lib/{mobilizon_web => graphql}/api/groups.ex (89%) rename lib/{mobilizon_web => graphql}/api/participations.ex (91%) rename lib/{mobilizon_web => graphql}/api/reports.ex (98%) rename lib/{mobilizon_web => graphql}/api/search.ex (98%) rename lib/{mobilizon_web => graphql}/api/utils.ex (80%) rename test/{mobilizon_web => graphql}/api/report_test.exs (98%) rename test/{mobilizon_web => graphql}/api/search_test.exs (95%) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 2bf6edef..b6257e71 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -30,7 +30,8 @@ defmodule Mobilizon.Federation.ActivityPub do alias Mobilizon.Federation.HTTPSignatures.Signature alias Mobilizon.Federation.WebFinger - alias MobilizonWeb.API.Utils, as: APIUtils + alias Mobilizon.GraphQL.API.Utils, as: APIUtils + alias MobilizonWeb.Email.{Admin, Mailer} require Logger diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index 6a0fec7e..f940f235 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -15,7 +15,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier} alias Mobilizon.Federation.WebFinger - alias MobilizonWeb.API.Follows + alias Mobilizon.GraphQL.API.Follows require Logger diff --git a/lib/mobilizon_web/api/comments.ex b/lib/graphql/api/comments.ex similarity index 69% rename from lib/mobilizon_web/api/comments.ex rename to lib/graphql/api/comments.ex index 24fe7977..18bd7ea3 100644 --- a/lib/mobilizon_web/api/comments.ex +++ b/lib/graphql/api/comments.ex @@ -1,7 +1,8 @@ -defmodule MobilizonWeb.API.Comments do +defmodule Mobilizon.GraphQL.API.Comments do @moduledoc """ API for Comments. """ + alias Mobilizon.Events.Comment alias Mobilizon.Federation.ActivityPub @@ -12,8 +13,7 @@ defmodule MobilizonWeb.API.Comments do Creates a comment from an actor """ - @spec create_comment(map()) :: - {:ok, Activity.t(), Comment.t()} | any() + @spec create_comment(map) :: {:ok, Activity.t(), Comment.t()} | any def create_comment(args) do ActivityPub.create(:comment, args, true) end @@ -23,8 +23,7 @@ defmodule MobilizonWeb.API.Comments do Deletes a comment from an actor """ - @spec delete_comment(Comment.t()) :: - {:ok, Activity.t(), Comment.t()} | any() + @spec delete_comment(Comment.t()) :: {:ok, Activity.t(), Comment.t()} | any def delete_comment(%Comment{} = comment) do ActivityPub.delete(comment, true) end diff --git a/lib/mobilizon_web/api/events.ex b/lib/graphql/api/events.ex similarity index 89% rename from lib/mobilizon_web/api/events.ex rename to lib/graphql/api/events.ex index b3a7b58b..fdbb92ae 100644 --- a/lib/mobilizon_web/api/events.ex +++ b/lib/graphql/api/events.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Events do +defmodule Mobilizon.GraphQL.API.Events do @moduledoc """ API for Events. """ @@ -12,7 +12,7 @@ defmodule MobilizonWeb.API.Events do @doc """ Create an event """ - @spec create_event(map()) :: {:ok, Activity.t(), Event.t()} | any() + @spec create_event(map) :: {:ok, Activity.t(), Event.t()} | any def create_event(args) do with organizer_actor <- Map.get(args, :organizer_actor), args <- @@ -27,7 +27,7 @@ defmodule MobilizonWeb.API.Events do @doc """ Update an event """ - @spec update_event(map(), Event.t()) :: {:ok, Activity.t(), Event.t()} | any() + @spec update_event(map, Event.t()) :: {:ok, Activity.t(), Event.t()} | any def update_event(args, %Event{} = event) do with organizer_actor <- Map.get(args, :organizer_actor), args <- diff --git a/lib/mobilizon_web/api/follows.ex b/lib/graphql/api/follows.ex similarity index 97% rename from lib/mobilizon_web/api/follows.ex rename to lib/graphql/api/follows.ex index ca4e11af..1796c80d 100644 --- a/lib/mobilizon_web/api/follows.ex +++ b/lib/graphql/api/follows.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Follows do +defmodule Mobilizon.GraphQL.API.Follows do @moduledoc """ Common API for following, unfollowing, accepting and rejecting stuff. """ diff --git a/lib/mobilizon_web/api/groups.ex b/lib/graphql/api/groups.ex similarity index 89% rename from lib/mobilizon_web/api/groups.ex rename to lib/graphql/api/groups.ex index b8747a8c..4ff5371c 100644 --- a/lib/mobilizon_web/api/groups.ex +++ b/lib/graphql/api/groups.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Groups do +defmodule Mobilizon.GraphQL.API.Groups do @moduledoc """ API for Groups. """ @@ -12,7 +12,7 @@ defmodule MobilizonWeb.API.Groups do @doc """ Create a group """ - @spec create_group(map()) :: {:ok, Activity.t(), Actor.t()} | any() + @spec create_group(map) :: {:ok, Activity.t(), Actor.t()} | any def create_group(args) do with preferred_username <- args |> Map.get(:preferred_username) |> HtmlSanitizeEx.strip_tags() |> String.trim(), diff --git a/lib/mobilizon_web/api/participations.ex b/lib/graphql/api/participations.ex similarity index 91% rename from lib/mobilizon_web/api/participations.ex rename to lib/graphql/api/participations.ex index 4c53d500..a280d7fc 100644 --- a/lib/mobilizon_web/api/participations.ex +++ b/lib/graphql/api/participations.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Participations do +defmodule Mobilizon.GraphQL.API.Participations do @moduledoc """ Common API to join events and groups. """ @@ -27,11 +27,13 @@ defmodule MobilizonWeb.API.Participations do @doc """ Update participation status """ - def update(%Participant{} = participation, %Actor{} = moderator, :participant), - do: accept(participation, moderator) + def update(%Participant{} = participation, %Actor{} = moderator, :participant) do + accept(participation, moderator) + end - def update(%Participant{} = participation, %Actor{} = moderator, :rejected), - do: reject(participation, moderator) + def update(%Participant{} = participation, %Actor{} = moderator, :rejected) do + reject(participation, moderator) + end defp accept( %Participant{} = participation, diff --git a/lib/mobilizon_web/api/reports.ex b/lib/graphql/api/reports.ex similarity index 98% rename from lib/mobilizon_web/api/reports.ex rename to lib/graphql/api/reports.ex index 2281f47e..e5654765 100644 --- a/lib/mobilizon_web/api/reports.ex +++ b/lib/graphql/api/reports.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Reports do +defmodule Mobilizon.GraphQL.API.Reports do @moduledoc """ API for Reports. """ diff --git a/lib/mobilizon_web/api/search.ex b/lib/graphql/api/search.ex similarity index 98% rename from lib/mobilizon_web/api/search.ex rename to lib/graphql/api/search.ex index 7cb2d600..343d179b 100644 --- a/lib/mobilizon_web/api/search.ex +++ b/lib/graphql/api/search.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Search do +defmodule Mobilizon.GraphQL.API.Search do @moduledoc """ API for search. """ diff --git a/lib/mobilizon_web/api/utils.ex b/lib/graphql/api/utils.ex similarity index 80% rename from lib/mobilizon_web/api/utils.ex rename to lib/graphql/api/utils.ex index c785b389..1ff7e328 100644 --- a/lib/mobilizon_web/api/utils.ex +++ b/lib/graphql/api/utils.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.Utils do +defmodule Mobilizon.GraphQL.API.Utils do @moduledoc """ Utils for API. """ @@ -10,11 +10,7 @@ defmodule MobilizonWeb.API.Utils do Creates HTML content from text and mentions """ @spec make_content_html(String.t(), list(), String.t()) :: String.t() - def make_content_html( - text, - additional_tags, - content_type - ) do + def make_content_html(text, additional_tags, content_type) do with {text, mentions, tags} <- format_input(text, content_type, []) do {text, mentions, additional_tags ++ Enum.map(tags, fn {_, tag} -> tag end)} end @@ -24,9 +20,7 @@ defmodule MobilizonWeb.API.Utils do text |> Formatter.html_escape("text/plain") |> Formatter.linkify(options) - |> (fn {text, mentions, tags} -> - {String.replace(text, ~r/\r?\n/, "
"), mentions, tags} - end).() + |> (fn {text, mentions, tags} -> {String.replace(text, ~r/\r?\n/, "
"), mentions, tags} end).() end def format_input(text, "text/html", options) do diff --git a/lib/graphql/resolvers/comment.ex b/lib/graphql/resolvers/comment.ex index 002e1f7d..4779468a 100644 --- a/lib/graphql/resolvers/comment.ex +++ b/lib/graphql/resolvers/comment.ex @@ -9,7 +9,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Comment do alias Mobilizon.Events.Comment, as: CommentModel alias Mobilizon.Users.User - alias MobilizonWeb.API.Comments + alias Mobilizon.GraphQL.API.Comments require Logger diff --git a/lib/graphql/resolvers/event.ex b/lib/graphql/resolvers/event.ex index a502e1cf..8864091c 100644 --- a/lib/graphql/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -8,12 +8,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do alias Mobilizon.Events.{Event, Participant, EventParticipantStats} alias Mobilizon.Users.User + alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.Resolvers.Person alias Mobilizon.Federation.ActivityPub.Activity - alias MobilizonWeb.API - # We limit the max number of events that can be retrieved @event_max_limit 100 @number_of_related_events 3 @@ -231,7 +230,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do {:actor_approve_permission, Mobilizon.Events.moderator_for_event?(participation.event.id, moderator_actor_id)}, {:ok, _activity, participation} <- - MobilizonWeb.API.Participations.update(participation, moderator_actor, new_role) do + API.Participations.update(participation, moderator_actor, new_role) do {:ok, participation} else {:is_owned, nil} -> @@ -268,7 +267,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do {:is_owned, %Actor{} = organizer_actor} <- User.owns_actor(user, organizer_actor_id), args_with_organizer <- Map.put(args, :organizer_actor, organizer_actor), {:ok, %Activity{data: %{"object" => %{"type" => "Event"}}}, %Event{} = event} <- - MobilizonWeb.API.Events.create_event(args_with_organizer) do + API.Events.create_event(args_with_organizer) do {:ok, event} else {:is_owned, nil} -> @@ -302,7 +301,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do User.owns_actor(user, organizer_actor_id), args <- Map.put(args, :organizer_actor, organizer_actor), {:ok, %Activity{data: %{"object" => %{"type" => "Event"}}}, %Event{} = event} <- - MobilizonWeb.API.Events.update_event(args, event) do + API.Events.update_event(args, event) do {:ok, event} else {:error, :event_not_found} -> @@ -360,7 +359,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do end defp do_delete_event(event, federate \\ true) when is_boolean(federate) do - with {:ok, _activity, event} <- MobilizonWeb.API.Events.delete_event(event) do + with {:ok, _activity, event} <- API.Events.delete_event(event) do {:ok, %{id: event.id}} end end diff --git a/lib/graphql/resolvers/group.ex b/lib/graphql/resolvers/group.ex index c2ff0409..99ab2abb 100644 --- a/lib/graphql/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -7,12 +7,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do alias Mobilizon.Actors.{Actor, Member} alias Mobilizon.Users.User + alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.Resolvers.Person alias Mobilizon.Federation.ActivityPub - alias MobilizonWeb.API - require Logger @doc """ diff --git a/lib/graphql/resolvers/member.ex b/lib/graphql/resolvers/member.ex index 65cdd249..fffe483d 100644 --- a/lib/graphql/resolvers/member.ex +++ b/lib/graphql/resolvers/member.ex @@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Member do @moduledoc """ Handles the member-related GraphQL calls """ + alias Mobilizon.Actors alias Mobilizon.Actors.{Actor} diff --git a/lib/graphql/resolvers/picture.ex b/lib/graphql/resolvers/picture.ex index 941ef6fd..d8f4ce72 100644 --- a/lib/graphql/resolvers/picture.ex +++ b/lib/graphql/resolvers/picture.ex @@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do @moduledoc """ Handles the picture-related GraphQL calls """ + alias Mobilizon.Actors.Actor alias Mobilizon.Media alias Mobilizon.Media.Picture diff --git a/lib/graphql/resolvers/report.ex b/lib/graphql/resolvers/report.ex index e8b78199..6e07b10b 100644 --- a/lib/graphql/resolvers/report.ex +++ b/lib/graphql/resolvers/report.ex @@ -11,7 +11,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do alias Mobilizon.Reports.{Note, Report} alias Mobilizon.Users.User - alias MobilizonWeb.API.Reports, as: ReportsAPI + alias Mobilizon.GraphQL.API def list_reports( _parent, @@ -50,7 +50,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do %{context: %{current_user: user}} = _resolution ) do with {:is_owned, %Actor{}} <- User.owns_actor(user, reporter_id), - {:ok, _, %Report{} = report} <- ReportsAPI.report(args) do + {:ok, _, %Report{} = report} <- API.Reports.report(args) do {:ok, report} else {:is_owned, nil} -> @@ -76,8 +76,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do when is_moderator(role) do with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, moderator_id), %Report{} = report <- Mobilizon.Reports.get_report(report_id), - {:ok, %Report{} = report} <- - MobilizonWeb.API.Reports.update_report_status(actor, report, status) do + {:ok, %Report{} = report} <- API.Reports.update_report_status(actor, report, status) do {:ok, report} else {:is_owned, nil} -> @@ -101,8 +100,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do with {:is_owned, %Actor{}} <- User.owns_actor(user, moderator_id), %Report{} = report <- Reports.get_report(report_id), %Actor{} = moderator <- Actors.get_local_actor_with_preload(moderator_id), - {:ok, %Note{} = note} <- - MobilizonWeb.API.Reports.create_report_note(report, moderator, content) do + {:ok, %Note{} = note} <- API.Reports.create_report_note(report, moderator, content) do {:ok, note} end end @@ -116,8 +114,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do with {:is_owned, %Actor{}} <- User.owns_actor(user, moderator_id), %Note{} = note <- Reports.get_note(note_id), %Actor{} = moderator <- Actors.get_local_actor_with_preload(moderator_id), - {:ok, %Note{} = note} <- - MobilizonWeb.API.Reports.delete_report_note(note, moderator) do + {:ok, %Note{} = note} <- API.Reports.delete_report_note(note, moderator) do {:ok, %{id: note.id}} end end diff --git a/lib/graphql/resolvers/search.ex b/lib/graphql/resolvers/search.ex index acb74b96..9c33e94e 100644 --- a/lib/graphql/resolvers/search.ex +++ b/lib/graphql/resolvers/search.ex @@ -2,7 +2,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do @moduledoc """ Handles the event-related GraphQL calls """ - alias MobilizonWeb.API.Search + + alias Mobilizon.GraphQL.API.Search @doc """ Search persons diff --git a/lib/graphql/resolvers/tag.ex b/lib/graphql/resolvers/tag.ex index b7a5dd11..a21eb742 100644 --- a/lib/graphql/resolvers/tag.ex +++ b/lib/graphql/resolvers/tag.ex @@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Tag do @moduledoc """ Handles the tag-related GraphQL calls """ + alias Mobilizon.Events alias Mobilizon.Events.{Event, Tag} diff --git a/lib/mix/tasks/mobilizon/move_participant_stats.ex b/lib/mix/tasks/mobilizon/move_participant_stats.ex index 6ecba7e2..5c31be34 100644 --- a/lib/mix/tasks/mobilizon/move_participant_stats.ex +++ b/lib/mix/tasks/mobilizon/move_participant_stats.ex @@ -7,11 +7,12 @@ defmodule Mix.Tasks.Mobilizon.MoveParticipantStats do use Mix.Task - alias Mobilizon.Storage.Repo + import Ecto.Query + alias Mobilizon.Events alias Mobilizon.Events.Event alias Mobilizon.Events.ParticipantRole - import Ecto.Query + alias Mobilizon.Storage.Repo require Logger diff --git a/lib/mix/tasks/mobilizon/relay.ex b/lib/mix/tasks/mobilizon/relay.ex index f7f0830a..d91b2006 100644 --- a/lib/mix/tasks/mobilizon/relay.ex +++ b/lib/mix/tasks/mobilizon/relay.ex @@ -23,6 +23,7 @@ defmodule Mix.Tasks.Mobilizon.Relay do use Mix.Task alias Mix.Tasks.Mobilizon.Common + alias Mobilizon.Federation.ActivityPub.Relay @shortdoc "Manages remote relays" diff --git a/lib/mix/tasks/mobilizon/toot.ex b/lib/mix/tasks/mobilizon/toot.ex index a8aabe23..3473d8b5 100644 --- a/lib/mix/tasks/mobilizon/toot.ex +++ b/lib/mix/tasks/mobilizon/toot.ex @@ -5,10 +5,11 @@ defmodule Mix.Tasks.Mobilizon.Toot do use Mix.Task - alias MobilizonWeb.API.Comments alias Mobilizon.Actors alias Mobilizon.Actors.Actor + alias Mobilizon.GraphQL.API.Comments + require Logger @shortdoc "Toot to an user" diff --git a/test/federation/activity_pub/transmogrifier_test.exs b/test/federation/activity_pub/transmogrifier_test.exs index 07065c4c..f6730a01 100644 --- a/test/federation/activity_pub/transmogrifier_test.exs +++ b/test/federation/activity_pub/transmogrifier_test.exs @@ -20,7 +20,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier} alias Mobilizon.Federation.ActivityStream.{Convertible} - alias MobilizonWeb.API + alias Mobilizon.GraphQL.API setup_all do HTTPoison.start() diff --git a/test/mobilizon_web/api/report_test.exs b/test/graphql/api/report_test.exs similarity index 98% rename from test/mobilizon_web/api/report_test.exs rename to test/graphql/api/report_test.exs index 03cfaa43..3ce187d4 100644 --- a/test/mobilizon_web/api/report_test.exs +++ b/test/graphql/api/report_test.exs @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.ReportTest do +defmodule Mobilizon.GraphQL.API.ReportTest do use Mobilizon.DataCase import Mobilizon.Factory @@ -9,9 +9,9 @@ defmodule MobilizonWeb.API.ReportTest do alias Mobilizon.Users alias Mobilizon.Users.User - alias Mobilizon.Federation.ActivityPub.{Activity, Relay} + alias Mobilizon.GraphQL.API.Reports - alias MobilizonWeb.API.Reports + alias Mobilizon.Federation.ActivityPub.{Activity, Relay} describe "reports" do test "creates a report on a event" do diff --git a/test/mobilizon_web/api/search_test.exs b/test/graphql/api/search_test.exs similarity index 95% rename from test/mobilizon_web/api/search_test.exs rename to test/graphql/api/search_test.exs index e3d800bc..84959148 100644 --- a/test/mobilizon_web/api/search_test.exs +++ b/test/graphql/api/search_test.exs @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.API.SearchTest do +defmodule Mobilizon.GraphQL.API.SearchTest do use ExUnit.Case, async: false import Mock @@ -9,9 +9,9 @@ defmodule MobilizonWeb.API.SearchTest do alias Mobilizon.Events.Event alias Mobilizon.Storage.Page - alias Mobilizon.Federation.ActivityPub + alias Mobilizon.GraphQL.API.Search - alias MobilizonWeb.API.Search + alias Mobilizon.Federation.ActivityPub test "search an user by username" do with_mock ActivityPub, diff --git a/test/graphql/resolvers/admin_test.exs b/test/graphql/resolvers/admin_test.exs index 7bc2d857..a4e61fce 100644 --- a/test/graphql/resolvers/admin_test.exs +++ b/test/graphql/resolvers/admin_test.exs @@ -10,8 +10,8 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do alias Mobilizon.Federation.ActivityPub.Relay + alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.AbsintheHelpers - alias MobilizonWeb.API describe "Resolver: List the action logs" do @note_content "This a note on a report" From 8856cc2f5507471b224a93f1cd06b706d60b03bc Mon Sep 17 00:00:00 2001 From: rustra Date: Sun, 26 Jan 2020 21:36:50 +0100 Subject: [PATCH 3/5] Rename MobilizonWeb to Mobilizon.Web --- config/config.exs | 16 +- config/dev.exs | 6 +- config/e2e.exs | 2 +- config/prod.exs | 10 +- config/test.exs | 8 +- lib/federation/activity_pub/activity_pub.ex | 18 +- lib/federation/activity_pub/relay.ex | 2 +- lib/federation/activity_pub/transmogrifier.ex | 2 +- lib/federation/activity_pub/utils.ex | 4 +- .../activity_stream/converter/actor.ex | 4 +- .../activity_stream/converter/picture.ex | 2 +- .../activity_stream/converter/utils.ex | 2 +- lib/federation/web_finger/web_finger.ex | 6 +- lib/graphql/api/participations.ex | 2 +- lib/graphql/resolvers/person.ex | 6 +- lib/graphql/resolvers/picture.ex | 4 +- lib/graphql/resolvers/user.ex | 2 +- lib/mobilizon.ex | 8 +- lib/mobilizon/actors/actor.ex | 10 +- lib/mobilizon/actors/actors.ex | 4 +- lib/mobilizon/actors/follower.ex | 2 +- lib/mobilizon/addresses/address.ex | 2 +- lib/mobilizon/events/comment.ex | 4 +- lib/mobilizon/events/event.ex | 4 +- lib/mobilizon/events/events.ex | 2 +- lib/mobilizon/events/participant.ex | 2 +- lib/mobilizon/media/media.ex | 2 +- lib/mobilizon/reports/report.ex | 2 +- lib/mobilizon/users/user.ex | 2 +- lib/mobilizon/users/users.ex | 2 +- lib/mobilizon_web/views/layout_view.ex | 3 - lib/service/export/feed.ex | 8 +- lib/service/formatter/formatter.ex | 2 +- lib/service/metadata/actor.ex | 2 +- lib/service/metadata/event.ex | 4 +- lib/service/metadata/instance.ex | 2 +- lib/{mobilizon_web => web}/auth/context.ex | 4 +- .../auth/error_handler.ex | 2 +- lib/{mobilizon_web => web}/auth/guardian.ex | 2 +- lib/{mobilizon_web => web}/auth/pipeline.ex | 8 +- .../cache/activity_pub.ex | 6 +- lib/{mobilizon_web => web}/cache/cache.ex | 4 +- .../channels/graphql_socket.ex | 6 +- .../controllers/activity_pub_controller.ex | 10 +- .../controllers/fallback_controller.ex | 6 +- .../controllers/feed_controller.ex | 6 +- .../controllers/media_proxy_controller.ex | 8 +- .../controllers/node_info_controller.ex | 8 +- .../controllers/page_controller.ex | 8 +- .../controllers/web_finger_controller.ex | 6 +- lib/{mobilizon_web => web}/email/admin.ex | 10 +- lib/{mobilizon_web => web}/email/checker.ex | 2 +- lib/{mobilizon_web => web}/email/email.ex | 8 +- lib/{mobilizon_web => web}/email/event.ex | 10 +- lib/{mobilizon_web => web}/email/mailer.ex | 2 +- .../email/participation.ex | 12 +- lib/{mobilizon_web => web}/email/user.ex | 12 +- lib/{mobilizon_web => web}/endpoint.ex | 8 +- lib/{mobilizon_web => web}/gettext.ex | 8 +- lib/{mobilizon_web => web}/mobilizon_web.ex | 24 +-- .../plugs/federating.ex | 4 +- .../plugs/http_signatures.ex | 2 +- .../plugs/mapped_signature_to_identity.ex | 2 +- .../plugs/uploaded_media.ex | 6 +- .../proxy/media_proxy.ex | 10 +- .../proxy/reverse_proxy.ex | 6 +- lib/{mobilizon_web => web}/router.ex | 34 +-- .../templates/email/email.html.eex | 4 +- .../templates/email/email.text.eex | 0 .../event_participation_approved.html.eex | 2 +- .../event_participation_approved.text.eex | 2 +- .../event_participation_rejected.html.eex | 0 .../event_participation_rejected.text.eex | 0 .../templates/email/event_updated.html.eex | 2 +- .../templates/email/event_updated.text.eex | 2 +- .../templates/email/password_reset.html.eex | 2 +- .../templates/email/password_reset.text.eex | 2 +- .../email/registration_confirmation.html.eex | 2 +- .../email/registration_confirmation.text.eex | 2 +- .../templates/email/report.html.eex | 4 +- .../templates/email/report.text.eex | 2 +- .../upload/filter/anonymize_filename.ex | 8 +- .../upload/filter/dedupe.ex | 6 +- .../upload/filter/filter.ex | 10 +- .../upload/filter/mogrify.ex | 6 +- .../upload/filter/optimize.ex | 6 +- lib/{mobilizon_web => web}/upload/mime.ex | 2 +- lib/{mobilizon_web => web}/upload/upload.ex | 14 +- .../upload/uploader/local.ex | 4 +- .../upload/uploader/uploader.ex | 8 +- .../views/activity_pub/actor_view.ex | 4 +- .../views/activity_pub/object_view.ex | 4 +- .../views/changeset_view.ex | 6 +- .../views/email_view.ex | 6 +- .../views/error_helpers.ex | 6 +- .../views/error_view.ex | 4 +- .../views/json_ld/object_view.ex | 8 +- lib/web/views/layout_view.ex | 3 + lib/{mobilizon_web => web}/views/page_view.ex | 4 +- mix.exs | 196 +++++++++--------- .../activity_pub/transmogrifier_test.exs | 4 +- test/federation/activity_pub/utils_test.exs | 4 +- .../federation/web_finger/web_finger_test.exs | 4 +- .../relay/fetch_relay_follow.json | 2 +- .../relay/fetch_relay_unfollow.json | 2 +- test/graphql/resolvers/address_test.exs | 2 +- test/graphql/resolvers/admin_test.exs | 2 +- test/graphql/resolvers/comment_test.exs | 2 +- test/graphql/resolvers/config_test.exs | 2 +- test/graphql/resolvers/event_test.exs | 6 +- test/graphql/resolvers/feed_token_test.exs | 2 +- test/graphql/resolvers/group_test.exs | 4 +- test/graphql/resolvers/member_test.exs | 2 +- test/graphql/resolvers/participant_test.exs | 4 +- test/graphql/resolvers/person_test.exs | 8 +- test/graphql/resolvers/picture_test.exs | 4 +- test/graphql/resolvers/report_test.exs | 2 +- test/graphql/resolvers/search_test.exs | 2 +- test/graphql/resolvers/tag_test.exs | 2 +- test/graphql/resolvers/user_test.exs | 4 +- test/mobilizon/actors/actors_test.exs | 4 +- test/mobilizon/media/media_test.exs | 2 +- test/mobilizon_web/views/error_view_test.exs | 19 -- test/mobilizon_web/views/layout_view_test.exs | 3 - test/mobilizon_web/views/page_view_test.exs | 3 - test/support/abinthe_helpers.ex | 2 +- test/support/channel_case.ex | 4 +- test/support/conn_case.ex | 8 +- test/support/data_case.ex | 4 +- test/support/factory.ex | 8 +- .../activity_pub_controller_test.exs | 14 +- .../controllers/feed_controller_test.exs | 8 +- .../controllers/nodeinfo_controller_test.exs | 8 +- .../controllers/page_controller_test.exs | 8 +- .../controllers/webfinger_controller_test.exs | 6 +- .../plugs/federating_test.exs | 6 +- .../mapped_identity_to_signature_test.exs | 6 +- .../plugs/uploaded_media_test.exs | 6 +- .../proxy/media_proxy_test.exs | 18 +- .../upload/upload_test.exs | 16 +- test/web/views/error_view_test.exs | 19 ++ test/web/views/layout_view_test.exs | 3 + test/web/views/page_view_test.exs | 3 + 143 files changed, 490 insertions(+), 490 deletions(-) delete mode 100644 lib/mobilizon_web/views/layout_view.ex rename lib/{mobilizon_web => web}/auth/context.ex (85%) rename lib/{mobilizon_web => web}/auth/error_handler.ex (83%) rename lib/{mobilizon_web => web}/auth/guardian.ex (97%) rename lib/{mobilizon_web => web}/auth/pipeline.ex (56%) rename lib/{mobilizon_web => web}/cache/activity_pub.ex (94%) rename lib/{mobilizon_web => web}/cache/cache.ex (90%) rename lib/{mobilizon_web => web}/channels/graphql_socket.ex (84%) rename lib/{mobilizon_web => web}/controllers/activity_pub_controller.ex (94%) rename lib/{mobilizon_web => web}/controllers/fallback_controller.ex (69%) rename lib/{mobilizon_web => web}/controllers/feed_controller.ex (93%) rename lib/{mobilizon_web => web}/controllers/media_proxy_controller.ex (90%) rename lib/{mobilizon_web => web}/controllers/node_info_controller.ex (93%) rename lib/{mobilizon_web => web}/controllers/page_controller.ex (90%) rename lib/{mobilizon_web => web}/controllers/web_finger_controller.ex (88%) rename lib/{mobilizon_web => web}/email/admin.ex (76%) rename lib/{mobilizon_web => web}/email/checker.ex (91%) rename lib/{mobilizon_web => web}/email/email.ex (64%) rename lib/{mobilizon_web => web}/email/event.ex (90%) rename lib/{mobilizon_web => web}/email/mailer.ex (68%) rename lib/{mobilizon_web => web}/email/participation.ex (88%) rename lib/{mobilizon_web => web}/email/user.ex (95%) rename lib/{mobilizon_web => web}/endpoint.ex (90%) rename lib/{mobilizon_web => web}/gettext.ex (87%) rename lib/{mobilizon_web => web}/mobilizon_web.ex (72%) rename lib/{mobilizon_web => web}/plugs/federating.ex (84%) rename lib/{mobilizon_web => web}/plugs/http_signatures.ex (96%) rename lib/{mobilizon_web => web}/plugs/mapped_signature_to_identity.ex (97%) rename lib/{mobilizon_web => web}/plugs/uploaded_media.ex (91%) rename lib/{mobilizon_web => web}/proxy/media_proxy.ex (85%) rename lib/{mobilizon_web => web}/proxy/reverse_proxy.ex (98%) rename lib/{mobilizon_web => web}/router.ex (84%) rename lib/{mobilizon_web => web}/templates/email/email.html.eex (95%) rename lib/{mobilizon_web => web}/templates/email/email.text.eex (100%) rename lib/{mobilizon_web => web}/templates/email/event_participation_approved.html.eex (91%) rename lib/{mobilizon_web => web}/templates/email/event_participation_approved.text.eex (85%) rename lib/{mobilizon_web => web}/templates/email/event_participation_rejected.html.eex (100%) rename lib/{mobilizon_web => web}/templates/email/event_participation_rejected.text.eex (100%) rename lib/{mobilizon_web => web}/templates/email/event_updated.html.eex (94%) rename lib/{mobilizon_web => web}/templates/email/event_updated.text.eex (94%) rename lib/{mobilizon_web => web}/templates/email/password_reset.html.eex (91%) rename lib/{mobilizon_web => web}/templates/email/password_reset.text.eex (86%) rename lib/{mobilizon_web => web}/templates/email/registration_confirmation.html.eex (90%) rename lib/{mobilizon_web => web}/templates/email/registration_confirmation.text.eex (79%) rename lib/{mobilizon_web => web}/templates/email/report.html.eex (94%) rename lib/{mobilizon_web => web}/templates/email/report.text.eex (86%) rename lib/{mobilizon_web => web}/upload/filter/anonymize_filename.ex (77%) rename lib/{mobilizon_web => web}/upload/filter/dedupe.ex (84%) rename lib/{mobilizon_web => web}/upload/filter/filter.ex (76%) rename lib/{mobilizon_web => web}/upload/filter/mogrify.ex (86%) rename lib/{mobilizon_web => web}/upload/filter/optimize.ex (77%) rename lib/{mobilizon_web => web}/upload/mime.ex (98%) rename lib/{mobilizon_web => web}/upload/upload.ex (93%) rename lib/{mobilizon_web => web}/upload/uploader/local.ex (94%) rename lib/{mobilizon_web => web}/upload/uploader/uploader.ex (91%) rename lib/{mobilizon_web => web}/views/activity_pub/actor_view.ex (98%) rename lib/{mobilizon_web => web}/views/activity_pub/object_view.ex (90%) rename lib/{mobilizon_web => web}/views/changeset_view.ex (78%) rename lib/{mobilizon_web => web}/views/email_view.ex (70%) rename lib/{mobilizon_web => web}/views/error_helpers.ex (85%) rename lib/{mobilizon_web => web}/views/error_view.ex (94%) rename lib/{mobilizon_web => web}/views/json_ld/object_view.ex (91%) create mode 100644 lib/web/views/layout_view.ex rename lib/{mobilizon_web => web}/views/page_view.ex (97%) delete mode 100644 test/mobilizon_web/views/error_view_test.exs delete mode 100644 test/mobilizon_web/views/layout_view_test.exs delete mode 100644 test/mobilizon_web/views/page_view_test.exs rename test/{mobilizon_web => web}/controllers/activity_pub_controller_test.exs (97%) rename test/{mobilizon_web => web}/controllers/feed_controller_test.exs (98%) rename test/{mobilizon_web => web}/controllers/nodeinfo_controller_test.exs (91%) rename test/{mobilizon_web => web}/controllers/page_controller_test.exs (92%) rename test/{mobilizon_web => web}/controllers/webfinger_controller_test.exs (92%) rename test/{mobilizon_web => web}/plugs/federating_test.exs (85%) rename test/{mobilizon_web => web}/plugs/mapped_identity_to_signature_test.exs (93%) rename test/{mobilizon_web => web}/plugs/uploaded_media_test.exs (91%) rename test/{mobilizon_web => web}/proxy/media_proxy_test.exs (90%) rename test/{mobilizon_web => web}/upload/upload_test.exs (91%) create mode 100644 test/web/views/error_view_test.exs create mode 100644 test/web/views/layout_view_test.exs create mode 100644 test/web/views/page_view_test.exs diff --git a/config/config.exs b/config/config.exs index 64e0bdc0..a6a947e7 100644 --- a/config/config.exs +++ b/config/config.exs @@ -36,18 +36,18 @@ config :mime, :types, %{ } # Configures the endpoint -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, url: [host: "localhost"], secret_key_base: "1yOazsoE0Wqu4kXk3uC5gu3jDbShOimTCzyFL3OjCdBmOXMyHX87Qmf3+Tu9s0iM", - render_errors: [view: MobilizonWeb.ErrorView, accepts: ~w(html json)], + render_errors: [view: Mobilizon.Web.ErrorView, accepts: ~w(html json)], pubsub: [name: Mobilizon.PubSub, adapter: Phoenix.PubSub.PG2] # Upload configuration -config :mobilizon, MobilizonWeb.Upload, - uploader: MobilizonWeb.Upload.Uploader.Local, +config :mobilizon, Mobilizon.Web.Upload, + uploader: Mobilizon.Web.Upload.Uploader.Local, filters: [ - MobilizonWeb.Upload.Filter.Dedupe, - MobilizonWeb.Upload.Filter.Optimize + Mobilizon.Web.Upload.Filter.Dedupe, + Mobilizon.Web.Upload.Filter.Optimize ], link_name: true, proxy_remote: false, @@ -60,7 +60,7 @@ config :mobilizon, MobilizonWeb.Upload, ] ] -config :mobilizon, MobilizonWeb.Upload.Uploader.Local, uploads: "uploads" +config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "uploads" config :mobilizon, :media_proxy, enabled: true, @@ -78,7 +78,7 @@ config :logger, :console, format: "$time $metadata[$level] $message\n", metadata: [:request_id] -config :mobilizon, MobilizonWeb.Auth.Guardian, +config :mobilizon, Mobilizon.Web.Auth.Guardian, issuer: "mobilizon", secret_key: "ty0WM7YBE3ojvxoUQxo8AERrNpfbXnIJ82ovkPdqbUFw31T5LcK8wGjaOiReVQjo" diff --git a/config/dev.exs b/config/dev.exs index ac5f5a92..32883da9 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -6,7 +6,7 @@ import Config # The watchers configuration can be used to run external # watchers to your application. For example, we use it # with brunch.io to recompile .js and .css sources. -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, http: [ port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4000 ], @@ -39,7 +39,7 @@ config :mobilizon, MobilizonWeb.Endpoint, # different ports. # Watch static and templates for browser reloading. -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, live_reload: [ patterns: [ ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, @@ -61,7 +61,7 @@ config :phoenix, :stacktrace_depth, 20 # Initialize plugs at runtime for faster development compilation config :phoenix, :plug_init_mode, :runtime -config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.LocalAdapter +config :mobilizon, Mobilizon.Web.Email.Mailer, adapter: Bamboo.LocalAdapter # Configure your database config :mobilizon, Mobilizon.Storage.Repo, diff --git a/config/e2e.exs b/config/e2e.exs index 5af46111..18f33210 100644 --- a/config/e2e.exs +++ b/config/e2e.exs @@ -2,7 +2,7 @@ import Config import_config "dev.exs" -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, http: [ port: 4000 ], diff --git a/config/prod.exs b/config/prod.exs index af0ae23b..4ff43c09 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,6 +1,6 @@ import Config -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, http: [ port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4000, transport_options: [socket_opts: [:inet6]] @@ -24,7 +24,7 @@ config :mobilizon, Mobilizon.Storage.Repo, port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432", pool_size: 15 -config :mobilizon, MobilizonWeb.Email.Mailer, +config :mobilizon, Mobilizon.Web.Email.Mailer, adapter: Bamboo.SMTPAdapter, server: "localhost", hostname: "localhost", @@ -53,7 +53,7 @@ config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geos # To get SSL working, you will need to add the `https` key # to the previous section and set your `:url` port to 443: # -# config :mobilizon, MobilizonWeb.Endpoint, +# config :mobilizon, Mobilizon.Web.Endpoint, # ... # url: [host: "example.com", port: 443], # https: [:inet6, @@ -68,7 +68,7 @@ config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geos # We also recommend setting `force_ssl`, ensuring no data is # ever sent via http, always redirecting to https: # -# config :mobilizon, MobilizonWeb.Endpoint, +# config :mobilizon, Mobilizon.Web.Endpoint, # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. @@ -83,5 +83,5 @@ config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geos # Alternatively, you can configure exactly which server to # start per endpoint: # -# config :mobilizon, MobilizonWeb.Endpoint, server: true +# config :mobilizon, Mobilizon.Web.Endpoint, server: true # diff --git a/config/test.exs b/config/test.exs index 7a43f0ed..c3f70f21 100644 --- a/config/test.exs +++ b/config/test.exs @@ -6,7 +6,7 @@ config :mobilizon, :instance, # We don't run a server during test. If one is required, # you can enable the server option below. -config :mobilizon, MobilizonWeb.Endpoint, +config :mobilizon, Mobilizon.Web.Endpoint, http: [ port: System.get_env("MOBILIZON_INSTANCE_PORT") || 80 ], @@ -30,11 +30,11 @@ config :mobilizon, Mobilizon.Storage.Repo, hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost", pool: Ecto.Adapters.SQL.Sandbox -config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.TestAdapter +config :mobilizon, Mobilizon.Web.Email.Mailer, adapter: Bamboo.TestAdapter -config :mobilizon, MobilizonWeb.Upload, filters: [], link_name: false +config :mobilizon, Mobilizon.Web.Upload, filters: [], link_name: false -config :mobilizon, MobilizonWeb.Upload.Uploader.Local, uploads: "test/uploads" +config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "test/uploads" config :exvcr, vcr_cassette_library_dir: "test/fixtures/vcr_cassettes" diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index b6257e71..d97b9d53 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -32,7 +32,7 @@ defmodule Mobilizon.Federation.ActivityPub do alias Mobilizon.GraphQL.API.Utils, as: APIUtils - alias MobilizonWeb.Email.{Admin, Mailer} + alias Mobilizon.Web.Email.{Admin, Mailer} require Logger @@ -318,7 +318,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 || "#{MobilizonWeb.Endpoint.url()}/unfollow/#{follow_id}/activity", + activity_id || "#{Mobilizon.Web.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 +483,7 @@ defmodule Mobilizon.Federation.ActivityPub do # If it's an exclusion it should be something else "actor" => actor_url, "object" => event_url, - "id" => "#{MobilizonWeb.Endpoint.url()}/leave/event/#{participant.id}" + "id" => "#{Mobilizon.Web.Endpoint.url()}/leave/event/#{participant.id}" }, audience <- Audience.calculate_to_and_cc_from_mentions(participant), @@ -778,7 +778,7 @@ defmodule Mobilizon.Federation.ActivityPub do make_accept_join_data( follower_as_data, Map.merge(additional, %{ - "id" => "#{MobilizonWeb.Endpoint.url()}/accept/follow/#{follower.id}", + "id" => "#{Mobilizon.Web.Endpoint.url()}/accept/follow/#{follower.id}", "to" => [follower.actor.url], "cc" => [], "actor" => follower.target_actor.url @@ -797,7 +797,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(MobilizonWeb.Endpoint, participant.actor, + Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor, event_person_participation_changed: participant.actor.id ), participant_as_data <- Convertible.model_to_as(participant), @@ -807,7 +807,7 @@ defmodule Mobilizon.Federation.ActivityPub do make_accept_join_data( participant_as_data, Map.merge(Map.merge(audience, additional), %{ - "id" => "#{MobilizonWeb.Endpoint.url()}/accept/join/#{participant.id}" + "id" => "#{Mobilizon.Web.Endpoint.url()}/accept/join/#{participant.id}" }) ) do {:ok, participant, update_data} @@ -823,7 +823,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(MobilizonWeb.Endpoint, participant.actor, + Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor, event_person_participation_changed: participant.actor.id ), participant_as_data <- Convertible.model_to_as(participant), @@ -839,7 +839,7 @@ defmodule Mobilizon.Federation.ActivityPub do reject_data |> Map.merge(audience) |> Map.merge(%{ - "id" => "#{MobilizonWeb.Endpoint.url()}/reject/join/#{participant.id}" + "id" => "#{Mobilizon.Web.Endpoint.url()}/reject/join/#{participant.id}" }) do {:ok, participant, update_data} else @@ -866,7 +866,7 @@ defmodule Mobilizon.Federation.ActivityPub do reject_data |> Map.merge(audience) |> Map.merge(%{ - "id" => "#{MobilizonWeb.Endpoint.url()}/reject/follow/#{follower.id}" + "id" => "#{Mobilizon.Web.Endpoint.url()}/reject/follow/#{follower.id}" }) do {:ok, follower, update_data} else diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index f940f235..800fe98d 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -28,7 +28,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("#{MobilizonWeb.Endpoint.url()}/relay") do + Actors.get_or_create_instance_actor_by_url("#{Mobilizon.Web.Endpoint.url()}/relay") do actor end end diff --git a/lib/federation/activity_pub/transmogrifier.ex b/lib/federation/activity_pub/transmogrifier.ex index 21ae9c2d..34e57b8b 100644 --- a/lib/federation/activity_pub/transmogrifier.ex +++ b/lib/federation/activity_pub/transmogrifier.ex @@ -17,7 +17,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do alias Mobilizon.Federation.ActivityPub.{Activity, Utils} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible} - alias MobilizonWeb.Email.Participation + alias Mobilizon.Web.Email.Participation require Logger diff --git a/lib/federation/activity_pub/utils.ex b/lib/federation/activity_pub/utils.ex index 016e8f21..3349d358 100644 --- a/lib/federation/activity_pub/utils.ex +++ b/lib/federation/activity_pub/utils.ex @@ -198,7 +198,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do Save picture data from %Plug.Upload{} and return AS Link data. """ def make_picture_data(%Plug.Upload{} = picture, opts) do - case MobilizonWeb.Upload.store(picture, opts) do + case Mobilizon.Web.Upload.store(picture, opts) do {:ok, picture} -> picture @@ -219,7 +219,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do """ def make_picture_data(picture) when is_map(picture) do with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <- - MobilizonWeb.Upload.store(picture.file), + Mobilizon.Web.Upload.store(picture.file), {:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)}, {:ok, %Picture{file: _file} = picture} <- Mobilizon.Media.create_picture(%{ diff --git a/lib/federation/activity_stream/converter/actor.ex b/lib/federation/activity_stream/converter/actor.ex index 5468c6de..f3bcf00a 100644 --- a/lib/federation/activity_stream/converter/actor.ex +++ b/lib/federation/activity_stream/converter/actor.ex @@ -29,14 +29,14 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do data["icon"]["url"] && %{ "name" => data["icon"]["name"] || "avatar", - "url" => MobilizonWeb.MediaProxy.url(data["icon"]["url"]) + "url" => Mobilizon.Web.MediaProxy.url(data["icon"]["url"]) } banner = data["image"]["url"] && %{ "name" => data["image"]["name"] || "banner", - "url" => MobilizonWeb.MediaProxy.url(data["image"]["url"]) + "url" => Mobilizon.Web.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 f2f29d1d..6fdc0173 100644 --- a/lib/federation/activity_stream/converter/picture.ex +++ b/lib/federation/activity_stream/converter/picture.ex @@ -34,7 +34,7 @@ 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}} <- - MobilizonWeb.Upload.store(%{body: body, name: name}), + 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(%{ "file" => %{ diff --git a/lib/federation/activity_stream/converter/utils.ex b/lib/federation/activity_stream/converter/utils.ex index 1783ef81..7cd7203d 100644 --- a/lib/federation/activity_stream/converter/utils.ex +++ b/lib/federation/activity_stream/converter/utils.ex @@ -40,7 +40,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do def build_tags(tags) do Enum.map(tags, fn %Tag{} = tag -> %{ - "href" => MobilizonWeb.Endpoint.url() <> "/tags/#{tag.slug}", + "href" => Mobilizon.Web.Endpoint.url() <> "/tags/#{tag.slug}", "name" => "##{tag.title}", "type" => "Hashtag" } diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index bf71c384..1aec9a27 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -17,7 +17,7 @@ defmodule Mobilizon.Federation.WebFinger do require Logger def host_meta do - base_url = MobilizonWeb.Endpoint.url() + base_url = Mobilizon.Web.Endpoint.url() { :XRD, @@ -35,7 +35,7 @@ defmodule Mobilizon.Federation.WebFinger do end def webfinger(resource, "JSON") do - host = MobilizonWeb.Endpoint.host() + host = Mobilizon.Web.Endpoint.host() regex = ~r/(acct:)?(?\w+)@#{host}/ with %{"name" => name} <- Regex.named_captures(regex, resource), @@ -59,7 +59,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}@#{MobilizonWeb.Endpoint.host()}", + "subject" => "acct:#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", "aliases" => [actor.url], "links" => [ %{"rel" => "self", "type" => "application/activity+json", "href" => actor.url}, diff --git a/lib/graphql/api/participations.ex b/lib/graphql/api/participations.ex index a280d7fc..740f82f3 100644 --- a/lib/graphql/api/participations.ex +++ b/lib/graphql/api/participations.ex @@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.API.Participations do alias Mobilizon.Federation.ActivityPub - alias MobilizonWeb.Email.Participation + alias Mobilizon.Web.Email.Participation @spec join(Event.t(), Actor.t()) :: {:ok, Participant.t()} def join(%Event{id: event_id} = event, %Actor{id: actor_id} = actor) do diff --git a/lib/graphql/resolvers/person.ex b/lib/graphql/resolvers/person.ex index 8ec9241b..b16a1f76 100644 --- a/lib/graphql/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -157,7 +157,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do pic = args[key][:picture] with {:ok, %{name: name, url: url, content_type: content_type, size: _size}} <- - MobilizonWeb.Upload.store(pic.file, type: key, description: pic.alt) do + Mobilizon.Web.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 +236,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, MobilizonWeb.MediaProxy.url(avatar_url))) + actor |> Map.put(:avatar, avatar |> Map.put(:url, Mobilizon.Web.MediaProxy.url(avatar_url))) end @spec proxify_avatar(Actor.t()) :: Actor.t() @@ -244,7 +244,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, MobilizonWeb.MediaProxy.url(banner_url))) + actor |> Map.put(:banner, banner |> Map.put(:url, Mobilizon.Web.MediaProxy.url(banner_url))) end @spec proxify_banner(Actor.t()) :: Actor.t() diff --git a/lib/graphql/resolvers/picture.ex b/lib/graphql/resolvers/picture.ex index d8f4ce72..be28f34d 100644 --- a/lib/graphql/resolvers/picture.ex +++ b/lib/graphql/resolvers/picture.ex @@ -18,7 +18,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do @doc """ Get picture for an event that has an attached - See MobilizonWeb.Resolvers.Event.create_event/3 + See Mobilizon.Web.Resolvers.Event.create_event/3 """ def picture(%{picture: picture} = _parent, _args, _resolution), do: {:ok, picture} def picture(_parent, %{id: picture_id}, _resolution), do: do_fetch_picture(picture_id) @@ -53,7 +53,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do ) do with {:is_owned, %Actor{}} <- User.owns_actor(user, actor_id), {:ok, %{name: _name, url: url, content_type: content_type, size: size}} <- - MobilizonWeb.Upload.store(file), + Mobilizon.Web.Upload.store(file), args <- args |> Map.put(:url, url) diff --git a/lib/graphql/resolvers/user.ex b/lib/graphql/resolvers/user.ex index 4b4993ed..2194f41f 100644 --- a/lib/graphql/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias MobilizonWeb.{Auth, Email} + alias Mobilizon.Web.{Auth, Email} require Logger diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index 6f31f7f6..b5f0589b 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -26,7 +26,7 @@ defmodule Mobilizon do @spec user_agent :: String.t() def user_agent do - info = "#{MobilizonWeb.Endpoint.url()} <#{Config.get([:instance, :email], "")}>" + info = "#{Mobilizon.Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>" "#{named_version()}; #{info}" end @@ -37,8 +37,8 @@ defmodule Mobilizon do children = [ # supervisors Mobilizon.Storage.Repo, - MobilizonWeb.Endpoint, - {Absinthe.Subscription, [MobilizonWeb.Endpoint]}, + Mobilizon.Web.Endpoint, + {Absinthe.Subscription, [Mobilizon.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 - MobilizonWeb.Endpoint.config_change(changed, removed) + Mobilizon.Web.Endpoint.config_change(changed, removed) :ok end diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 50de3513..6857039b 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -15,8 +15,8 @@ defmodule Mobilizon.Actors.Actor do alias Mobilizon.Users.User alias Mobilizon.Mention - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes require Logger @@ -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, "#{MobilizonWeb.Endpoint.url()}/inbox") + |> put_change(:shared_inbox_url, "#{Mobilizon.Web.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" => "#{MobilizonWeb.Endpoint.url()}/inbox", + "inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox", "followers_url" => "#{url}/followers", "following_url" => "#{url}/following", - "shared_inbox_url" => "#{MobilizonWeb.Endpoint.url()}/inbox", + "shared_inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox", "type" => :Application } end diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 44c562d7..5b43d3bc 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -755,7 +755,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 MobilizonWeb.Upload.remove(url) do + case Mobilizon.Web.Upload.remove(url) do {:ok, _value} -> {:ok, actor} @@ -774,7 +774,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 - MobilizonWeb.Upload.remove(old_url) + Mobilizon.Web.Upload.remove(old_url) end end end) diff --git a/lib/mobilizon/actors/follower.ex b/lib/mobilizon/actors/follower.ex index 9b29e4c9..a397677d 100644 --- a/lib/mobilizon/actors/follower.ex +++ b/lib/mobilizon/actors/follower.ex @@ -65,6 +65,6 @@ defmodule Mobilizon.Actors.Follower do changeset |> put_change(:id, uuid) - |> put_change(:url, "#{MobilizonWeb.Endpoint.url()}/follow/#{uuid}") + |> put_change(:url, "#{Mobilizon.Web.Endpoint.url()}/follow/#{uuid}") end end diff --git a/lib/mobilizon/addresses/address.ex b/lib/mobilizon/addresses/address.ex index ec04a749..ce2a7dd4 100644 --- a/lib/mobilizon/addresses/address.ex +++ b/lib/mobilizon/addresses/address.ex @@ -65,7 +65,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, "#{MobilizonWeb.Endpoint.url()}/address/#{Ecto.UUID.generate()}") + url = Map.get(changes, :url, "#{Mobilizon.Web.Endpoint.url()}/address/#{Ecto.UUID.generate()}") put_change(changeset, :url, url) end diff --git a/lib/mobilizon/events/comment.ex b/lib/mobilizon/events/comment.ex index b3af573d..889755af 100644 --- a/lib/mobilizon/events/comment.ex +++ b/lib/mobilizon/events/comment.ex @@ -11,8 +11,8 @@ defmodule Mobilizon.Events.Comment do alias Mobilizon.Events.{Comment, CommentVisibility, Event, Tag} alias Mobilizon.Mention - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes @type t :: %__MODULE__{ text: String.t(), diff --git a/lib/mobilizon/events/event.ex b/lib/mobilizon/events/event.ex index 603d858a..2702100b 100644 --- a/lib/mobilizon/events/event.ex +++ b/lib/mobilizon/events/event.ex @@ -33,8 +33,8 @@ defmodule Mobilizon.Events.Event do alias Mobilizon.Mention alias Mobilizon.Storage.Repo - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes @type t :: %__MODULE__{ url: String.t(), diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 0c277892..c26d615f 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -31,7 +31,7 @@ defmodule Mobilizon.Events do alias Mobilizon.Storage.{Page, Repo} alias Mobilizon.Users.User - alias MobilizonWeb.Email + alias Mobilizon.Web.Email defenum(EventVisibility, :event_visibility, [ :public, diff --git a/lib/mobilizon/events/participant.ex b/lib/mobilizon/events/participant.ex index a5bd7080..affaf492 100644 --- a/lib/mobilizon/events/participant.ex +++ b/lib/mobilizon/events/participant.ex @@ -11,7 +11,7 @@ defmodule Mobilizon.Events.Participant do alias Mobilizon.Events alias Mobilizon.Events.{Event, ParticipantRole} - alias MobilizonWeb.Endpoint + alias Mobilizon.Web.Endpoint @type t :: %__MODULE__{ role: ParticipantRole.t(), diff --git a/lib/mobilizon/media/media.ex b/lib/mobilizon/media/media.ex index 7f9b6fe8..ccb336a7 100644 --- a/lib/mobilizon/media/media.ex +++ b/lib/mobilizon/media/media.ex @@ -62,7 +62,7 @@ defmodule Mobilizon.Media do Multi.new() |> Multi.delete(:picture, picture) |> Multi.run(:remove, fn _repo, %{picture: %Picture{file: %File{url: url}}} -> - MobilizonWeb.Upload.remove(url) + Mobilizon.Web.Upload.remove(url) end) |> Repo.transaction() diff --git a/lib/mobilizon/reports/report.ex b/lib/mobilizon/reports/report.ex index 38818b55..8aa90840 100644 --- a/lib/mobilizon/reports/report.ex +++ b/lib/mobilizon/reports/report.ex @@ -71,7 +71,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 <- "#{MobilizonWeb.Endpoint.url()}/report/#{Ecto.UUID.generate()}" do + url <- "#{Mobilizon.Web.Endpoint.url()}/report/#{Ecto.UUID.generate()}" do put_change(changeset, :url, url) else _ -> changeset diff --git a/lib/mobilizon/users/user.ex b/lib/mobilizon/users/user.ex index 919daf92..e78e5ae8 100644 --- a/lib/mobilizon/users/user.ex +++ b/lib/mobilizon/users/user.ex @@ -12,7 +12,7 @@ defmodule Mobilizon.Users.User do alias Mobilizon.Events.FeedToken alias Mobilizon.Users.UserRole - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @type t :: %__MODULE__{ email: String.t(), diff --git a/lib/mobilizon/users/users.ex b/lib/mobilizon/users/users.ex index cb6c3e66..79b98db7 100644 --- a/lib/mobilizon/users/users.ex +++ b/lib/mobilizon/users/users.ex @@ -13,7 +13,7 @@ defmodule Mobilizon.Users do alias Mobilizon.Storage.{Page, Repo} alias Mobilizon.Users.User - alias MobilizonWeb.Auth + alias Mobilizon.Web.Auth @type tokens :: %{ required(:access_token) => String.t(), diff --git a/lib/mobilizon_web/views/layout_view.ex b/lib/mobilizon_web/views/layout_view.ex deleted file mode 100644 index 961a8471..00000000 --- a/lib/mobilizon_web/views/layout_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule MobilizonWeb.LayoutView do - use MobilizonWeb, :view -end diff --git a/lib/service/export/feed.ex b/lib/service/export/feed.ex index ae0f3f2b..4ecd7719 100644 --- a/lib/service/export/feed.ex +++ b/lib/service/export/feed.ex @@ -3,7 +3,7 @@ defmodule Mobilizon.Service.Export.Feed do Serve Atom Syndication Feeds. """ - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext alias Atomex.{Entry, Feed} @@ -12,8 +12,8 @@ defmodule Mobilizon.Service.Export.Feed do alias Mobilizon.Events.{Event, FeedToken} alias Mobilizon.Users.User - alias MobilizonWeb.{Endpoint, MediaProxy} - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.{Endpoint, MediaProxy} + alias Mobilizon.Web.Router.Helpers, as: Routes require Logger @@ -74,7 +74,7 @@ defmodule Mobilizon.Service.Export.Feed do self_url |> Feed.new( DateTime.utc_now(), - Gettext.gettext(MobilizonWeb.Gettext, title, actor: display_name) + Gettext.gettext(Mobilizon.Web.Gettext, title, actor: display_name) ) |> Feed.author(display_name, uri: actor.url) |> Feed.link(self_url, rel: "self") diff --git a/lib/service/formatter/formatter.ex b/lib/service/formatter/formatter.ex index 169139a2..6cfc4dce 100644 --- a/lib/service/formatter/formatter.ex +++ b/lib/service/formatter/formatter.ex @@ -52,7 +52,7 @@ defmodule Mobilizon.Service.Formatter do def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do tag = String.downcase(tag) - url = "#{MobilizonWeb.Endpoint.url()}/tag/#{tag}" + url = "#{Mobilizon.Web.Endpoint.url()}/tag/#{tag}" link = "" {link, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}} diff --git a/lib/service/metadata/actor.ex b/lib/service/metadata/actor.ex index d6bb357a..2a9e3035 100644 --- a/lib/service/metadata/actor.ex +++ b/lib/service/metadata/actor.ex @@ -1,7 +1,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do alias Phoenix.HTML.Tag alias Mobilizon.Actors.Actor - alias MobilizonWeb.MediaProxy + alias Mobilizon.Web.MediaProxy def build_tags(%Actor{} = actor) do tags = [ diff --git a/lib/service/metadata/event.ex b/lib/service/metadata/event.ex index 479dd782..b8fd1c49 100644 --- a/lib/service/metadata/event.ex +++ b/lib/service/metadata/event.ex @@ -2,8 +2,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do alias Phoenix.HTML alias Phoenix.HTML.Tag alias Mobilizon.Events.Event - alias MobilizonWeb.JsonLD.ObjectView - alias MobilizonWeb.MediaProxy + alias Mobilizon.Web.JsonLD.ObjectView + alias Mobilizon.Web.MediaProxy def build_tags(%Event{} = event) do event = Map.put(event, :description, process_description(event.description)) diff --git a/lib/service/metadata/instance.ex b/lib/service/metadata/instance.ex index e1e53145..a6b71efc 100644 --- a/lib/service/metadata/instance.ex +++ b/lib/service/metadata/instance.ex @@ -6,7 +6,7 @@ defmodule Mobilizon.Service.Metadata.Instance do alias Phoenix.HTML alias Phoenix.HTML.Tag alias Mobilizon.Config - alias MobilizonWeb.Endpoint + alias Mobilizon.Web.Endpoint def build_tags() do description = process_description(Config.instance_description()) diff --git a/lib/mobilizon_web/auth/context.ex b/lib/web/auth/context.ex similarity index 85% rename from lib/mobilizon_web/auth/context.ex rename to lib/web/auth/context.ex index f47ccfa6..18f05407 100644 --- a/lib/mobilizon_web/auth/context.ex +++ b/lib/web/auth/context.ex @@ -1,6 +1,6 @@ -defmodule MobilizonWeb.Auth.Context do +defmodule Mobilizon.Web.Auth.Context do @moduledoc """ - Guardian context for MobilizonWeb + Guardian context for Mobilizon.Web """ @behaviour Plug diff --git a/lib/mobilizon_web/auth/error_handler.ex b/lib/web/auth/error_handler.ex similarity index 83% rename from lib/mobilizon_web/auth/error_handler.ex rename to lib/web/auth/error_handler.ex index ae7a0282..6207477d 100644 --- a/lib/mobilizon_web/auth/error_handler.ex +++ b/lib/web/auth/error_handler.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Auth.ErrorHandler do +defmodule Mobilizon.Web.Auth.ErrorHandler do @moduledoc """ In case we have an auth error """ diff --git a/lib/mobilizon_web/auth/guardian.ex b/lib/web/auth/guardian.ex similarity index 97% rename from lib/mobilizon_web/auth/guardian.ex rename to lib/web/auth/guardian.ex index 225be5a8..070141a3 100644 --- a/lib/mobilizon_web/auth/guardian.ex +++ b/lib/web/auth/guardian.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Auth.Guardian do +defmodule Mobilizon.Web.Auth.Guardian do @moduledoc """ Handles the JWT tokens encoding and decoding """ diff --git a/lib/mobilizon_web/auth/pipeline.ex b/lib/web/auth/pipeline.ex similarity index 56% rename from lib/mobilizon_web/auth/pipeline.ex rename to lib/web/auth/pipeline.ex index e8bc59e6..9e4b74a4 100644 --- a/lib/mobilizon_web/auth/pipeline.ex +++ b/lib/web/auth/pipeline.ex @@ -1,14 +1,14 @@ -defmodule MobilizonWeb.Auth.Pipeline do +defmodule Mobilizon.Web.Auth.Pipeline do @moduledoc """ Handles the app sessions """ use Guardian.Plug.Pipeline, otp_app: :mobilizon, - module: MobilizonWeb.Auth.Guardian, - error_handler: MobilizonWeb.Auth.ErrorHandler + module: Mobilizon.Web.Auth.Guardian, + error_handler: Mobilizon.Web.Auth.ErrorHandler plug(Guardian.Plug.VerifyHeader, realm: "Bearer") plug(Guardian.Plug.LoadResource, allow_blank: true) - plug(MobilizonWeb.Auth.Context) + plug(Mobilizon.Web.Auth.Context) end diff --git a/lib/mobilizon_web/cache/activity_pub.ex b/lib/web/cache/activity_pub.ex similarity index 94% rename from lib/mobilizon_web/cache/activity_pub.ex rename to lib/web/cache/activity_pub.ex index c7393312..930bac0e 100644 --- a/lib/mobilizon_web/cache/activity_pub.ex +++ b/lib/web/cache/activity_pub.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Cache.ActivityPub do +defmodule Mobilizon.Web.Cache.ActivityPub do @moduledoc """ ActivityPub related cache. """ @@ -9,8 +9,8 @@ defmodule MobilizonWeb.Cache.ActivityPub do alias Mobilizon.Federation.ActivityPub.Relay - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes @cache :activity_pub diff --git a/lib/mobilizon_web/cache/cache.ex b/lib/web/cache/cache.ex similarity index 90% rename from lib/mobilizon_web/cache/cache.ex rename to lib/web/cache/cache.ex index 70fba94f..65c06bae 100644 --- a/lib/mobilizon_web/cache/cache.ex +++ b/lib/web/cache/cache.ex @@ -1,11 +1,11 @@ -defmodule MobilizonWeb.Cache do +defmodule Mobilizon.Web.Cache do @moduledoc """ Facade module which provides access to all cached data. """ alias Mobilizon.Actors.Actor - alias MobilizonWeb.Cache.ActivityPub + alias Mobilizon.Web.Cache.ActivityPub @caches [:activity_pub, :feed, :ics] diff --git a/lib/mobilizon_web/channels/graphql_socket.ex b/lib/web/channels/graphql_socket.ex similarity index 84% rename from lib/mobilizon_web/channels/graphql_socket.ex rename to lib/web/channels/graphql_socket.ex index dc51892e..83bb5fc8 100644 --- a/lib/mobilizon_web/channels/graphql_socket.ex +++ b/lib/web/channels/graphql_socket.ex @@ -1,14 +1,14 @@ -defmodule MobilizonWeb.GraphQLSocket do +defmodule Mobilizon.Web.GraphQLSocket do use Phoenix.Socket use Absinthe.Phoenix.Socket, - schema: MobilizonWeb.Schema + schema: Mobilizon.Web.Schema alias Mobilizon.Users.User def connect(%{"token" => token}, socket) do with {:ok, authed_socket} <- - Guardian.Phoenix.Socket.authenticate(socket, MobilizonWeb.Auth.Guardian, token), + Guardian.Phoenix.Socket.authenticate(socket, Mobilizon.Web.Auth.Guardian, token), %User{} = user <- Guardian.Phoenix.Socket.current_resource(authed_socket) do authed_socket = Absinthe.Phoenix.Socket.put_options(socket, diff --git a/lib/mobilizon_web/controllers/activity_pub_controller.ex b/lib/web/controllers/activity_pub_controller.ex similarity index 94% rename from lib/mobilizon_web/controllers/activity_pub_controller.ex rename to lib/web/controllers/activity_pub_controller.ex index a7b2407a..52ed51f7 100644 --- a/lib/mobilizon_web/controllers/activity_pub_controller.ex +++ b/lib/web/controllers/activity_pub_controller.ex @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/activity_pub_controller.ex -defmodule MobilizonWeb.ActivityPubController do - use MobilizonWeb, :controller +defmodule Mobilizon.Web.ActivityPubController do + use Mobilizon.Web, :controller alias Mobilizon.{Actors, Config} alias Mobilizon.Actors.Actor @@ -12,14 +12,14 @@ defmodule MobilizonWeb.ActivityPubController do alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub.Federator - alias MobilizonWeb.ActivityPub.ActorView - alias MobilizonWeb.Cache + alias Mobilizon.Web.ActivityPub.ActorView + alias Mobilizon.Web.Cache require Logger action_fallback(:errors) - plug(MobilizonWeb.Plugs.Federating when action in [:inbox, :relay]) + plug(Mobilizon.Web.Plugs.Federating when action in [:inbox, :relay]) plug(:relay_active? when action in [:relay]) def relay_active?(conn, _) do diff --git a/lib/mobilizon_web/controllers/fallback_controller.ex b/lib/web/controllers/fallback_controller.ex similarity index 69% rename from lib/mobilizon_web/controllers/fallback_controller.ex rename to lib/web/controllers/fallback_controller.ex index aea620e1..f92fb231 100644 --- a/lib/mobilizon_web/controllers/fallback_controller.ex +++ b/lib/web/controllers/fallback_controller.ex @@ -1,15 +1,15 @@ -defmodule MobilizonWeb.FallbackController do +defmodule Mobilizon.Web.FallbackController do @moduledoc """ Translates controller action results into valid `Plug.Conn` responses. See `Phoenix.Controller.action_fallback/1` for more details. """ - use MobilizonWeb, :controller + use Mobilizon.Web, :controller def call(conn, {:error, :not_found}) do conn |> put_status(:not_found) - |> put_view(MobilizonWeb.ErrorView) + |> put_view(Mobilizon.Web.ErrorView) |> render(:"404") end end diff --git a/lib/mobilizon_web/controllers/feed_controller.ex b/lib/web/controllers/feed_controller.ex similarity index 93% rename from lib/mobilizon_web/controllers/feed_controller.ex rename to lib/web/controllers/feed_controller.ex index 83af5893..12956309 100644 --- a/lib/mobilizon_web/controllers/feed_controller.ex +++ b/lib/web/controllers/feed_controller.ex @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.FeedController do +defmodule Mobilizon.Web.FeedController do @moduledoc """ Controller to serve RSS, ATOM and iCal Feeds """ - use MobilizonWeb, :controller + use Mobilizon.Web, :controller plug(:put_layout, false) - action_fallback(MobilizonWeb.FallbackController) + action_fallback(Mobilizon.Web.FallbackController) def actor(conn, %{"name" => name, "format" => "atom"}) do case Cachex.fetch(:feed, "actor_" <> name) do diff --git a/lib/mobilizon_web/controllers/media_proxy_controller.ex b/lib/web/controllers/media_proxy_controller.ex similarity index 90% rename from lib/mobilizon_web/controllers/media_proxy_controller.ex rename to lib/web/controllers/media_proxy_controller.ex index 6980cac3..8a764aa6 100644 --- a/lib/mobilizon_web/controllers/media_proxy_controller.ex +++ b/lib/web/controllers/media_proxy_controller.ex @@ -3,15 +3,15 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/media_proxy/controller.ex -defmodule MobilizonWeb.MediaProxyController do - use MobilizonWeb, :controller +defmodule Mobilizon.Web.MediaProxyController do + use Mobilizon.Web, :controller alias Plug.Conn alias Mobilizon.Config - alias MobilizonWeb.MediaProxy - alias MobilizonWeb.ReverseProxy + alias Mobilizon.Web.MediaProxy + alias Mobilizon.Web.ReverseProxy @default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]] diff --git a/lib/mobilizon_web/controllers/node_info_controller.ex b/lib/web/controllers/node_info_controller.ex similarity index 93% rename from lib/mobilizon_web/controllers/node_info_controller.ex rename to lib/web/controllers/node_info_controller.ex index d96f84e6..67cd636c 100644 --- a/lib/mobilizon_web/controllers/node_info_controller.ex +++ b/lib/web/controllers/node_info_controller.ex @@ -3,14 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex -defmodule MobilizonWeb.NodeInfoController do - use MobilizonWeb, :controller +defmodule Mobilizon.Web.NodeInfoController do + use Mobilizon.Web, :controller alias Mobilizon.Config alias Mobilizon.Service.Statistics - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes @node_info_supported_versions ["2.0", "2.1"] @node_info_schema_uri "http://nodeinfo.diaspora.software/ns/schema/" diff --git a/lib/mobilizon_web/controllers/page_controller.ex b/lib/web/controllers/page_controller.ex similarity index 90% rename from lib/mobilizon_web/controllers/page_controller.ex rename to lib/web/controllers/page_controller.ex index a79f94b6..45dc8c6d 100644 --- a/lib/mobilizon_web/controllers/page_controller.ex +++ b/lib/web/controllers/page_controller.ex @@ -1,13 +1,13 @@ -defmodule MobilizonWeb.PageController do +defmodule Mobilizon.Web.PageController do @moduledoc """ Controller to load our webapp """ - use MobilizonWeb, :controller + use Mobilizon.Web, :controller - alias MobilizonWeb.Cache + alias Mobilizon.Web.Cache plug(:put_layout, false) - action_fallback(MobilizonWeb.FallbackController) + action_fallback(Mobilizon.Web.FallbackController) def index(conn, _params), do: render(conn, :index) diff --git a/lib/mobilizon_web/controllers/web_finger_controller.ex b/lib/web/controllers/web_finger_controller.ex similarity index 88% rename from lib/mobilizon_web/controllers/web_finger_controller.ex rename to lib/web/controllers/web_finger_controller.ex index 6e96dc48..b0aec252 100644 --- a/lib/mobilizon_web/controllers/web_finger_controller.ex +++ b/lib/web/controllers/web_finger_controller.ex @@ -3,16 +3,16 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/web_finger/web_finger_controller.ex -defmodule MobilizonWeb.WebFingerController do +defmodule Mobilizon.Web.WebFingerController do @moduledoc """ Handles Webfinger requests """ - use MobilizonWeb, :controller + use Mobilizon.Web, :controller alias Mobilizon.Federation.WebFinger - plug(MobilizonWeb.Plugs.Federating) + plug(Mobilizon.Web.Plugs.Federating) @doc """ Provides /.well-known/host-meta diff --git a/lib/mobilizon_web/email/admin.ex b/lib/web/email/admin.ex similarity index 76% rename from lib/mobilizon_web/email/admin.ex rename to lib/web/email/admin.ex index 0f78db66..b1734947 100644 --- a/lib/mobilizon_web/email/admin.ex +++ b/lib/web/email/admin.ex @@ -1,23 +1,23 @@ -defmodule MobilizonWeb.Email.Admin do +defmodule Mobilizon.Web.Email.Admin do @moduledoc """ Handles emails sent to admins. """ - use Bamboo.Phoenix, view: MobilizonWeb.EmailView + use Bamboo.Phoenix, view: Mobilizon.Web.EmailView import Bamboo.Phoenix - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext alias Mobilizon.Config alias Mobilizon.Reports.Report alias Mobilizon.Users.User - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t() def report(%User{email: email}, %Report{} = report, locale \\ "en") do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/checker.ex b/lib/web/email/checker.ex similarity index 91% rename from lib/mobilizon_web/email/checker.ex rename to lib/web/email/checker.ex index 17ee1b1d..9a2aec50 100644 --- a/lib/mobilizon_web/email/checker.ex +++ b/lib/web/email/checker.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Email.Checker do +defmodule Mobilizon.Web.Email.Checker do @moduledoc """ Provides a function to test emails against a "not so bad" regex. """ diff --git a/lib/mobilizon_web/email/email.ex b/lib/web/email/email.ex similarity index 64% rename from lib/mobilizon_web/email/email.ex rename to lib/web/email/email.ex index 0bcb221c..c0e1b788 100644 --- a/lib/mobilizon_web/email/email.ex +++ b/lib/web/email/email.ex @@ -1,9 +1,9 @@ -defmodule MobilizonWeb.Email do +defmodule Mobilizon.Web.Email do @moduledoc """ The Email context. """ - use Bamboo.Phoenix, view: MobilizonWeb.EmailView + use Bamboo.Phoenix, view: Mobilizon.Web.EmailView alias Mobilizon.Config @@ -16,7 +16,7 @@ defmodule MobilizonWeb.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({MobilizonWeb.EmailView, "email.html"}) - |> put_text_layout({MobilizonWeb.EmailView, "email.text"}) + |> put_html_layout({Mobilizon.Web.EmailView, "email.html"}) + |> put_text_layout({Mobilizon.Web.EmailView, "email.text"}) end end diff --git a/lib/mobilizon_web/email/event.ex b/lib/web/email/event.ex similarity index 90% rename from lib/mobilizon_web/email/event.ex rename to lib/web/email/event.ex index 9ea5b985..3b8150e0 100644 --- a/lib/mobilizon_web/email/event.ex +++ b/lib/web/email/event.ex @@ -1,13 +1,13 @@ -defmodule MobilizonWeb.Email.Event do +defmodule Mobilizon.Web.Email.Event do @moduledoc """ Handles emails sent about events. """ - use Bamboo.Phoenix, view: MobilizonWeb.EmailView + use Bamboo.Phoenix, view: Mobilizon.Web.EmailView import Bamboo.Phoenix - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext alias Mobilizon.Actors.Actor alias Mobilizon.Events @@ -15,7 +15,7 @@ defmodule MobilizonWeb.Email.Event do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @important_changes [:title, :begins_on, :ends_on, :status] @@ -29,7 +29,7 @@ defmodule MobilizonWeb.Email.Event do changes, locale \\ "en" ) do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/mailer.ex b/lib/web/email/mailer.ex similarity index 68% rename from lib/mobilizon_web/email/mailer.ex rename to lib/web/email/mailer.ex index 246d20d0..87316f1c 100644 --- a/lib/mobilizon_web/email/mailer.ex +++ b/lib/web/email/mailer.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Email.Mailer do +defmodule Mobilizon.Web.Email.Mailer do @moduledoc """ Mobilizon Mailer. """ diff --git a/lib/mobilizon_web/email/participation.ex b/lib/web/email/participation.ex similarity index 88% rename from lib/mobilizon_web/email/participation.ex rename to lib/web/email/participation.ex index 4bf40066..df9096cc 100644 --- a/lib/mobilizon_web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -1,19 +1,19 @@ -defmodule MobilizonWeb.Email.Participation do +defmodule Mobilizon.Web.Email.Participation do @moduledoc """ Handles emails sent about participation. """ - use Bamboo.Phoenix, view: MobilizonWeb.EmailView + use Bamboo.Phoenix, view: Mobilizon.Web.EmailView import Bamboo.Phoenix - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext alias Mobilizon.Users.User alias Mobilizon.Actors.Actor alias Mobilizon.Events.Participant - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @doc """ Send emails to local user @@ -46,7 +46,7 @@ defmodule MobilizonWeb.Email.Participation do %Participant{event: event, role: :rejected}, locale ) do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( @@ -67,7 +67,7 @@ defmodule MobilizonWeb.Email.Participation do %Participant{event: event, role: :participant}, locale ) do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/email/user.ex b/lib/web/email/user.ex similarity index 95% rename from lib/mobilizon_web/email/user.ex rename to lib/web/email/user.ex index 74af1874..de6091d6 100644 --- a/lib/mobilizon_web/email/user.ex +++ b/lib/web/email/user.ex @@ -1,19 +1,19 @@ -defmodule MobilizonWeb.Email.User do +defmodule Mobilizon.Web.Email.User do @moduledoc """ Handles emails sent to users. """ - use Bamboo.Phoenix, view: MobilizonWeb.EmailView + use Bamboo.Phoenix, view: Mobilizon.Web.EmailView import Bamboo.Phoenix - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext alias Mobilizon.{Config, Crypto, Users} alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias MobilizonWeb.Email + alias Mobilizon.Web.Email require Logger @@ -22,7 +22,7 @@ defmodule MobilizonWeb.Email.User do %User{email: email, confirmation_token: confirmation_token}, locale \\ "en" ) do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( @@ -42,7 +42,7 @@ defmodule MobilizonWeb.Email.User do %User{email: email, reset_password_token: reset_password_token}, locale \\ "en" ) do - MobilizonWeb.Gettext.put_locale(locale) + Mobilizon.Web.Gettext.put_locale(locale) subject = gettext( diff --git a/lib/mobilizon_web/endpoint.ex b/lib/web/endpoint.ex similarity index 90% rename from lib/mobilizon_web/endpoint.ex rename to lib/web/endpoint.ex index 23fb15a1..df012368 100644 --- a/lib/mobilizon_web/endpoint.ex +++ b/lib/web/endpoint.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.Endpoint do +defmodule Mobilizon.Web.Endpoint do @moduledoc """ Endpoint for Mobilizon app """ @@ -14,12 +14,12 @@ defmodule MobilizonWeb.Endpoint do ) end - socket("/graphql_socket", MobilizonWeb.GraphQLSocket, + socket("/graphql_socket", Mobilizon.Web.GraphQLSocket, websocket: true, longpoll: false ) - plug(MobilizonWeb.Plugs.UploadedMedia) + plug(Mobilizon.Web.Plugs.UploadedMedia) # Serve at "/" the static files from "priv/static" directory. # @@ -65,5 +65,5 @@ defmodule MobilizonWeb.Endpoint do signing_salt: "F9CCTF22" ) - plug(MobilizonWeb.Router) + plug(Mobilizon.Web.Router) end diff --git a/lib/mobilizon_web/gettext.ex b/lib/web/gettext.ex similarity index 87% rename from lib/mobilizon_web/gettext.ex rename to lib/web/gettext.ex index e6880ae8..18a2fd49 100644 --- a/lib/mobilizon_web/gettext.ex +++ b/lib/web/gettext.ex @@ -1,11 +1,11 @@ -defmodule MobilizonWeb.Gettext do +defmodule Mobilizon.Web.Gettext do @moduledoc """ A module providing Internationalization with a gettext-based API. By using [Gettext](https://hexdocs.pm/gettext), your module gains a set of macros for translations, for example: - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext # Simple translation gettext "Here is the string to translate" @@ -24,13 +24,13 @@ defmodule MobilizonWeb.Gettext do def put_locale(locale) do locale = determine_best_locale(locale) - Gettext.put_locale(MobilizonWeb.Gettext, locale) + Gettext.put_locale(Mobilizon.Web.Gettext, locale) end @spec determine_best_locale(String.t()) :: String.t() def determine_best_locale(locale) do locale = String.trim(locale) - locales = Gettext.known_locales(MobilizonWeb.Gettext) + locales = Gettext.known_locales(Mobilizon.Web.Gettext) cond do # Either it matches directly, eg: "en" => "en", "fr" => "fr", "fr_FR" => "fr_FR" diff --git a/lib/mobilizon_web/mobilizon_web.ex b/lib/web/mobilizon_web.ex similarity index 72% rename from lib/mobilizon_web/mobilizon_web.ex rename to lib/web/mobilizon_web.ex index ab3f09ff..e962bad2 100644 --- a/lib/mobilizon_web/mobilizon_web.ex +++ b/lib/web/mobilizon_web.ex @@ -1,12 +1,12 @@ -defmodule MobilizonWeb do +defmodule Mobilizon.Web do @moduledoc """ The entrypoint for defining your web interface, such as controllers, views, channels and so on. This can be used in your application as: - use MobilizonWeb, :controller - use MobilizonWeb, :view + use Mobilizon.Web, :controller + use Mobilizon.Web, :view The definitions below will be executed for every view, controller, etc, so keep them short and clean, focused @@ -19,18 +19,18 @@ defmodule MobilizonWeb do def controller do quote do - use Phoenix.Controller, namespace: MobilizonWeb + use Phoenix.Controller, namespace: Mobilizon.Web import Plug.Conn - import MobilizonWeb.Router.Helpers - import MobilizonWeb.Gettext + import Mobilizon.Web.Router.Helpers + import Mobilizon.Web.Gettext end end def view do quote do use Phoenix.View, - root: "lib/mobilizon_web/templates", - namespace: MobilizonWeb + root: "lib/web/templates", + namespace: Mobilizon.Web # Import convenience functions from controllers import Phoenix.Controller, only: [get_flash: 2, view_module: 1] @@ -38,9 +38,9 @@ defmodule MobilizonWeb do # Use all HTML functionality (forms, tags, etc) use Phoenix.HTML - import MobilizonWeb.Router.Helpers - import MobilizonWeb.ErrorHelpers - import MobilizonWeb.Gettext + import Mobilizon.Web.Router.Helpers + import Mobilizon.Web.ErrorHelpers + import Mobilizon.Web.Gettext end end @@ -55,7 +55,7 @@ defmodule MobilizonWeb do def channel do quote do use Phoenix.Channel - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext end end diff --git a/lib/mobilizon_web/plugs/federating.ex b/lib/web/plugs/federating.ex similarity index 84% rename from lib/mobilizon_web/plugs/federating.ex rename to lib/web/plugs/federating.ex index 07dcca73..d63b69ce 100644 --- a/lib/mobilizon_web/plugs/federating.ex +++ b/lib/web/plugs/federating.ex @@ -3,7 +3,7 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule MobilizonWeb.Plugs.Federating do +defmodule Mobilizon.Web.Plugs.Federating do @moduledoc """ Restrict ActivityPub routes when not federating """ @@ -20,7 +20,7 @@ defmodule MobilizonWeb.Plugs.Federating do else conn |> put_status(404) - |> Phoenix.Controller.put_view(MobilizonWeb.ErrorView) + |> Phoenix.Controller.put_view(Mobilizon.Web.ErrorView) |> Phoenix.Controller.render("404.json") |> halt() end diff --git a/lib/mobilizon_web/plugs/http_signatures.ex b/lib/web/plugs/http_signatures.ex similarity index 96% rename from lib/mobilizon_web/plugs/http_signatures.ex rename to lib/web/plugs/http_signatures.ex index 1dc66954..fa4ae1fb 100644 --- a/lib/mobilizon_web/plugs/http_signatures.ex +++ b/lib/web/plugs/http_signatures.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/plugs/http_signature.ex -defmodule MobilizonWeb.Plugs.HTTPSignatures do +defmodule Mobilizon.Web.Plugs.HTTPSignatures do @moduledoc """ Plug to check HTTP Signatures on every incoming request """ diff --git a/lib/mobilizon_web/plugs/mapped_signature_to_identity.ex b/lib/web/plugs/mapped_signature_to_identity.ex similarity index 97% rename from lib/mobilizon_web/plugs/mapped_signature_to_identity.ex rename to lib/web/plugs/mapped_signature_to_identity.ex index e62c10a0..84262bc3 100644 --- a/lib/mobilizon_web/plugs/mapped_signature_to_identity.ex +++ b/lib/web/plugs/mapped_signature_to_identity.ex @@ -3,7 +3,7 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule MobilizonWeb.Plugs.MappedSignatureToIdentity do +defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentity do @moduledoc """ Get actor identity from Signature when handing fetches """ diff --git a/lib/mobilizon_web/plugs/uploaded_media.ex b/lib/web/plugs/uploaded_media.ex similarity index 91% rename from lib/mobilizon_web/plugs/uploaded_media.ex rename to lib/web/plugs/uploaded_media.ex index 78f72dd5..53b9e43a 100644 --- a/lib/mobilizon_web/plugs/uploaded_media.ex +++ b/lib/web/plugs/uploaded_media.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/plugs/uploaded_media.ex -defmodule MobilizonWeb.Plugs.UploadedMedia do +defmodule Mobilizon.Web.Plugs.UploadedMedia do @moduledoc """ Serves uploaded media files """ @@ -41,7 +41,7 @@ defmodule MobilizonWeb.Plugs.UploadedMedia do conn end - config = Config.get([MobilizonWeb.Upload]) + config = Config.get([Mobilizon.Web.Upload]) with uploader <- Keyword.fetch!(config, :uploader), proxy_remote = Keyword.get(config, :proxy_remote, false), @@ -76,7 +76,7 @@ defmodule MobilizonWeb.Plugs.UploadedMedia do end defp get_media(conn, {:url, url}, true, _) do - MobilizonWeb.ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], [])) + Mobilizon.Web.ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], [])) end defp get_media(conn, {:url, url}, _, _) do diff --git a/lib/mobilizon_web/proxy/media_proxy.ex b/lib/web/proxy/media_proxy.ex similarity index 85% rename from lib/mobilizon_web/proxy/media_proxy.ex rename to lib/web/proxy/media_proxy.ex index 0f03544e..35611c84 100644 --- a/lib/mobilizon_web/proxy/media_proxy.ex +++ b/lib/web/proxy/media_proxy.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/media_proxy/media_proxy.ex -defmodule MobilizonWeb.MediaProxy do +defmodule Mobilizon.Web.MediaProxy do @moduledoc """ Handles proxifying media files """ @@ -22,7 +22,7 @@ defmodule MobilizonWeb.MediaProxy do config = Application.get_env(:mobilizon, :media_proxy, []) if !Keyword.get(config, :enabled, false) or - String.starts_with?(url, MobilizonWeb.Endpoint.url()) do + String.starts_with?(url, Mobilizon.Web.Endpoint.url()) do url else encode_url(url) @@ -30,7 +30,7 @@ defmodule MobilizonWeb.MediaProxy do end def encode_url(url) do - secret = Application.get_env(:mobilizon, MobilizonWeb.Endpoint)[:secret_key_base] + secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base] # Must preserve `%2F` for compatibility with S3 # https://git.pleroma.social/pleroma/pleroma/issues/580 @@ -52,7 +52,7 @@ defmodule MobilizonWeb.MediaProxy do end def decode_url(sig, url) do - secret = Application.get_env(:mobilizon, MobilizonWeb.Endpoint)[:secret_key_base] + secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base] sig = Base.url_decode64!(sig, @base64_opts) local_sig = :crypto.hmac(:sha, secret, url) @@ -69,7 +69,7 @@ defmodule MobilizonWeb.MediaProxy do def build_url(sig_base64, url_base64, filename \\ nil) do [ - Config.get([:media_proxy, :base_url], MobilizonWeb.Endpoint.url()), + Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()), "proxy", sig_base64, url_base64, diff --git a/lib/mobilizon_web/proxy/reverse_proxy.ex b/lib/web/proxy/reverse_proxy.ex similarity index 98% rename from lib/mobilizon_web/proxy/reverse_proxy.ex rename to lib/web/proxy/reverse_proxy.ex index a56e36b4..f0f68c08 100644 --- a/lib/mobilizon_web/proxy/reverse_proxy.ex +++ b/lib/web/proxy/reverse_proxy.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/reverse_proxy.ex -defmodule MobilizonWeb.ReverseProxy do +defmodule Mobilizon.Web.ReverseProxy do @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) @resp_cache_headers ~w(etag date last-modified cache-control) @@ -18,7 +18,7 @@ defmodule MobilizonWeb.ReverseProxy do @moduledoc """ A reverse proxy. - MobilizonWeb.ReverseProxy.call(conn, url, options) + Mobilizon.Web.ReverseProxy.call(conn, url, options) It is not meant to be added into a plug pipeline, but to be called from another plug or controller. @@ -111,7 +111,7 @@ defmodule MobilizonWeb.ReverseProxy do req_headers = build_req_headers(conn.req_headers, opts) opts = - if filename = MobilizonWeb.MediaProxy.filename(url) do + if filename = Mobilizon.Web.MediaProxy.filename(url) do Keyword.put_new(opts, :attachment_name, filename) else opts diff --git a/lib/mobilizon_web/router.ex b/lib/web/router.ex similarity index 84% rename from lib/mobilizon_web/router.ex rename to lib/web/router.ex index caff1d7f..3943ef3c 100644 --- a/lib/mobilizon_web/router.ex +++ b/lib/web/router.ex @@ -1,12 +1,12 @@ -defmodule MobilizonWeb.Router do +defmodule Mobilizon.Web.Router do @moduledoc """ Router for mobilizon app """ - use MobilizonWeb, :router + use Mobilizon.Web, :router pipeline :graphql do # plug(:accepts, ["json"]) - plug(MobilizonWeb.Auth.Pipeline) + plug(Mobilizon.Web.Auth.Pipeline) end pipeline :well_known do @@ -14,13 +14,13 @@ defmodule MobilizonWeb.Router do end pipeline :activity_pub_signature do - plug(MobilizonWeb.Plugs.HTTPSignatures) - plug(MobilizonWeb.Plugs.MappedSignatureToIdentity) + plug(Mobilizon.Web.Plugs.HTTPSignatures) + plug(Mobilizon.Web.Plugs.MappedSignatureToIdentity) end pipeline :relay do - plug(MobilizonWeb.Plugs.HTTPSignatures) - plug(MobilizonWeb.Plugs.MappedSignatureToIdentity) + plug(Mobilizon.Web.Plugs.HTTPSignatures) + plug(Mobilizon.Web.Plugs.MappedSignatureToIdentity) plug(:accepts, ["activity-json", "json"]) end @@ -60,7 +60,7 @@ defmodule MobilizonWeb.Router do ## FEDERATION - scope "/.well-known", MobilizonWeb do + scope "/.well-known", Mobilizon.Web do pipe_through(:well_known) get("/host-meta", WebFingerController, :host_meta) @@ -69,7 +69,7 @@ defmodule MobilizonWeb.Router do get("/nodeinfo/:version", NodeInfoController, :nodeinfo) end - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:activity_pub_and_html) pipe_through(:activity_pub_signature) @@ -78,7 +78,7 @@ defmodule MobilizonWeb.Router do get("/comments/:uuid", PageController, :comment) end - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:activity_pub) get("/@:name/outbox", ActivityPubController, :outbox) @@ -86,13 +86,13 @@ defmodule MobilizonWeb.Router do get("/@:name/followers", ActivityPubController, :followers) end - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:activity_pub_signature) post("/@:name/inbox", ActivityPubController, :inbox) post("/inbox", ActivityPubController, :inbox) end - scope "/relay", MobilizonWeb do + scope "/relay", Mobilizon.Web do pipe_through(:relay) get("/", ActivityPubController, :relay) @@ -101,7 +101,7 @@ defmodule MobilizonWeb.Router do ## FEED - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:atom_and_ical) get("/@:name/feed/:format", FeedController, :actor) @@ -111,9 +111,9 @@ defmodule MobilizonWeb.Router do ## MOBILIZON - forward("/graphiql", Absinthe.Plug.GraphiQL, schema: MobilizonWeb.Schema) + forward("/graphiql", Absinthe.Plug.GraphiQL, schema: Mobilizon.Web.Schema) - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:browser) # Because the "/events/:uuid" route caches all these, we need to force them @@ -127,7 +127,7 @@ defmodule MobilizonWeb.Router do get("/moderation/reports/:id", PageController, :index, as: "moderation_report") end - scope "/proxy/", MobilizonWeb do + scope "/proxy/", Mobilizon.Web do pipe_through(:remote_media) get("/:sig/:url", MediaProxyController, :remote) @@ -139,7 +139,7 @@ defmodule MobilizonWeb.Router do forward("/sent_emails", Bamboo.SentEmailViewerPlug) end - scope "/", MobilizonWeb do + scope "/", Mobilizon.Web do pipe_through(:browser) get("/*path", PageController, :index) diff --git a/lib/mobilizon_web/templates/email/email.html.eex b/lib/web/templates/email/email.html.eex similarity index 95% rename from lib/mobilizon_web/templates/email/email.html.eex rename to lib/web/templates/email/email.html.eex index 5270646d..26639732 100644 --- a/lib/mobilizon_web/templates/email/email.html.eex +++ b/lib/web/templates/email/email.html.eex @@ -58,8 +58,8 @@ diff --git a/lib/mobilizon_web/templates/email/email.text.eex b/lib/web/templates/email/email.text.eex similarity index 100% rename from lib/mobilizon_web/templates/email/email.text.eex rename to lib/web/templates/email/email.text.eex diff --git a/lib/mobilizon_web/templates/email/event_participation_approved.html.eex b/lib/web/templates/email/event_participation_approved.html.eex similarity index 91% rename from lib/mobilizon_web/templates/email/event_participation_approved.html.eex rename to lib/web/templates/email/event_participation_approved.html.eex index b5b6fcb9..62624836 100644 --- a/lib/mobilizon_web/templates/email/event_participation_approved.html.eex +++ b/lib/web/templates/email/event_participation_approved.html.eex @@ -54,7 +54,7 @@
- - <%= Mobilizon.Config.instance_name() %>" width="366" height="108" style="display: block; width: 366px; max-width: 366px; min-width: 366px; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;" border="0"> + + <%= Mobilizon.Config.instance_name() %>" width="366" height="108" style="display: block; width: 366px; max-width: 366px; min-width: 366px; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;" border="0">
- diff --git a/lib/mobilizon_web/templates/email/event_participation_approved.text.eex b/lib/web/templates/email/event_participation_approved.text.eex similarity index 85% rename from lib/mobilizon_web/templates/email/event_participation_approved.text.eex rename to lib/web/templates/email/event_participation_approved.text.eex index 7f1521b7..2712e824 100644 --- a/lib/mobilizon_web/templates/email/event_participation_approved.text.eex +++ b/lib/web/templates/email/event_participation_approved.text.eex @@ -6,6 +6,6 @@ <%= gettext "An organizer just approved your participation. You're now going to this event!" %> -<%= page_url(MobilizonWeb.Endpoint, :event, @event.id) %> +<%= page_url(Mobilizon.Web.Endpoint, :event, @event.id) %> <%= gettext "If you need to cancel your participation, just access the previous link and click on the participation button." %> diff --git a/lib/mobilizon_web/templates/email/event_participation_rejected.html.eex b/lib/web/templates/email/event_participation_rejected.html.eex similarity index 100% rename from lib/mobilizon_web/templates/email/event_participation_rejected.html.eex rename to lib/web/templates/email/event_participation_rejected.html.eex diff --git a/lib/mobilizon_web/templates/email/event_participation_rejected.text.eex b/lib/web/templates/email/event_participation_rejected.text.eex similarity index 100% rename from lib/mobilizon_web/templates/email/event_participation_rejected.text.eex rename to lib/web/templates/email/event_participation_rejected.text.eex diff --git a/lib/mobilizon_web/templates/email/event_updated.html.eex b/lib/web/templates/email/event_updated.html.eex similarity index 94% rename from lib/mobilizon_web/templates/email/event_updated.html.eex rename to lib/web/templates/email/event_updated.html.eex index ce5d9b2d..5bc9c18f 100644 --- a/lib/mobilizon_web/templates/email/event_updated.html.eex +++ b/lib/web/templates/email/event_updated.html.eex @@ -97,7 +97,7 @@
+ <%= gettext "Go to event page" %>
- diff --git a/lib/mobilizon_web/templates/email/event_updated.text.eex b/lib/web/templates/email/event_updated.text.eex similarity index 94% rename from lib/mobilizon_web/templates/email/event_updated.text.eex rename to lib/web/templates/email/event_updated.text.eex index 8a2128de..b9ce3027 100644 --- a/lib/mobilizon_web/templates/email/event_updated.text.eex +++ b/lib/web/templates/email/event_updated.text.eex @@ -16,6 +16,6 @@ <%= gettext "New date and time for ending of event: %{ends_on}", ends_on: datetime_to_string(@event.ends_on, @locale) %> <% end %> -<%= gettext "View the updated event on: %{link}", link: page_url(MobilizonWeb.Endpoint, :event, @event.id) %> +<%= gettext "View the updated event on: %{link}", link: page_url(Mobilizon.Web.Endpoint, :event, @event.id) %> <%= gettext "If you need to cancel your participation, just access the event page through link above and click on the participation button." %> diff --git a/lib/mobilizon_web/templates/email/password_reset.html.eex b/lib/web/templates/email/password_reset.html.eex similarity index 91% rename from lib/mobilizon_web/templates/email/password_reset.html.eex rename to lib/web/templates/email/password_reset.html.eex index f6669148..721a6b84 100644 --- a/lib/mobilizon_web/templates/email/password_reset.html.eex +++ b/lib/web/templates/email/password_reset.html.eex @@ -57,7 +57,7 @@
+ <%= gettext "Go to event page" %>
- diff --git a/lib/mobilizon_web/templates/email/password_reset.text.eex b/lib/web/templates/email/password_reset.text.eex similarity index 86% rename from lib/mobilizon_web/templates/email/password_reset.text.eex rename to lib/web/templates/email/password_reset.text.eex index 58a4aacd..a7f50b7b 100644 --- a/lib/mobilizon_web/templates/email/password_reset.text.eex +++ b/lib/web/templates/email/password_reset.text.eex @@ -6,7 +6,7 @@ <%= gettext "Resetting your password is easy. Just click the link below and follow the instructions. We'll have you up and running in no time." %> -<%= MobilizonWeb.Endpoint.url() <> "/password-reset/#{@token}" %> +<%= Mobilizon.Web.Endpoint.url() <> "/password-reset/#{@token}" %> <%= gettext "If you didn't request this, please ignore this email. Your password won't change until you access the link below and create a new one." %> diff --git a/lib/mobilizon_web/templates/email/registration_confirmation.html.eex b/lib/web/templates/email/registration_confirmation.html.eex similarity index 90% rename from lib/mobilizon_web/templates/email/registration_confirmation.html.eex rename to lib/web/templates/email/registration_confirmation.html.eex index c60426e5..76f6271d 100644 --- a/lib/mobilizon_web/templates/email/registration_confirmation.html.eex +++ b/lib/web/templates/email/registration_confirmation.html.eex @@ -54,7 +54,7 @@
" target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #424056; display: inline-block;"> + " target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #424056; display: inline-block;"> <%= gettext "Reset Password" %>
- diff --git a/lib/mobilizon_web/templates/email/registration_confirmation.text.eex b/lib/web/templates/email/registration_confirmation.text.eex similarity index 79% rename from lib/mobilizon_web/templates/email/registration_confirmation.text.eex rename to lib/web/templates/email/registration_confirmation.text.eex index ee5a915b..1670a44e 100644 --- a/lib/mobilizon_web/templates/email/registration_confirmation.text.eex +++ b/lib/web/templates/email/registration_confirmation.text.eex @@ -4,4 +4,4 @@ <%= gettext "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email.", host: @instance[:name] %> -<%= MobilizonWeb.Endpoint.url() <> "/validate/#{@token}" %> +<%= Mobilizon.Web.Endpoint.url() <> "/validate/#{@token}" %> diff --git a/lib/mobilizon_web/templates/email/report.html.eex b/lib/web/templates/email/report.html.eex similarity index 94% rename from lib/mobilizon_web/templates/email/report.html.eex rename to lib/web/templates/email/report.html.eex index e4f26d06..419cd4df 100644 --- a/lib/mobilizon_web/templates/email/report.html.eex +++ b/lib/web/templates/email/report.html.eex @@ -48,7 +48,7 @@
" target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #424056; display: inline-block;"> + " target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #424056; display: inline-block;"> <%= gettext "Activate my account" %>

<%= gettext "Event" %>

- " target="_blank"> + " target="_blank"> <%= gettext "%{title} by %{creator}", title: @report.event.title, creator: Mobilizon.Actors.Actor.preferred_username_and_domain(@report.reported) %>

@@ -100,7 +100,7 @@
- diff --git a/lib/mobilizon_web/templates/email/report.text.eex b/lib/web/templates/email/report.text.eex similarity index 86% rename from lib/mobilizon_web/templates/email/report.text.eex rename to lib/web/templates/email/report.text.eex index d054fa42..4b5a1b27 100644 --- a/lib/mobilizon_web/templates/email/report.text.eex +++ b/lib/web/templates/email/report.text.eex @@ -25,5 +25,5 @@ <% end %> -View the report: <%= moderation_report_url(MobilizonWeb.Endpoint, :index, @report.id) %> +View the report: <%= moderation_report_url(Mobilizon.Web.Endpoint, :index, @report.id) %> diff --git a/lib/mobilizon_web/upload/filter/anonymize_filename.ex b/lib/web/upload/filter/anonymize_filename.ex similarity index 77% rename from lib/mobilizon_web/upload/filter/anonymize_filename.ex rename to lib/web/upload/filter/anonymize_filename.ex index 290b9df5..33074ba2 100644 --- a/lib/mobilizon_web/upload/filter/anonymize_filename.ex +++ b/lib/web/upload/filter/anonymize_filename.ex @@ -3,21 +3,21 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload/filter/anonymize_filename.ex -defmodule MobilizonWeb.Upload.Filter.AnonymizeFilename do +defmodule Mobilizon.Web.Upload.Filter.AnonymizeFilename do @moduledoc """ Replaces the original filename with a pre-defined text or randomly generated string. - Should be used after `MobilizonWeb.Upload.Filter.Dedupe`. + Should be used after `Mobilizon.Web.Upload.Filter.Dedupe`. """ - @behaviour MobilizonWeb.Upload.Filter + @behaviour Mobilizon.Web.Upload.Filter alias Mobilizon.Config def filter(upload) do extension = List.last(String.split(upload.name, ".")) name = Config.get([__MODULE__, :text], random(extension)) - {:ok, %MobilizonWeb.Upload{upload | name: name}} + {:ok, %Mobilizon.Web.Upload{upload | name: name}} end defp random(extension) do diff --git a/lib/mobilizon_web/upload/filter/dedupe.ex b/lib/web/upload/filter/dedupe.ex similarity index 84% rename from lib/mobilizon_web/upload/filter/dedupe.ex rename to lib/web/upload/filter/dedupe.ex index 42f1ef63..d1f48d75 100644 --- a/lib/mobilizon_web/upload/filter/dedupe.ex +++ b/lib/web/upload/filter/dedupe.ex @@ -3,12 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload/filter/dedupe.ex -defmodule MobilizonWeb.Upload.Filter.Dedupe do +defmodule Mobilizon.Web.Upload.Filter.Dedupe do @moduledoc """ Names the file after its hash to avoid dedupes """ - @behaviour MobilizonWeb.Upload.Filter - alias MobilizonWeb.Upload + @behaviour Mobilizon.Web.Upload.Filter + alias Mobilizon.Web.Upload def filter(%Upload{name: name} = upload) do extension = name |> String.split(".") |> List.last() diff --git a/lib/mobilizon_web/upload/filter/filter.ex b/lib/web/upload/filter/filter.ex similarity index 76% rename from lib/mobilizon_web/upload/filter/filter.ex rename to lib/web/upload/filter/filter.ex index 392d2b3a..63ef1686 100644 --- a/lib/mobilizon_web/upload/filter/filter.ex +++ b/lib/web/upload/filter/filter.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload/filter.ex -defmodule MobilizonWeb.Upload.Filter do +defmodule Mobilizon.Web.Upload.Filter do @moduledoc """ Upload Filter behaviour @@ -16,11 +16,11 @@ defmodule MobilizonWeb.Upload.Filter do require Logger - @callback filter(MobilizonWeb.Upload.t()) :: - :ok | {:ok, MobilizonWeb.Upload.t()} | {:error, any()} + @callback filter(Mobilizon.Web.Upload.t()) :: + :ok | {:ok, Mobilizon.Web.Upload.t()} | {:error, any()} - @spec filter([module()], MobilizonWeb.Upload.t()) :: - {:ok, MobilizonWeb.Upload.t()} | {:error, any()} + @spec filter([module()], Mobilizon.Web.Upload.t()) :: + {:ok, Mobilizon.Web.Upload.t()} | {:error, any()} def filter([], upload) do {:ok, upload} diff --git a/lib/mobilizon_web/upload/filter/mogrify.ex b/lib/web/upload/filter/mogrify.ex similarity index 86% rename from lib/mobilizon_web/upload/filter/mogrify.ex rename to lib/web/upload/filter/mogrify.ex index e7ae715c..fbf9e491 100644 --- a/lib/mobilizon_web/upload/filter/mogrify.ex +++ b/lib/web/upload/filter/mogrify.ex @@ -3,19 +3,19 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload/filter/mogrify.ex -defmodule MobilizonWeb.Upload.Filter.Mogrify do +defmodule Mobilizon.Web.Upload.Filter.Mogrify do @moduledoc """ Handle mogrify transformations """ - @behaviour MobilizonWeb.Upload.Filter + @behaviour Mobilizon.Web.Upload.Filter alias Mobilizon.Config @type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()} @type conversions :: conversion() | [conversion()] - def filter(%MobilizonWeb.Upload{tempfile: file, content_type: "image" <> _}) do + def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do filters = Config.get!([__MODULE__, :args]) file diff --git a/lib/mobilizon_web/upload/filter/optimize.ex b/lib/web/upload/filter/optimize.ex similarity index 77% rename from lib/mobilizon_web/upload/filter/optimize.ex rename to lib/web/upload/filter/optimize.ex index de95b125..0162f6c1 100644 --- a/lib/mobilizon_web/upload/filter/optimize.ex +++ b/lib/web/upload/filter/optimize.ex @@ -1,9 +1,9 @@ -defmodule MobilizonWeb.Upload.Filter.Optimize do +defmodule Mobilizon.Web.Upload.Filter.Optimize do @moduledoc """ Handle picture optimizations """ - @behaviour MobilizonWeb.Upload.Filter + @behaviour Mobilizon.Web.Upload.Filter alias Mobilizon.Config @@ -16,7 +16,7 @@ defmodule MobilizonWeb.Upload.Filter.Optimize do Cwebp ] - def filter(%MobilizonWeb.Upload{tempfile: file, content_type: "image" <> _}) do + def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do optimizers = Config.get([__MODULE__, :optimizers], @default_optimizers) case ExOptimizer.optimize(file, deps: optimizers) do diff --git a/lib/mobilizon_web/upload/mime.ex b/lib/web/upload/mime.ex similarity index 98% rename from lib/mobilizon_web/upload/mime.ex rename to lib/web/upload/mime.ex index 786c4e7f..206a6347 100644 --- a/lib/mobilizon_web/upload/mime.ex +++ b/lib/web/upload/mime.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/mime.ex -defmodule MobilizonWeb.Upload.MIME do +defmodule Mobilizon.Web.Upload.MIME do @moduledoc """ Returns the mime-type of a binary and optionally a normalized file-name. """ diff --git a/lib/mobilizon_web/upload/upload.ex b/lib/web/upload/upload.ex similarity index 93% rename from lib/mobilizon_web/upload/upload.ex rename to lib/web/upload/upload.ex index 6ddeb2f0..ae2845d7 100644 --- a/lib/mobilizon_web/upload/upload.ex +++ b/lib/web/upload/upload.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload.ex -defmodule MobilizonWeb.Upload do +defmodule Mobilizon.Web.Upload do @moduledoc """ Manage user uploads @@ -16,7 +16,7 @@ defmodule MobilizonWeb.Upload do * `:size_limit`: override size limit * `:activity_type`: override activity type - The `%MobilizonWeb.Upload{}` struct: all documented fields are meant to be overwritten in filters: + The `%Mobilizon.Web.Upload{}` struct: all documented fields are meant to be overwritten in filters: * `:id` - the upload id. * `:name` - the upload file name. @@ -27,8 +27,8 @@ defmodule MobilizonWeb.Upload do Related behaviors: - * `MobilizonWeb.Upload.Uploader` - * `MobilizonWeb.Upload.Filter` + * `Mobilizon.Web.Upload.Uploader` + * `Mobilizon.Web.Upload.Filter` """ @@ -36,7 +36,7 @@ defmodule MobilizonWeb.Upload do alias Mobilizon.Config - alias MobilizonWeb.Upload.{Filter, MIME, Uploader} + alias Mobilizon.Web.Upload.{Filter, MIME, Uploader} require Logger @@ -91,7 +91,7 @@ defmodule MobilizonWeb.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 == MobilizonWeb.Endpoint.host()} do + {:same_host, true} <- {:same_host, host == Mobilizon.Web.Endpoint.host()} do Uploader.remove_file(opts.uploader, path) else %URI{} = _uri -> @@ -129,7 +129,7 @@ defmodule MobilizonWeb.Upload do Keyword.get( opts, :base_url, - Config.get([__MODULE__, :base_url], MobilizonWeb.Endpoint.url()) + Config.get([__MODULE__, :base_url], Mobilizon.Web.Endpoint.url()) ) } end diff --git a/lib/mobilizon_web/upload/uploader/local.ex b/lib/web/upload/uploader/local.ex similarity index 94% rename from lib/mobilizon_web/upload/uploader/local.ex rename to lib/web/upload/uploader/local.ex index 48ea0eb4..5304820f 100644 --- a/lib/mobilizon_web/upload/uploader/local.ex +++ b/lib/web/upload/uploader/local.ex @@ -3,12 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/uploaders/local.ex -defmodule MobilizonWeb.Upload.Uploader.Local do +defmodule Mobilizon.Web.Upload.Uploader.Local do @moduledoc """ Local uploader for files """ - @behaviour MobilizonWeb.Upload.Uploader + @behaviour Mobilizon.Web.Upload.Uploader alias Mobilizon.Config diff --git a/lib/mobilizon_web/upload/uploader/uploader.ex b/lib/web/upload/uploader/uploader.ex similarity index 91% rename from lib/mobilizon_web/upload/uploader/uploader.ex rename to lib/web/upload/uploader/uploader.ex index eb02eecd..5c163b9c 100644 --- a/lib/mobilizon_web/upload/uploader/uploader.ex +++ b/lib/web/upload/uploader/uploader.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/uploaders/uploader.ex -defmodule MobilizonWeb.Upload.Uploader do +defmodule Mobilizon.Web.Upload.Uploader do @moduledoc """ Defines the contract to put and get an uploaded file to any backend. """ @@ -11,7 +11,7 @@ defmodule MobilizonWeb.Upload.Uploader do @doc """ Instructs how to get the file from the backend. - Used by `MobilizonWeb.Plugs.UploadedMedia`. + Used by `Mobilizon.Web.Plugs.UploadedMedia`. """ @type get_method :: {:static_dir, directory :: String.t()} | {:url, url :: String.t()} @callback get_file(file :: String.t()) :: {:ok, get_method()} @@ -32,7 +32,7 @@ defmodule MobilizonWeb.Upload.Uploader do """ @type file_spec :: {:file | :url, String.t()} - @callback put_file(MobilizonWeb.Upload.t()) :: + @callback put_file(Mobilizon.Web.Upload.t()) :: :ok | {:ok, file_spec()} | {:error, String.t()} | :wait_callback @callback remove_file(file_spec()) :: :ok | {:ok, file_spec()} | {:error, String.t()} @@ -43,7 +43,7 @@ defmodule MobilizonWeb.Upload.Uploader do | {:error, Plug.Conn.t(), String.t()} @optional_callbacks http_callback: 2 - @spec put_file(module(), MobilizonWeb.Upload.t()) :: {:ok, file_spec()} | {:error, String.t()} + @spec put_file(module(), Mobilizon.Web.Upload.t()) :: {:ok, file_spec()} | {:error, String.t()} def put_file(uploader, upload) do case uploader.put_file(upload) do :ok -> {:ok, {:file, upload.path}} diff --git a/lib/mobilizon_web/views/activity_pub/actor_view.ex b/lib/web/views/activity_pub/actor_view.ex similarity index 98% rename from lib/mobilizon_web/views/activity_pub/actor_view.ex rename to lib/web/views/activity_pub/actor_view.ex index 5d207a8c..4a43c65d 100644 --- a/lib/mobilizon_web/views/activity_pub/actor_view.ex +++ b/lib/web/views/activity_pub/actor_view.ex @@ -1,5 +1,5 @@ -defmodule MobilizonWeb.ActivityPub.ActorView do - use MobilizonWeb, :view +defmodule Mobilizon.Web.ActivityPub.ActorView do + use Mobilizon.Web, :view alias Mobilizon.Actors alias Mobilizon.Actors.Actor diff --git a/lib/mobilizon_web/views/activity_pub/object_view.ex b/lib/web/views/activity_pub/object_view.ex similarity index 90% rename from lib/mobilizon_web/views/activity_pub/object_view.ex rename to lib/web/views/activity_pub/object_view.ex index f0a77dad..2b4ee109 100644 --- a/lib/mobilizon_web/views/activity_pub/object_view.ex +++ b/lib/web/views/activity_pub/object_view.ex @@ -1,5 +1,5 @@ -defmodule MobilizonWeb.ActivityPub.ObjectView do - use MobilizonWeb, :view +defmodule Mobilizon.Web.ActivityPub.ObjectView do + use Mobilizon.Web, :view alias Mobilizon.Federation.ActivityPub.{Activity, Utils} diff --git a/lib/mobilizon_web/views/changeset_view.ex b/lib/web/views/changeset_view.ex similarity index 78% rename from lib/mobilizon_web/views/changeset_view.ex rename to lib/web/views/changeset_view.ex index eebe9553..0fa250a6 100644 --- a/lib/mobilizon_web/views/changeset_view.ex +++ b/lib/web/views/changeset_view.ex @@ -1,14 +1,14 @@ -defmodule MobilizonWeb.ChangesetView do +defmodule Mobilizon.Web.ChangesetView do @moduledoc """ View for changesets in case of errors """ - use MobilizonWeb, :view + use Mobilizon.Web, :view @doc """ Traverses and translates changeset errors. See `Ecto.Changeset.traverse_errors/2` and - `MobilizonWeb.ErrorHelpers.translate_error/1` for more details. + `Mobilizon.Web.ErrorHelpers.translate_error/1` for more details. """ def translate_errors(changeset) do Ecto.Changeset.traverse_errors(changeset, &translate_error/1) diff --git a/lib/mobilizon_web/views/email_view.ex b/lib/web/views/email_view.ex similarity index 70% rename from lib/mobilizon_web/views/email_view.ex rename to lib/web/views/email_view.ex index a65d3ce5..bb81467a 100644 --- a/lib/mobilizon_web/views/email_view.ex +++ b/lib/web/views/email_view.ex @@ -1,7 +1,7 @@ -defmodule MobilizonWeb.EmailView do - use MobilizonWeb, :view +defmodule Mobilizon.Web.EmailView do + use Mobilizon.Web, :view - import MobilizonWeb.Gettext + import Mobilizon.Web.Gettext def datetime_to_string(%DateTime{} = datetime, locale \\ "en") do with {:ok, string} <- diff --git a/lib/mobilizon_web/views/error_helpers.ex b/lib/web/views/error_helpers.ex similarity index 85% rename from lib/mobilizon_web/views/error_helpers.ex rename to lib/web/views/error_helpers.ex index 2ae367b2..be5a36c7 100644 --- a/lib/mobilizon_web/views/error_helpers.ex +++ b/lib/web/views/error_helpers.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.ErrorHelpers do +defmodule Mobilizon.Web.ErrorHelpers do @moduledoc """ Conveniences for translating and building error messages. """ @@ -32,9 +32,9 @@ defmodule MobilizonWeb.ErrorHelpers do # dgettext "errors", "is invalid" # if count = opts[:count] do - Gettext.dngettext(MobilizonWeb.Gettext, "errors", msg, msg, count, opts) + Gettext.dngettext(Mobilizon.Web.Gettext, "errors", msg, msg, count, opts) else - Gettext.dgettext(MobilizonWeb.Gettext, "errors", msg, opts) + Gettext.dgettext(Mobilizon.Web.Gettext, "errors", msg, opts) end end end diff --git a/lib/mobilizon_web/views/error_view.ex b/lib/web/views/error_view.ex similarity index 94% rename from lib/mobilizon_web/views/error_view.ex rename to lib/web/views/error_view.ex index d05bb93d..848b8aa0 100644 --- a/lib/mobilizon_web/views/error_view.ex +++ b/lib/web/views/error_view.ex @@ -1,8 +1,8 @@ -defmodule MobilizonWeb.ErrorView do +defmodule Mobilizon.Web.ErrorView do @moduledoc """ View for errors """ - use MobilizonWeb, :view + use Mobilizon.Web, :view def render("404.html", _assigns) do with {:ok, index_content} <- File.read(index_file_path()) do diff --git a/lib/mobilizon_web/views/json_ld/object_view.ex b/lib/web/views/json_ld/object_view.ex similarity index 91% rename from lib/mobilizon_web/views/json_ld/object_view.ex rename to lib/web/views/json_ld/object_view.ex index 96021a23..55aad9fe 100644 --- a/lib/mobilizon_web/views/json_ld/object_view.ex +++ b/lib/web/views/json_ld/object_view.ex @@ -1,12 +1,12 @@ -defmodule MobilizonWeb.JsonLD.ObjectView do - use MobilizonWeb, :view +defmodule Mobilizon.Web.JsonLD.ObjectView do + use Mobilizon.Web, :view alias Mobilizon.Actors.Actor alias Mobilizon.Addresses.Address alias Mobilizon.Events.Event - alias MobilizonWeb.JsonLD.ObjectView - alias MobilizonWeb.MediaProxy + alias Mobilizon.Web.JsonLD.ObjectView + alias Mobilizon.Web.MediaProxy def render("event.json", %{event: %Event{} = event}) do # TODO: event.description is actually markdown! diff --git a/lib/web/views/layout_view.ex b/lib/web/views/layout_view.ex new file mode 100644 index 00000000..7685cd78 --- /dev/null +++ b/lib/web/views/layout_view.ex @@ -0,0 +1,3 @@ +defmodule Mobilizon.Web.LayoutView do + use Mobilizon.Web, :view +end diff --git a/lib/mobilizon_web/views/page_view.ex b/lib/web/views/page_view.ex similarity index 97% rename from lib/mobilizon_web/views/page_view.ex rename to lib/web/views/page_view.ex index 8a0cc383..873a908f 100644 --- a/lib/mobilizon_web/views/page_view.ex +++ b/lib/web/views/page_view.ex @@ -1,9 +1,9 @@ -defmodule MobilizonWeb.PageView do +defmodule Mobilizon.Web.PageView do @moduledoc """ View for our webapp """ - use MobilizonWeb, :view + use Mobilizon.Web, :view alias Mobilizon.Actors.Actor alias Mobilizon.Events.{Comment, Event} diff --git a/mix.exs b/mix.exs index 2d018b40..55e31469 100644 --- a/mix.exs +++ b/mix.exs @@ -159,10 +159,10 @@ defmodule Mobilizon.Mixfile do groups_for_modules: groups_for_modules(), nest_modules_by_prefix: [ Mobilizon, - MobilizonWeb, + Mobilizon.Web, Mobilizon.Service.Geospatial, - MobilizonWeb.Resolvers, - MobilizonWeb.Schema, + Mobilizon.Web.Resolvers, + Mobilizon.Web.Schema, Mobilizon.Service ] ] @@ -216,56 +216,56 @@ defmodule Mobilizon.Mixfile do Mobilizon.Federation.ActivityPub.Activity ], APIs: [ - MobilizonWeb.API.Comments, - MobilizonWeb.API.Events, - MobilizonWeb.API.Follows, - MobilizonWeb.API.Groups, - MobilizonWeb.API.Participations, - MobilizonWeb.API.Reports, - MobilizonWeb.API.Search, - MobilizonWeb.API.Utils + Mobilizon.Web.API.Comments, + Mobilizon.Web.API.Events, + Mobilizon.Web.API.Follows, + Mobilizon.Web.API.Groups, + Mobilizon.Web.API.Participations, + Mobilizon.Web.API.Reports, + Mobilizon.Web.API.Search, + Mobilizon.Web.API.Utils ], Web: [ - MobilizonWeb, - MobilizonWeb.Endpoint, - MobilizonWeb.Router, - MobilizonWeb.Router.Helpers, - MobilizonWeb.Plugs.UploadedMedia, - MobilizonWeb.FallbackController, - MobilizonWeb.FeedController, - MobilizonWeb.MediaProxyController, - MobilizonWeb.PageController, - MobilizonWeb.ChangesetView, - MobilizonWeb.JsonLD.ObjectView, - MobilizonWeb.EmailView, - MobilizonWeb.ErrorHelpers, - MobilizonWeb.ErrorView, - MobilizonWeb.LayoutView, - MobilizonWeb.PageView, - MobilizonWeb.Auth.Context, - MobilizonWeb.Auth.ErrorHandler, - MobilizonWeb.Auth.Guardian, - MobilizonWeb.Auth.Pipeline, - MobilizonWeb.Cache, - MobilizonWeb.Cache.ActivityPub, - MobilizonWeb.Email, - MobilizonWeb.Email.Admin, - MobilizonWeb.Email.Checker, - MobilizonWeb.Email.Event, - MobilizonWeb.Email.Mailer, - MobilizonWeb.Email.Participation, - MobilizonWeb.Email.User, - MobilizonWeb.Upload, - MobilizonWeb.Upload.Filter, - MobilizonWeb.Upload.Filter.AnonymizeFilename, - MobilizonWeb.Upload.Filter.Dedupe, - MobilizonWeb.Upload.Filter.Mogrify, - MobilizonWeb.Upload.Filter.Optimize, - MobilizonWeb.Upload.MIME, - MobilizonWeb.Upload.Uploader, - MobilizonWeb.Upload.Uploader.Local, - MobilizonWeb.MediaProxy, - MobilizonWeb.ReverseProxy + Mobilizon.Web, + Mobilizon.Web.Endpoint, + Mobilizon.Web.Router, + Mobilizon.Web.Router.Helpers, + Mobilizon.Web.Plugs.UploadedMedia, + Mobilizon.Web.FallbackController, + Mobilizon.Web.FeedController, + Mobilizon.Web.MediaProxyController, + Mobilizon.Web.PageController, + Mobilizon.Web.ChangesetView, + Mobilizon.Web.JsonLD.ObjectView, + Mobilizon.Web.EmailView, + Mobilizon.Web.ErrorHelpers, + Mobilizon.Web.ErrorView, + Mobilizon.Web.LayoutView, + Mobilizon.Web.PageView, + Mobilizon.Web.Auth.Context, + Mobilizon.Web.Auth.ErrorHandler, + Mobilizon.Web.Auth.Guardian, + Mobilizon.Web.Auth.Pipeline, + Mobilizon.Web.Cache, + Mobilizon.Web.Cache.ActivityPub, + Mobilizon.Web.Email, + Mobilizon.Web.Email.Admin, + Mobilizon.Web.Email.Checker, + Mobilizon.Web.Email.Event, + Mobilizon.Web.Email.Mailer, + Mobilizon.Web.Email.Participation, + Mobilizon.Web.Email.User, + Mobilizon.Web.Upload, + Mobilizon.Web.Upload.Filter, + Mobilizon.Web.Upload.Filter.AnonymizeFilename, + Mobilizon.Web.Upload.Filter.Dedupe, + Mobilizon.Web.Upload.Filter.Mogrify, + Mobilizon.Web.Upload.Filter.Optimize, + Mobilizon.Web.Upload.MIME, + Mobilizon.Web.Upload.Uploader, + Mobilizon.Web.Upload.Uploader.Local, + Mobilizon.Web.MediaProxy, + Mobilizon.Web.ReverseProxy ], Geospatial: [ Mobilizon.Service.Geospatial, @@ -280,47 +280,47 @@ defmodule Mobilizon.Mixfile do ], Localization: [ Mobilizon.Cldr, - MobilizonWeb.Gettext + Mobilizon.Web.Gettext ], GraphQL: [ - MobilizonWeb.GraphQLSocket, - MobilizonWeb.Resolvers.Address, - MobilizonWeb.Resolvers.Admin, - MobilizonWeb.Resolvers.Comment, - MobilizonWeb.Resolvers.Config, - MobilizonWeb.Resolvers.Event, - MobilizonWeb.Resolvers.FeedToken, - MobilizonWeb.Resolvers.Group, - MobilizonWeb.Resolvers.Member, - MobilizonWeb.Resolvers.Person, - MobilizonWeb.Resolvers.Picture, - MobilizonWeb.Resolvers.Report, - MobilizonWeb.Resolvers.Search, - MobilizonWeb.Resolvers.Tag, - MobilizonWeb.Resolvers.User, - MobilizonWeb.Schema, - MobilizonWeb.Schema.ActorInterface, - MobilizonWeb.Schema.Actors.ApplicationType, - MobilizonWeb.Schema.Actors.FollowerType, - MobilizonWeb.Schema.Actors.GroupType, - MobilizonWeb.Schema.Actors.MemberType, - MobilizonWeb.Schema.Actors.PersonType, - MobilizonWeb.Schema.AddressType, - MobilizonWeb.Schema.AdminType, - MobilizonWeb.Schema.CommentType, - MobilizonWeb.Schema.ConfigType, - MobilizonWeb.Schema.EventType, - MobilizonWeb.Schema.Events.FeedTokenType, - MobilizonWeb.Schema.Events.ParticipantType, - MobilizonWeb.Schema.PictureType, - MobilizonWeb.Schema.ReportType, - MobilizonWeb.Schema.SearchType, - MobilizonWeb.Schema.SortType, - MobilizonWeb.Schema.TagType, - MobilizonWeb.Schema.UserType, - MobilizonWeb.Schema.Utils, - MobilizonWeb.Schema.Custom.Point, - MobilizonWeb.Schema.Custom.UUID + Mobilizon.Web.GraphQLSocket, + Mobilizon.Web.Resolvers.Address, + Mobilizon.Web.Resolvers.Admin, + Mobilizon.Web.Resolvers.Comment, + Mobilizon.Web.Resolvers.Config, + Mobilizon.Web.Resolvers.Event, + Mobilizon.Web.Resolvers.FeedToken, + Mobilizon.Web.Resolvers.Group, + Mobilizon.Web.Resolvers.Member, + Mobilizon.Web.Resolvers.Person, + Mobilizon.Web.Resolvers.Picture, + Mobilizon.Web.Resolvers.Report, + Mobilizon.Web.Resolvers.Search, + Mobilizon.Web.Resolvers.Tag, + Mobilizon.Web.Resolvers.User, + Mobilizon.Web.Schema, + Mobilizon.Web.Schema.ActorInterface, + Mobilizon.Web.Schema.Actors.ApplicationType, + Mobilizon.Web.Schema.Actors.FollowerType, + Mobilizon.Web.Schema.Actors.GroupType, + Mobilizon.Web.Schema.Actors.MemberType, + Mobilizon.Web.Schema.Actors.PersonType, + Mobilizon.Web.Schema.AddressType, + Mobilizon.Web.Schema.AdminType, + Mobilizon.Web.Schema.CommentType, + Mobilizon.Web.Schema.ConfigType, + Mobilizon.Web.Schema.EventType, + Mobilizon.Web.Schema.Events.FeedTokenType, + Mobilizon.Web.Schema.Events.ParticipantType, + Mobilizon.Web.Schema.PictureType, + Mobilizon.Web.Schema.ReportType, + Mobilizon.Web.Schema.SearchType, + Mobilizon.Web.Schema.SortType, + Mobilizon.Web.Schema.TagType, + Mobilizon.Web.Schema.UserType, + Mobilizon.Web.Schema.Utils, + Mobilizon.Web.Schema.Custom.Point, + Mobilizon.Web.Schema.Custom.UUID ], ActivityPub: [ Mobilizon.Federation.ActivityPub, @@ -345,14 +345,14 @@ defmodule Mobilizon.Mixfile do Mobilizon.Federation.HTTPSignatures.Signature, Mobilizon.Federation.WebFinger, Mobilizon.Federation.WebFinger.XmlBuilder, - MobilizonWeb.Plugs.Federating, - MobilizonWeb.Plugs.HTTPSignatures, - MobilizonWeb.Plugs.MappedSignatureToIdentity, - MobilizonWeb.ActivityPubController, - MobilizonWeb.NodeInfoController, - MobilizonWeb.WebFingerController, - MobilizonWeb.ActivityPub.ActorView, - MobilizonWeb.ActivityPub.ObjectView + Mobilizon.Web.Plugs.Federating, + Mobilizon.Web.Plugs.HTTPSignatures, + Mobilizon.Web.Plugs.MappedSignatureToIdentity, + Mobilizon.Web.ActivityPubController, + Mobilizon.Web.NodeInfoController, + Mobilizon.Web.WebFingerController, + Mobilizon.Web.ActivityPub.ActorView, + Mobilizon.Web.ActivityPub.ObjectView ], Services: [ Mobilizon.Service.Export.Feed, diff --git a/test/federation/activity_pub/transmogrifier_test.exs b/test/federation/activity_pub/transmogrifier_test.exs index f6730a01..f2f57be3 100644 --- a/test/federation/activity_pub/transmogrifier_test.exs +++ b/test/federation/activity_pub/transmogrifier_test.exs @@ -961,7 +961,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do } expected_tag = %{ - "href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu", + "href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu", "type" => "Hashtag", "name" => "#2hu" } @@ -996,7 +996,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do {:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"}) expected_tag = %{ - "href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu", + "href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu", "type" => "Hashtag", "name" => "#2hu" } diff --git a/test/federation/activity_pub/utils_test.exs b/test/federation/activity_pub/utils_test.exs index 94963589..5c471f3e 100644 --- a/test/federation/activity_pub/utils_test.exs +++ b/test/federation/activity_pub/utils_test.exs @@ -7,8 +7,8 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do alias Mobilizon.Federation.ActivityStream.Converter - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes setup_all do HTTPoison.start() diff --git a/test/federation/web_finger/web_finger_test.exs b/test/federation/web_finger/web_finger_test.exs index 4d3337f8..ef786b5d 100644 --- a/test/federation/web_finger/web_finger_test.exs +++ b/test/federation/web_finger/web_finger_test.exs @@ -24,7 +24,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, MobilizonWeb.Endpoint.url()) + assert String.contains?(host_info, Mobilizon.Web.Endpoint.url()) end end @@ -33,7 +33,7 @@ defmodule Mobilizon.Federation.WebFingerTest do actor = insert(:actor) {:ok, result} = - WebFinger.webfinger("#{actor.preferred_username}@#{MobilizonWeb.Endpoint.host()}", "JSON") + WebFinger.webfinger("#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", "JSON") assert is_map(result) end diff --git a/test/fixtures/vcr_cassettes/relay/fetch_relay_follow.json b/test/fixtures/vcr_cassettes/relay/fetch_relay_follow.json index dc85a48f..7d402794 100644 --- a/test/fixtures/vcr_cassettes/relay/fetch_relay_follow.json +++ b/test/fixtures/vcr_cassettes/relay/fetch_relay_follow.json @@ -81,7 +81,7 @@ }, "response": { "binary": false, - "body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Federation.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Federation.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: MobilizonWeb.HTTPSignaturePlug.call/2\n (mobilizon) MobilizonWeb.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: MobilizonWeb.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: MobilizonWeb.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/b7791977-2a75-4715-815b-6e7125065b71\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:41 GMT\n * digest: SHA-256=ibNFcsnBeCCjWZo9We60tKfbRN3el0WCMVdOxtuC1cg=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"WbyGHT/WdvdRpWek8uCGHrFSblLpg+Iq802R5S2cjNj035OKpxRmu1r8u9Qr5KGIKgZn6LHt9YmB+PNlwsubPtTSkJpE8AAUDMHLKgCrH7A5Q6x6GlARl5bHNo4QtOxkXvnEbn31xfNDNp70QqZb/emw95TnELYUlMLZds0qYutT8U4WdDhSWcVytQmKJWNZXxEj+KlMDUaxag3lGscJ/HY0F+yGNov7FHthid1Y4LTGFsp/tismnMTlba12NH/kXPHtduNsX8uxFslM2ODwqAaospTGEpXmr9CPgbNy7626qgYaR2RdB/fYlCayLI4JJIlH8gOdocGHPrWNtVEHaQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n", + "body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Federation.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Federation.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: Mobilizon.Web.HTTPSignaturePlug.call/2\n (mobilizon) Mobilizon.Web.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: Mobilizon.Web.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: Mobilizon.Web.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: Mobilizon.Web.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: Mobilizon.Web.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/b7791977-2a75-4715-815b-6e7125065b71\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:41 GMT\n * digest: SHA-256=ibNFcsnBeCCjWZo9We60tKfbRN3el0WCMVdOxtuC1cg=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"WbyGHT/WdvdRpWek8uCGHrFSblLpg+Iq802R5S2cjNj035OKpxRmu1r8u9Qr5KGIKgZn6LHt9YmB+PNlwsubPtTSkJpE8AAUDMHLKgCrH7A5Q6x6GlARl5bHNo4QtOxkXvnEbn31xfNDNp70QqZb/emw95TnELYUlMLZds0qYutT8U4WdDhSWcVytQmKJWNZXxEj+KlMDUaxag3lGscJ/HY0F+yGNov7FHthid1Y4LTGFsp/tismnMTlba12NH/kXPHtduNsX8uxFslM2ODwqAaospTGEpXmr9CPgbNy7626qgYaR2RdB/fYlCayLI4JJIlH8gOdocGHPrWNtVEHaQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n", "headers": { "Server": "nginx/1.16.1", "Date": "Fri, 13 Dec 2019 09:41:41 GMT", diff --git a/test/fixtures/vcr_cassettes/relay/fetch_relay_unfollow.json b/test/fixtures/vcr_cassettes/relay/fetch_relay_unfollow.json index 7b743e63..2fa5b2c2 100644 --- a/test/fixtures/vcr_cassettes/relay/fetch_relay_unfollow.json +++ b/test/fixtures/vcr_cassettes/relay/fetch_relay_unfollow.json @@ -81,7 +81,7 @@ }, "response": { "binary": false, - "body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Service.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Service.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: MobilizonWeb.HTTPSignaturePlug.call/2\n (mobilizon) MobilizonWeb.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: MobilizonWeb.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: MobilizonWeb.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/57a6973e-f43f-4533-bf71-7a14a4c6e5ac\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:40 GMT\n * digest: SHA-256=Qc9d9X3qh2EqIqtn/72iY17OMDXAOINDC10hARNAc4w=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"JQPqSiJ0ZYdU6llrYXNMuN/bfzoLyubwOB59bljFq6i8ORXLw62Pt7Jue5WkMsySFcCXgS8k8K/H81YZkKzfWadwQV9L5rQEFSuW/DYJ2xffsDj90GsSi+sDRaQ5Ke8nPEbEMGR9jalh/F2VL97XscCgm6i3tdpbs6aFmqjKC+LzeH665t0WCHUxTgK47wECrMHw3j7lteGdm6N6IKWoWsRYeJoyFr/QCbNdWQOaAYYpCbJd0fjhPQRHhWQXidBoaDkhwesWc3mO8pvEnply9ES7Nzc6ULK7B98hg+aWeep8/KzRbxFyJ0OgnDJj/l39QiJ9t7v0yHX/WUzn0CaiiQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n", + "body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Service.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Service.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: Mobilizon.Web.HTTPSignaturePlug.call/2\n (mobilizon) Mobilizon.Web.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: Mobilizon.Web.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: Mobilizon.Web.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: Mobilizon.Web.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: Mobilizon.Web.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/57a6973e-f43f-4533-bf71-7a14a4c6e5ac\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:40 GMT\n * digest: SHA-256=Qc9d9X3qh2EqIqtn/72iY17OMDXAOINDC10hARNAc4w=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"JQPqSiJ0ZYdU6llrYXNMuN/bfzoLyubwOB59bljFq6i8ORXLw62Pt7Jue5WkMsySFcCXgS8k8K/H81YZkKzfWadwQV9L5rQEFSuW/DYJ2xffsDj90GsSi+sDRaQ5Ke8nPEbEMGR9jalh/F2VL97XscCgm6i3tdpbs6aFmqjKC+LzeH665t0WCHUxTgK47wECrMHw3j7lteGdm6N6IKWoWsRYeJoyFr/QCbNdWQOaAYYpCbJd0fjhPQRHhWQXidBoaDkhwesWc3mO8pvEnply9ES7Nzc6ULK7B98hg+aWeep8/KzRbxFyJ0OgnDJj/l39QiJ9t7v0yHX/WUzn0CaiiQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n", "headers": { "Server": "nginx/1.16.1", "Date": "Fri, 13 Dec 2019 09:41:40 GMT", diff --git a/test/graphql/resolvers/address_test.exs b/test/graphql/resolvers/address_test.exs index f55eb743..b204a7bf 100644 --- a/test/graphql/resolvers/address_test.exs +++ b/test/graphql/resolvers/address_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.AddressTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/admin_test.exs b/test/graphql/resolvers/admin_test.exs index a4e61fce..e8a1c699 100644 --- a/test/graphql/resolvers/admin_test.exs +++ b/test/graphql/resolvers/admin_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/comment_test.exs b/test/graphql/resolvers/comment_test.exs index d4469253..9e5ceabe 100644 --- a/test/graphql/resolvers/comment_test.exs +++ b/test/graphql/resolvers/comment_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/config_test.exs b/test/graphql/resolvers/config_test.exs index a126df97..2e516f19 100644 --- a/test/graphql/resolvers/config_test.exs +++ b/test/graphql/resolvers/config_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase use Bamboo.Test alias Mobilizon.GraphQL.AbsintheHelpers diff --git a/test/graphql/resolvers/event_test.exs b/test/graphql/resolvers/event_test.exs index b1ebd9d3..d817984e 100644 --- a/test/graphql/resolvers/event_test.exs +++ b/test/graphql/resolvers/event_test.exs @@ -1,5 +1,5 @@ -defmodule MobilizonWeb.Resolvers.EventTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.Resolvers.EventTest do + use Mobilizon.Web.ConnCase use Bamboo.Test use Oban.Testing, repo: Mobilizon.Storage.Repo @@ -10,7 +10,7 @@ defmodule MobilizonWeb.Resolvers.EventTest do alias Mobilizon.GraphQL.AbsintheHelpers - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @event %{ description: "some body", diff --git a/test/graphql/resolvers/feed_token_test.exs b/test/graphql/resolvers/feed_token_test.exs index 2810ed73..931c8c34 100644 --- a/test/graphql/resolvers/feed_token_test.exs +++ b/test/graphql/resolvers/feed_token_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedTokenTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/group_test.exs b/test/graphql/resolvers/group_test.exs index 4c0b29cf..00763a84 100644 --- a/test/graphql/resolvers/group_test.exs +++ b/test/graphql/resolvers/group_test.exs @@ -1,5 +1,5 @@ -defmodule MobilizonWeb.Resolvers.GroupTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.Resolvers.GroupTest do + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/member_test.exs b/test/graphql/resolvers/member_test.exs index b98906ce..9dcf4e25 100644 --- a/test/graphql/resolvers/member_test.exs +++ b/test/graphql/resolvers/member_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/participant_test.exs b/test/graphql/resolvers/participant_test.exs index 66e74475..632299de 100644 --- a/test/graphql/resolvers/participant_test.exs +++ b/test/graphql/resolvers/participant_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase use Bamboo.Test import Mobilizon.Factory @@ -7,7 +7,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do alias Mobilizon.Events alias Mobilizon.GraphQL.AbsintheHelpers - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @event %{ description: "some body", diff --git a/test/graphql/resolvers/person_test.exs b/test/graphql/resolvers/person_test.exs index 730d3d51..20094426 100644 --- a/test/graphql/resolvers/person_test.exs +++ b/test/graphql/resolvers/person_test.exs @@ -1,6 +1,6 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do use Oban.Testing, repo: Mobilizon.Storage.Repo - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory @@ -121,7 +121,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do actor.preferred_username assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~ - MobilizonWeb.Endpoint.url() + Mobilizon.Web.Endpoint.url() end test "create_person/3 creates a new identity", context do @@ -255,7 +255,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do "The beautiful atlantic way" assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~ - MobilizonWeb.Endpoint.url() <> "/media/" + Mobilizon.Web.Endpoint.url() <> "/media/" end test "update_person/3 updates an existing identity", context do @@ -325,7 +325,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"] =~ MobilizonWeb.Endpoint.url() <> "/media/" + assert res_person["banner"]["url"] =~ Mobilizon.Web.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 a8daeca0..b2a61538 100644 --- a/test/graphql/resolvers/picture_test.exs +++ b/test/graphql/resolvers/picture_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase use Bamboo.Test import Mobilizon.Factory @@ -43,7 +43,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"] =~ - MobilizonWeb.Endpoint.url() + Mobilizon.Web.Endpoint.url() end test "picture/3 returns nothing on a non-existent picture", context do diff --git a/test/graphql/resolvers/report_test.exs b/test/graphql/resolvers/report_test.exs index 2a083845..484cae0e 100644 --- a/test/graphql/resolvers/report_test.exs +++ b/test/graphql/resolvers/report_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/search_test.exs b/test/graphql/resolvers/search_test.exs index 6f8d436d..dd34d512 100644 --- a/test/graphql/resolvers/search_test.exs +++ b/test/graphql/resolvers/search_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.SearchTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/tag_test.exs b/test/graphql/resolvers/tag_test.exs index 3ef15f95..271ecbd4 100644 --- a/test/graphql/resolvers/tag_test.exs +++ b/test/graphql/resolvers/tag_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.TagTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory diff --git a/test/graphql/resolvers/user_test.exs b/test/graphql/resolvers/user_test.exs index 74ee6397..91b88320 100644 --- a/test/graphql/resolvers/user_test.exs +++ b/test/graphql/resolvers/user_test.exs @@ -1,5 +1,5 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase use Bamboo.Test import Mobilizon.Factory @@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do alias Mobilizon.GraphQL.AbsintheHelpers - alias MobilizonWeb.Email + alias Mobilizon.Web.Email @valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"} @valid_single_actor_params %{preferred_username: "test2", keys: "yolo"} diff --git a/test/mobilizon/actors/actors_test.exs b/test/mobilizon/actors/actors_test.exs index 0d4e5c80..2a2db092 100644 --- a/test/mobilizon/actors/actors_test.exs +++ b/test/mobilizon/actors/actors_test.exs @@ -14,7 +14,7 @@ defmodule Mobilizon.ActorsTest do alias Mobilizon.Federation.ActivityPub - alias MobilizonWeb.Upload.Uploader + alias Mobilizon.Web.Upload.Uploader describe "actors" do @valid_attrs %{ @@ -258,7 +258,7 @@ defmodule Mobilizon.ActorsTest do filename: "image.jpg" } - {:ok, data} = MobilizonWeb.Upload.store(file) + {:ok, data} = Mobilizon.Web.Upload.store(file) assert {:ok, actor} = Actors.update_actor( diff --git a/test/mobilizon/media/media_test.exs b/test/mobilizon/media/media_test.exs index bb16b8b1..50cedb5d 100644 --- a/test/mobilizon/media/media_test.exs +++ b/test/mobilizon/media/media_test.exs @@ -5,7 +5,7 @@ defmodule Mobilizon.MediaTest do alias Mobilizon.{Config, Media} - alias MobilizonWeb.Upload.Uploader + alias Mobilizon.Web.Upload.Uploader describe "media" do setup [:ensure_local_uploader] diff --git a/test/mobilizon_web/views/error_view_test.exs b/test/mobilizon_web/views/error_view_test.exs deleted file mode 100644 index fc757140..00000000 --- a/test/mobilizon_web/views/error_view_test.exs +++ /dev/null @@ -1,19 +0,0 @@ -defmodule MobilizonWeb.ErrorViewTest do - use MobilizonWeb.ConnCase, async: true - - # Bring render/3 and render_to_string/3 for testing custom views - import Phoenix.View - - test "renders 404.html" do - assert render_to_string(MobilizonWeb.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(MobilizonWeb.ErrorView, "500.html", []) == "Internal server error" - end - - test "render any other" do - assert render_to_string(MobilizonWeb.ErrorView, "505.html", []) == "Internal server error" - end -end diff --git a/test/mobilizon_web/views/layout_view_test.exs b/test/mobilizon_web/views/layout_view_test.exs deleted file mode 100644 index c8c8d636..00000000 --- a/test/mobilizon_web/views/layout_view_test.exs +++ /dev/null @@ -1,3 +0,0 @@ -defmodule MobilizonWeb.LayoutViewTest do - use MobilizonWeb.ConnCase, async: true -end diff --git a/test/mobilizon_web/views/page_view_test.exs b/test/mobilizon_web/views/page_view_test.exs deleted file mode 100644 index 5280b55d..00000000 --- a/test/mobilizon_web/views/page_view_test.exs +++ /dev/null @@ -1,3 +0,0 @@ -defmodule MobilizonWeb.PageViewTest do - use MobilizonWeb.ConnCase, async: true -end diff --git a/test/support/abinthe_helpers.ex b/test/support/abinthe_helpers.ex index 8bf05438..f41b1e84 100644 --- a/test/support/abinthe_helpers.ex +++ b/test/support/abinthe_helpers.ex @@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.AbsintheHelpers do use Phoenix.ConnTest - @endpoint MobilizonWeb.Endpoint + @endpoint Mobilizon.Web.Endpoint def query_skeleton(query, query_name) do %{ diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 5bfb388e..86cbdeb8 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.ChannelCase do +defmodule Mobilizon.Web.ChannelCase do @moduledoc """ This module defines the test case to be used by channel tests. @@ -25,7 +25,7 @@ defmodule MobilizonWeb.ChannelCase do use Phoenix.ChannelTest # The default endpoint for testing - @endpoint MobilizonWeb.Endpoint + @endpoint Mobilizon.Web.Endpoint end end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 18685ea9..ee76c8fa 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,4 +1,4 @@ -defmodule MobilizonWeb.ConnCase do +defmodule Mobilizon.Web.ConnCase do @moduledoc """ This module defines the test case to be used by tests that require setting up a connection. @@ -24,13 +24,13 @@ defmodule MobilizonWeb.ConnCase do quote do # Import conveniences for testing with connections use Phoenix.ConnTest - import MobilizonWeb.Router.Helpers + import Mobilizon.Web.Router.Helpers # The default endpoint for testing - @endpoint MobilizonWeb.Endpoint + @endpoint Mobilizon.Web.Endpoint def auth_conn(%Plug.Conn{} = conn, %User{} = user) do - {:ok, token, _claims} = MobilizonWeb.Auth.Guardian.encode_and_sign(user) + {:ok, token, _claims} = Mobilizon.Web.Auth.Guardian.encode_and_sign(user) conn |> Plug.Conn.put_req_header("authorization", "Bearer #{token}") diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 886ef2e2..61b22b62 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -19,8 +19,8 @@ defmodule Mobilizon.DataCase do alias Mobilizon.Config alias Mobilizon.Storage.Repo - alias MobilizonWeb.Upload - alias MobilizonWeb.Upload.Uploader + alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Uploader using do quote do diff --git a/test/support/factory.ex b/test/support/factory.ex index f48e8c92..00674c50 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -8,9 +8,9 @@ defmodule Mobilizon.Factory do alias Mobilizon.Actors.Actor alias Mobilizon.Crypto - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes - alias MobilizonWeb.Upload + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes + alias Mobilizon.Web.Upload def user_factory do %Mobilizon.Users.User{ @@ -60,7 +60,7 @@ defmodule Mobilizon.Factory do target_actor: build(:actor), actor: build(:actor), id: uuid, - url: "#{MobilizonWeb.Endpoint.url()}/follows/#{uuid}" + url: "#{Mobilizon.Web.Endpoint.url()}/follows/#{uuid}" } end diff --git a/test/mobilizon_web/controllers/activity_pub_controller_test.exs b/test/web/controllers/activity_pub_controller_test.exs similarity index 97% rename from test/mobilizon_web/controllers/activity_pub_controller_test.exs rename to test/web/controllers/activity_pub_controller_test.exs index e53487df..bd4ad85f 100644 --- a/test/mobilizon_web/controllers/activity_pub_controller_test.exs +++ b/test/web/controllers/activity_pub_controller_test.exs @@ -3,10 +3,10 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_controller_test.exs -defmodule MobilizonWeb.ActivityPubControllerTest do +defmodule Mobilizon.Web.ActivityPubControllerTest do use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney - use MobilizonWeb.ConnCase + use Mobilizon.Web.ConnCase import Mobilizon.Factory @@ -15,10 +15,10 @@ defmodule MobilizonWeb.ActivityPubControllerTest do alias Mobilizon.Federation.ActivityPub - alias MobilizonWeb.ActivityPub.ActorView - alias MobilizonWeb.Endpoint - alias MobilizonWeb.PageView - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.ActivityPub.ActorView + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.PageView + alias Mobilizon.Web.Router.Helpers, as: Routes setup_all do Mobilizon.Config.put([:instance, :federating], true) @@ -104,7 +104,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do conn = conn |> assign(:valid_signature, true) - |> post("#{MobilizonWeb.Endpoint.url()}/inbox", data) + |> post("#{Mobilizon.Web.Endpoint.url()}/inbox", data) assert "ok" == json_response(conn, 200) :timer.sleep(500) diff --git a/test/mobilizon_web/controllers/feed_controller_test.exs b/test/web/controllers/feed_controller_test.exs similarity index 98% rename from test/mobilizon_web/controllers/feed_controller_test.exs rename to test/web/controllers/feed_controller_test.exs index a9d4423b..e4247128 100644 --- a/test/mobilizon_web/controllers/feed_controller_test.exs +++ b/test/web/controllers/feed_controller_test.exs @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.FeedControllerTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.FeedControllerTest do + use Mobilizon.Web.ConnCase import Mobilizon.Factory - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes describe "/@:preferred_username/feed/atom" do test "it returns an RSS representation of the actor's public events if the actor is publicly visible", diff --git a/test/mobilizon_web/controllers/nodeinfo_controller_test.exs b/test/web/controllers/nodeinfo_controller_test.exs similarity index 91% rename from test/mobilizon_web/controllers/nodeinfo_controller_test.exs rename to test/web/controllers/nodeinfo_controller_test.exs index 28c0fa10..8708986e 100644 --- a/test/mobilizon_web/controllers/nodeinfo_controller_test.exs +++ b/test/web/controllers/nodeinfo_controller_test.exs @@ -1,10 +1,10 @@ -defmodule MobilizonWeb.NodeInfoControllerTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.NodeInfoControllerTest do + use Mobilizon.Web.ConnCase alias Mobilizon.Config - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes test "Get node info schemas", %{conn: conn} do conn = get(conn, node_info_path(conn, :schemas)) diff --git a/test/mobilizon_web/controllers/page_controller_test.exs b/test/web/controllers/page_controller_test.exs similarity index 92% rename from test/mobilizon_web/controllers/page_controller_test.exs rename to test/web/controllers/page_controller_test.exs index 9077a7af..c0f81bc7 100644 --- a/test/mobilizon_web/controllers/page_controller_test.exs +++ b/test/web/controllers/page_controller_test.exs @@ -1,12 +1,12 @@ -defmodule MobilizonWeb.PageControllerTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.PageControllerTest do + use Mobilizon.Web.ConnCase import Mobilizon.Factory alias Mobilizon.Actors.Actor - alias MobilizonWeb.Endpoint - alias MobilizonWeb.Router.Helpers, as: Routes + alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.Router.Helpers, as: Routes setup do conn = build_conn() |> put_req_header("accept", "text/html") diff --git a/test/mobilizon_web/controllers/webfinger_controller_test.exs b/test/web/controllers/webfinger_controller_test.exs similarity index 92% rename from test/mobilizon_web/controllers/webfinger_controller_test.exs rename to test/web/controllers/webfinger_controller_test.exs index 11739330..03a26b6c 100644 --- a/test/mobilizon_web/controllers/webfinger_controller_test.exs +++ b/test/web/controllers/webfinger_controller_test.exs @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs -defmodule MobilizonWeb.WebFingerControllerTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.WebFingerControllerTest do + use Mobilizon.Web.ConnCase import Mobilizon.Factory @@ -22,7 +22,7 @@ defmodule MobilizonWeb.WebFingerControllerTest do assert response(conn, 200) == "" assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers diff --git a/test/mobilizon_web/plugs/federating_test.exs b/test/web/plugs/federating_test.exs similarity index 85% rename from test/mobilizon_web/plugs/federating_test.exs rename to test/web/plugs/federating_test.exs index 9d704546..feaa3399 100644 --- a/test/mobilizon_web/plugs/federating_test.exs +++ b/test/web/plugs/federating_test.exs @@ -3,10 +3,10 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule MobilizonWeb.Plug.FederatingTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.Plug.FederatingTest do + use Mobilizon.Web.ConnCase - alias MobilizonWeb.Plugs.Federating + alias Mobilizon.Web.Plugs.Federating test "returns and halt the conn when federating is disabled" do Mobilizon.Config.put([:instance, :federating], false) diff --git a/test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs b/test/web/plugs/mapped_identity_to_signature_test.exs similarity index 93% rename from test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs rename to test/web/plugs/mapped_identity_to_signature_test.exs index 1a24ea86..b5142521 100644 --- a/test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs +++ b/test/web/plugs/mapped_identity_to_signature_test.exs @@ -3,11 +3,11 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule MobilizonWeb.Plugs.MappedSignatureToIdentityTest do - use MobilizonWeb.ConnCase +defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentityTest do + use Mobilizon.Web.ConnCase use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney - alias MobilizonWeb.Plugs.MappedSignatureToIdentity + alias Mobilizon.Web.Plugs.MappedSignatureToIdentity defp set_signature(conn, key_id) do conn diff --git a/test/mobilizon_web/plugs/uploaded_media_test.exs b/test/web/plugs/uploaded_media_test.exs similarity index 91% rename from test/mobilizon_web/plugs/uploaded_media_test.exs rename to test/web/plugs/uploaded_media_test.exs index f0dd2af5..9702a942 100644 --- a/test/mobilizon_web/plugs/uploaded_media_test.exs +++ b/test/web/plugs/uploaded_media_test.exs @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/plugs/uploaded_media_plug_test.ex -defmodule MobilizonWeb.Plugs.UploadedMediaPlugTest do - use MobilizonWeb.ConnCase - alias MobilizonWeb.Upload +defmodule Mobilizon.Web.Plugs.UploadedMediaPlugTest do + use Mobilizon.Web.ConnCase + alias Mobilizon.Web.Upload defp upload_file(context) do Mobilizon.DataCase.ensure_local_uploader(context) diff --git a/test/mobilizon_web/proxy/media_proxy_test.exs b/test/web/proxy/media_proxy_test.exs similarity index 90% rename from test/mobilizon_web/proxy/media_proxy_test.exs rename to test/web/proxy/media_proxy_test.exs index 46ba7442..60363db6 100644 --- a/test/mobilizon_web/proxy/media_proxy_test.exs +++ b/test/web/proxy/media_proxy_test.exs @@ -3,14 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/media_proxy_test.ex -defmodule MobilizonWeb.MediaProxyTest do +defmodule Mobilizon.Web.MediaProxyTest do use ExUnit.Case - import MobilizonWeb.MediaProxy + import Mobilizon.Web.MediaProxy alias Mobilizon.Config - alias MobilizonWeb.MediaProxyController + alias Mobilizon.Web.MediaProxyController setup do enabled = Config.get([:media_proxy, :enabled]) @@ -35,8 +35,8 @@ defmodule MobilizonWeb.MediaProxyTest do end test "ignores local url" do - local_url = MobilizonWeb.Endpoint.url() <> "/hello" - local_root = MobilizonWeb.Endpoint.url() + local_url = Mobilizon.Web.Endpoint.url() <> "/hello" + local_root = Mobilizon.Web.Endpoint.url() assert url(local_url) == local_url assert url(local_root) == local_root end @@ -47,7 +47,7 @@ defmodule MobilizonWeb.MediaProxyTest do assert String.starts_with?( encoded, - Config.get([:media_proxy, :base_url], MobilizonWeb.Endpoint.url()) + Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()) ) assert String.ends_with?(encoded, "/logo.png") @@ -84,16 +84,16 @@ defmodule MobilizonWeb.MediaProxyTest do end test "validates signature" do - secret_key_base = Config.get([MobilizonWeb.Endpoint, :secret_key_base]) + secret_key_base = Config.get([Mobilizon.Web.Endpoint, :secret_key_base]) on_exit(fn -> - Config.put([MobilizonWeb.Endpoint, :secret_key_base], secret_key_base) + Config.put([Mobilizon.Web.Endpoint, :secret_key_base], secret_key_base) end) encoded = url("https://pleroma.social") Config.put( - [MobilizonWeb.Endpoint, :secret_key_base], + [Mobilizon.Web.Endpoint, :secret_key_base], "00000000000000000000000000000000000000000000000" ) diff --git a/test/mobilizon_web/upload/upload_test.exs b/test/web/upload/upload_test.exs similarity index 91% rename from test/mobilizon_web/upload/upload_test.exs rename to test/web/upload/upload_test.exs index 78f2187e..b2845a92 100644 --- a/test/mobilizon_web/upload/upload_test.exs +++ b/test/web/upload/upload_test.exs @@ -8,8 +8,8 @@ defmodule Mobilizon.UploadTest do alias Mobilizon.Config - alias MobilizonWeb.Upload - alias MobilizonWeb.Upload.Uploader + alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Uploader describe "Storing a file with the Local uploader" do setup [:ensure_local_uploader] @@ -31,7 +31,7 @@ defmodule Mobilizon.UploadTest do size: 13_227 } = data - assert String.starts_with?(url, MobilizonWeb.Endpoint.url() <> "/media/") + assert String.starts_with?(url, Mobilizon.Web.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: [MobilizonWeb.Upload.Filter.Dedupe]) + {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.Dedupe]) assert data.url == - MobilizonWeb.Endpoint.url() <> + Mobilizon.Web.Endpoint.url() <> "/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg" end @@ -88,7 +88,7 @@ defmodule Mobilizon.UploadTest do filename: "an [image.jpg" } - {:ok, data} = Upload.store(file, filters: [MobilizonWeb.Upload.Filter.Dedupe]) + {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.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: [MobilizonWeb.Upload.Filter.AnonymizeFilename]) + {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.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, MobilizonWeb.Endpoint.url() <> "/media/") + assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/") %URI{path: "/media/" <> path} = URI.parse(url) {Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url} diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs new file mode 100644 index 00000000..7a4656f4 --- /dev/null +++ b/test/web/views/error_view_test.exs @@ -0,0 +1,19 @@ +defmodule Mobilizon.Web.ErrorViewTest do + use Mobilizon.Web.ConnCase, async: true + + # Bring render/3 and render_to_string/3 for testing custom views + import Phoenix.View + + test "renders 404.html" do + assert render_to_string(Mobilizon.Web.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" + end + + test "render any other" do + assert render_to_string(Mobilizon.Web.ErrorView, "505.html", []) == "Internal server error" + end +end diff --git a/test/web/views/layout_view_test.exs b/test/web/views/layout_view_test.exs new file mode 100644 index 00000000..49f02589 --- /dev/null +++ b/test/web/views/layout_view_test.exs @@ -0,0 +1,3 @@ +defmodule Mobilizon.Web.LayoutViewTest do + use Mobilizon.Web.ConnCase, async: true +end diff --git a/test/web/views/page_view_test.exs b/test/web/views/page_view_test.exs new file mode 100644 index 00000000..9405c5dd --- /dev/null +++ b/test/web/views/page_view_test.exs @@ -0,0 +1,3 @@ +defmodule Mobilizon.Web.PageViewTest do + use Mobilizon.Web.ConnCase, async: true +end From 848691541f1b817a0b96aedd033a06e2dbffc915 Mon Sep 17 00:00:00 2001 From: rustra Date: Sun, 26 Jan 2020 21:44:19 +0100 Subject: [PATCH 4/5] Correct docs modules in mix.exs --- mix.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mix.exs b/mix.exs index 55e31469..c963bd48 100644 --- a/mix.exs +++ b/mix.exs @@ -216,14 +216,14 @@ defmodule Mobilizon.Mixfile do Mobilizon.Federation.ActivityPub.Activity ], APIs: [ - Mobilizon.Web.API.Comments, - Mobilizon.Web.API.Events, - Mobilizon.Web.API.Follows, - Mobilizon.Web.API.Groups, - Mobilizon.Web.API.Participations, - Mobilizon.Web.API.Reports, - Mobilizon.Web.API.Search, - Mobilizon.Web.API.Utils + Mobilizon.GraphQL.API.Comments, + Mobilizon.GraphQL.API.Events, + Mobilizon.GraphQL.API.Follows, + Mobilizon.GraphQL.API.Groups, + Mobilizon.GraphQL.API.Participations, + Mobilizon.GraphQL.API.Reports, + Mobilizon.GraphQL.API.Search, + Mobilizon.GraphQL.API.Utils ], Web: [ Mobilizon.Web, From bc31e2f0c2740a873fe24b4b11fbbf4b1bda892d Mon Sep 17 00:00:00 2001 From: rustra Date: Sun, 26 Jan 2020 21:53:04 +0100 Subject: [PATCH 5/5] Fix `mix format` --- lib/mobilizon/addresses/address.ex | 3 ++- test/federation/web_finger/web_finger_test.exs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/mobilizon/addresses/address.ex b/lib/mobilizon/addresses/address.ex index ce2a7dd4..c7a4f2fd 100644 --- a/lib/mobilizon/addresses/address.ex +++ b/lib/mobilizon/addresses/address.ex @@ -65,7 +65,8 @@ 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, "#{Mobilizon.Web.Endpoint.url()}/address/#{Ecto.UUID.generate()}") put_change(changeset, :url, url) end diff --git a/test/federation/web_finger/web_finger_test.exs b/test/federation/web_finger/web_finger_test.exs index ef786b5d..a995c4d3 100644 --- a/test/federation/web_finger/web_finger_test.exs +++ b/test/federation/web_finger/web_finger_test.exs @@ -33,7 +33,10 @@ defmodule Mobilizon.Federation.WebFingerTest do actor = insert(:actor) {:ok, result} = - WebFinger.webfinger("#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", "JSON") + WebFinger.webfinger( + "#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", + "JSON" + ) assert is_map(result) end
+ <%= gettext "View the report" %>