diff --git a/config/config.exs b/config/config.exs
index d4996a4bb..64e0bdc0d 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -44,7 +44,7 @@ config :mobilizon, MobilizonWeb.Endpoint,
# Upload configuration
config :mobilizon, MobilizonWeb.Upload,
- uploader: MobilizonWeb.Uploaders.Local,
+ uploader: MobilizonWeb.Upload.Uploader.Local,
filters: [
MobilizonWeb.Upload.Filter.Dedupe,
MobilizonWeb.Upload.Filter.Optimize
@@ -60,7 +60,7 @@ config :mobilizon, MobilizonWeb.Upload,
]
]
-config :mobilizon, MobilizonWeb.Uploaders.Local, uploads: "uploads"
+config :mobilizon, MobilizonWeb.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.Guardian,
+config :mobilizon, MobilizonWeb.Auth.Guardian,
issuer: "mobilizon",
secret_key: "ty0WM7YBE3ojvxoUQxo8AERrNpfbXnIJ82ovkPdqbUFw31T5LcK8wGjaOiReVQjo"
diff --git a/config/dev.exs b/config/dev.exs
index 0ffb389f8..ac5f5a921 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -66,8 +66,8 @@ config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.LocalAdapter
# Configure your database
config :mobilizon, Mobilizon.Storage.Repo,
types: Mobilizon.Storage.PostgresTypes,
- username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "postgres",
- password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "postgres",
+ username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
+ password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_dev",
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
diff --git a/config/test.exs b/config/test.exs
index 15a3fcb77..7a43f0ed3 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -24,8 +24,8 @@ config :logger,
# Configure your database
config :mobilizon, Mobilizon.Storage.Repo,
types: Mobilizon.Storage.PostgresTypes,
- username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "postgres",
- password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "postgres",
+ username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
+ password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_test",
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
pool: Ecto.Adapters.SQL.Sandbox
@@ -34,7 +34,7 @@ config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.TestAdapter
config :mobilizon, MobilizonWeb.Upload, filters: [], link_name: false
-config :mobilizon, MobilizonWeb.Uploaders.Local, uploads: "test/uploads"
+config :mobilizon, MobilizonWeb.Upload.Uploader.Local, uploads: "test/uploads"
config :exvcr,
vcr_cassette_library_dir: "test/fixtures/vcr_cassettes"
diff --git a/lib/federation/activity_pub/transmogrifier.ex b/lib/federation/activity_pub/transmogrifier.ex
index 481fbe88e..21ae9c2db 100644
--- a/lib/federation/activity_pub/transmogrifier.ex
+++ b/lib/federation/activity_pub/transmogrifier.ex
@@ -221,7 +221,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
%{"type" => "Update", "object" => %{"type" => "Event"} = object, "actor" => _actor} =
update_data
) do
- with actor <- Utils.get_actor(update_data),
+ with actor <- Utils.get_actor(update_data),
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
{:ok, %Event{} = old_event} <-
object |> Utils.get_url() |> ActivityPub.fetch_object_from_url(),
@@ -289,7 +289,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
with actor <- Utils.get_actor(data),
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
object_id <- Utils.get_url(object),
- {:origin_check, true} <- {:origin_check, Utils.origin_check_from_id?(actor_url, object_id)},
+ {:origin_check, true} <-
+ {:origin_check, Utils.origin_check_from_id?(actor_url, object_id)},
{:ok, object} <- ActivityPub.fetch_object_from_url(object_id),
{:ok, activity, object} <- ActivityPub.delete(object, false) do
{:ok, activity, object}
diff --git a/lib/federation/activity_stream/converter.ex b/lib/federation/activity_stream/converter/converter.ex
similarity index 100%
rename from lib/federation/activity_stream/converter.ex
rename to lib/federation/activity_stream/converter/converter.ex
diff --git a/lib/mobilizon/admin/action_log.ex b/lib/mobilizon/admin/action_log.ex
index 49e823043..9aa98000d 100644
--- a/lib/mobilizon/admin/action_log.ex
+++ b/lib/mobilizon/admin/action_log.ex
@@ -1,11 +1,3 @@
-import EctoEnum
-
-defenum(Mobilizon.Admin.ActionLogAction, [
- "update",
- "create",
- "delete"
-])
-
defmodule Mobilizon.Admin.ActionLog do
@moduledoc """
Represents an action log entity.
diff --git a/lib/mobilizon/admin/admin.ex b/lib/mobilizon/admin/admin.ex
index 3d162434f..4c76ae217 100644
--- a/lib/mobilizon/admin/admin.ex
+++ b/lib/mobilizon/admin/admin.ex
@@ -4,9 +4,19 @@ defmodule Mobilizon.Admin do
"""
import Ecto.Query
+ import EctoEnum
+ alias Mobilizon.Actors.Actor
+ alias Mobilizon.{Admin, Users}
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Storage.{Page, Repo}
+ alias Mobilizon.Users.User
+
+ defenum(ActionLogAction, [
+ "update",
+ "create",
+ "delete"
+ ])
@doc """
Creates a action_log.
@@ -28,8 +38,37 @@ defmodule Mobilizon.Admin do
|> Repo.all()
end
+ @doc """
+ Log an admin action
+ """
+ @spec log_action(Actor.t(), String.t(), String.t()) :: {:ok, ActionLog.t()}
+ def log_action(%Actor{user_id: user_id, id: actor_id}, action, target) do
+ with %User{role: role} <- Users.get_user!(user_id),
+ {:role, true} <- {:role, role in [:administrator, :moderator]},
+ {:ok, %ActionLog{} = create_action_log} <-
+ Admin.create_action_log(%{
+ "actor_id" => actor_id,
+ "target_type" => to_string(target.__struct__),
+ "target_id" => target.id,
+ "action" => action,
+ "changes" => stringify_struct(target)
+ }) do
+ {:ok, create_action_log}
+ end
+ end
+
@spec list_action_logs_query :: Ecto.Query.t()
defp list_action_logs_query do
from(r in ActionLog, preload: [:actor], order_by: [desc: :id])
end
+
+ defp stringify_struct(%_{} = struct) do
+ association_fields = struct.__struct__.__schema__(:associations)
+
+ struct
+ |> Map.from_struct()
+ |> Map.drop(association_fields ++ [:__meta__])
+ end
+
+ defp stringify_struct(struct), do: struct
end
diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex
index 94bcfef9b..0c277892b 100644
--- a/lib/mobilizon/events/events.ex
+++ b/lib/mobilizon/events/events.ex
@@ -7,10 +7,11 @@ defmodule Mobilizon.Events do
import Ecto.Query
import EctoEnum
- alias Ecto.{Multi, Changeset}
import Mobilizon.Storage.Ecto
+ alias Ecto.{Multi, Changeset}
+
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
@@ -331,14 +332,14 @@ defmodule Mobilizon.Events do
|> Repo.transaction() do
Cachex.del(:ics, "event_#{new_event.uuid}")
- Email.Events.calculate_event_diff_and_send_notifications(
+ Email.Event.calculate_event_diff_and_send_notifications(
old_event,
new_event,
changes
)
unless new_event.draft,
- do: BuildSearch.enqueue(:update_search_event, %{"event_id" => new_event.id})
+ do: Workers.BuildSearch.enqueue(:update_search_event, %{"event_id" => new_event.id})
{:ok, Repo.preload(new_event, @event_preloads)}
end
diff --git a/lib/mobilizon/users/users.ex b/lib/mobilizon/users/users.ex
index 802dc42b2..cb6c3e665 100644
--- a/lib/mobilizon/users/users.ex
+++ b/lib/mobilizon/users/users.ex
@@ -13,6 +13,8 @@ defmodule Mobilizon.Users do
alias Mobilizon.Storage.{Page, Repo}
alias Mobilizon.Users.User
+ alias MobilizonWeb.Auth
+
@type tokens :: %{
required(:access_token) => String.t(),
required(:refresh_token) => String.t()
@@ -247,7 +249,7 @@ defmodule Mobilizon.Users do
@spec generate_access_token(User.t()) :: {:ok, String.t()}
def generate_access_token(user) do
with {:ok, access_token, _claims} <-
- MobilizonWeb.Guardian.encode_and_sign(user, %{}, token_type: "access") do
+ Auth.Guardian.encode_and_sign(user, %{}, token_type: "access") do
{:ok, access_token}
end
end
@@ -258,7 +260,7 @@ defmodule Mobilizon.Users do
@spec generate_refresh_token(User.t()) :: {:ok, String.t()}
def generate_refresh_token(user) do
with {:ok, refresh_token, _claims} <-
- MobilizonWeb.Guardian.encode_and_sign(user, %{}, token_type: "refresh") do
+ Auth.Guardian.encode_and_sign(user, %{}, token_type: "refresh") do
{:ok, refresh_token}
end
end
diff --git a/lib/mobilizon_web/api/reports.ex b/lib/mobilizon_web/api/reports.ex
index 582ae4312..2281f47e4 100644
--- a/lib/mobilizon_web/api/reports.ex
+++ b/lib/mobilizon_web/api/reports.ex
@@ -3,12 +3,10 @@ defmodule MobilizonWeb.API.Reports do
API for Reports.
"""
- import Mobilizon.Service.Admin.ActionLog
-
alias Mobilizon.Actors.Actor
+ alias Mobilizon.{Admin, Users}
alias Mobilizon.Reports, as: ReportsAction
alias Mobilizon.Reports.{Note, Report, ReportStatus}
- alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mobilizon.Federation.ActivityPub
@@ -34,7 +32,7 @@ defmodule MobilizonWeb.API.Reports do
with {:valid_state, true} <-
{:valid_state, ReportStatus.valid_value?(state)},
{:ok, report} <- ReportsAction.update_report(report, %{"status" => state}),
- {:ok, _} <- log_action(actor, "update", report) do
+ {:ok, _} <- Admin.log_action(actor, "update", report) do
{:ok, report}
else
{:valid_state, false} -> {:error, "Unsupported state"}
@@ -58,7 +56,7 @@ defmodule MobilizonWeb.API.Reports do
"moderator_id" => moderator_id,
"content" => content
}),
- {:ok, _} <- log_action(moderator, "create", note) do
+ {:ok, _} <- Admin.log_action(moderator, "create", note) do
{:ok, note}
else
{:role, false} ->
@@ -79,7 +77,7 @@ defmodule MobilizonWeb.API.Reports do
{:role, true} <- {:role, role in [:administrator, :moderator]},
{:ok, %Note{} = note} <-
Mobilizon.Reports.delete_note(note),
- {:ok, _} <- log_action(moderator, "delete", note) do
+ {:ok, _} <- Admin.log_action(moderator, "delete", note) do
{:ok, note}
else
{:role, false} ->
diff --git a/lib/mobilizon_web/context.ex b/lib/mobilizon_web/auth/context.ex
similarity index 82%
rename from lib/mobilizon_web/context.ex
rename to lib/mobilizon_web/auth/context.ex
index 7721162d4..f47ccfa6e 100644
--- a/lib/mobilizon_web/context.ex
+++ b/lib/mobilizon_web/auth/context.ex
@@ -1,10 +1,11 @@
-defmodule MobilizonWeb.Context do
+defmodule MobilizonWeb.Auth.Context do
@moduledoc """
Guardian context for MobilizonWeb
"""
@behaviour Plug
import Plug.Conn
+
alias Mobilizon.Users.User
def init(opts) do
@@ -17,8 +18,7 @@ defmodule MobilizonWeb.Context do
context =
case Guardian.Plug.current_resource(conn) do
%User{} = user ->
- context
- |> Map.put(:current_user, user)
+ Map.put(context, :current_user, user)
nil ->
context
diff --git a/lib/mobilizon_web/auth_error_handler.ex b/lib/mobilizon_web/auth/error_handler.ex
similarity index 83%
rename from lib/mobilizon_web/auth_error_handler.ex
rename to lib/mobilizon_web/auth/error_handler.ex
index 853ff92be..ae7a02824 100644
--- a/lib/mobilizon_web/auth_error_handler.ex
+++ b/lib/mobilizon_web/auth/error_handler.ex
@@ -1,4 +1,4 @@
-defmodule MobilizonWeb.AuthErrorHandler do
+defmodule MobilizonWeb.Auth.ErrorHandler do
@moduledoc """
In case we have an auth error
"""
diff --git a/lib/mobilizon_web/guardian.ex b/lib/mobilizon_web/auth/guardian.ex
similarity index 97%
rename from lib/mobilizon_web/guardian.ex
rename to lib/mobilizon_web/auth/guardian.ex
index 8fd954c6d..225be5a85 100644
--- a/lib/mobilizon_web/guardian.ex
+++ b/lib/mobilizon_web/auth/guardian.ex
@@ -1,7 +1,8 @@
-defmodule MobilizonWeb.Guardian do
+defmodule MobilizonWeb.Auth.Guardian do
@moduledoc """
Handles the JWT tokens encoding and decoding
"""
+
use Guardian,
otp_app: :mobilizon,
permissions: %{
@@ -11,6 +12,7 @@ defmodule MobilizonWeb.Guardian do
alias Mobilizon.Users
alias Mobilizon.Users.User
+
require Logger
def subject_for_token(%User{} = user, _claims) do
diff --git a/lib/mobilizon_web/auth_pipeline.ex b/lib/mobilizon_web/auth/pipeline.ex
similarity index 56%
rename from lib/mobilizon_web/auth_pipeline.ex
rename to lib/mobilizon_web/auth/pipeline.ex
index 1f2a753a0..e8bc59e69 100644
--- a/lib/mobilizon_web/auth_pipeline.ex
+++ b/lib/mobilizon_web/auth/pipeline.ex
@@ -1,14 +1,14 @@
-defmodule MobilizonWeb.AuthPipeline do
+defmodule MobilizonWeb.Auth.Pipeline do
@moduledoc """
Handles the app sessions
"""
use Guardian.Plug.Pipeline,
otp_app: :mobilizon,
- module: MobilizonWeb.Guardian,
- error_handler: MobilizonWeb.AuthErrorHandler
+ module: MobilizonWeb.Auth.Guardian,
+ error_handler: MobilizonWeb.Auth.ErrorHandler
plug(Guardian.Plug.VerifyHeader, realm: "Bearer")
plug(Guardian.Plug.LoadResource, allow_blank: true)
- plug(MobilizonWeb.Context)
+ plug(MobilizonWeb.Auth.Context)
end
diff --git a/lib/mobilizon_web/cache/activity_pub.ex b/lib/mobilizon_web/cache/activity_pub.ex
index d91c1cb17..c73933123 100644
--- a/lib/mobilizon_web/cache/activity_pub.ex
+++ b/lib/mobilizon_web/cache/activity_pub.ex
@@ -1,6 +1,6 @@
defmodule MobilizonWeb.Cache.ActivityPub do
@moduledoc """
- The ActivityPub related functions.
+ ActivityPub related cache.
"""
alias Mobilizon.{Actors, Events, Tombstone}
@@ -9,8 +9,8 @@ defmodule MobilizonWeb.Cache.ActivityPub do
alias Mobilizon.Federation.ActivityPub.Relay
- alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint
+ alias MobilizonWeb.Router.Helpers, as: Routes
@cache :activity_pub
diff --git a/lib/mobilizon_web/cache.ex b/lib/mobilizon_web/cache/cache.ex
similarity index 100%
rename from lib/mobilizon_web/cache.ex
rename to lib/mobilizon_web/cache/cache.ex
diff --git a/lib/mobilizon_web/channels/graphql_socket.ex b/lib/mobilizon_web/channels/graphql_socket.ex
index 72372a663..dc51892e2 100644
--- a/lib/mobilizon_web/channels/graphql_socket.ex
+++ b/lib/mobilizon_web/channels/graphql_socket.ex
@@ -8,7 +8,7 @@ defmodule MobilizonWeb.GraphQLSocket do
def connect(%{"token" => token}, socket) do
with {:ok, authed_socket} <-
- Guardian.Phoenix.Socket.authenticate(socket, MobilizonWeb.Guardian, token),
+ Guardian.Phoenix.Socket.authenticate(socket, MobilizonWeb.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/federation/controllers/activity_pub_controller.ex b/lib/mobilizon_web/controllers/activity_pub_controller.ex
similarity index 95%
rename from lib/federation/controllers/activity_pub_controller.ex
rename to lib/mobilizon_web/controllers/activity_pub_controller.ex
index 2893ab0d4..a7b2407af 100644
--- a/lib/federation/controllers/activity_pub_controller.ex
+++ b/lib/mobilizon_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 Mobilizon.Federation.ActivityPubController do
- use Mobilizon.Federation, :controller
+defmodule MobilizonWeb.ActivityPubController do
+ use MobilizonWeb, :controller
alias Mobilizon.{Actors, Config}
alias Mobilizon.Actors.Actor
@@ -19,7 +19,7 @@ defmodule Mobilizon.Federation.ActivityPubController do
action_fallback(:errors)
- plug(Mobilizon.Federation.Plugs.Federating when action in [:inbox, :relay])
+ plug(MobilizonWeb.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/web_finger_controller.ex b/lib/mobilizon_web/controllers/web_finger_controller.ex
index d831ede32..6e96dc487 100644
--- a/lib/mobilizon_web/controllers/web_finger_controller.ex
+++ b/lib/mobilizon_web/controllers/web_finger_controller.ex
@@ -12,7 +12,7 @@ defmodule MobilizonWeb.WebFingerController do
alias Mobilizon.Federation.WebFinger
- plug(Mobilizon.Federation.Plugs.Federating)
+ plug(MobilizonWeb.Plugs.Federating)
@doc """
Provides /.well-known/host-meta
diff --git a/lib/mobilizon_web/email/user.ex b/lib/mobilizon_web/email/user.ex
index 131cd4f5b..74af18740 100644
--- a/lib/mobilizon_web/email/user.ex
+++ b/lib/mobilizon_web/email/user.ex
@@ -149,9 +149,9 @@ defmodule MobilizonWeb.Email.User do
_ ->
case Timex.before?(
- Timex.shift(Map.get(user, key), hours: 1),
- DateTime.utc_now() |> DateTime.truncate(:second)
- ) do
+ Timex.shift(Map.get(user, key), hours: 1),
+ DateTime.utc_now() |> DateTime.truncate(:second)
+ ) do
true ->
:ok
diff --git a/lib/federation/plugs/federating.ex b/lib/mobilizon_web/plugs/federating.ex
similarity index 92%
rename from lib/federation/plugs/federating.ex
rename to lib/mobilizon_web/plugs/federating.ex
index 8af7f8e91..07dcca734 100644
--- a/lib/federation/plugs/federating.ex
+++ b/lib/mobilizon_web/plugs/federating.ex
@@ -3,7 +3,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Mobilizon.Federation.Plugs.Federating do
+defmodule MobilizonWeb.Plugs.Federating do
@moduledoc """
Restrict ActivityPub routes when not federating
"""
diff --git a/lib/federation/plugs/http_signature.ex b/lib/mobilizon_web/plugs/http_signatures.ex
similarity index 96%
rename from lib/federation/plugs/http_signature.ex
rename to lib/mobilizon_web/plugs/http_signatures.ex
index 1075eba54..1dc669544 100644
--- a/lib/federation/plugs/http_signature.ex
+++ b/lib/mobilizon_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 Mobilizon.Federation.Plugs.HTTPSignatures do
+defmodule MobilizonWeb.Plugs.HTTPSignatures do
@moduledoc """
Plug to check HTTP Signatures on every incoming request
"""
diff --git a/lib/federation/plugs/mapped_signature_to_identity.ex b/lib/mobilizon_web/plugs/mapped_signature_to_identity.ex
similarity index 100%
rename from lib/federation/plugs/mapped_signature_to_identity.ex
rename to lib/mobilizon_web/plugs/mapped_signature_to_identity.ex
diff --git a/lib/mobilizon_web/media_proxy.ex b/lib/mobilizon_web/proxy/media_proxy.ex
similarity index 100%
rename from lib/mobilizon_web/media_proxy.ex
rename to lib/mobilizon_web/proxy/media_proxy.ex
diff --git a/lib/mobilizon_web/reverse_proxy.ex b/lib/mobilizon_web/proxy/reverse_proxy.ex
similarity index 100%
rename from lib/mobilizon_web/reverse_proxy.ex
rename to lib/mobilizon_web/proxy/reverse_proxy.ex
diff --git a/lib/mobilizon_web/resolvers/comment.ex b/lib/mobilizon_web/resolvers/comment.ex
index 094f18d37..0810c3a9c 100644
--- a/lib/mobilizon_web/resolvers/comment.ex
+++ b/lib/mobilizon_web/resolvers/comment.ex
@@ -3,9 +3,7 @@ defmodule MobilizonWeb.Resolvers.Comment do
Handles the comment-related GraphQL calls.
"""
- import Mobilizon.Service.Admin.ActionLog
-
- alias Mobilizon.Actors
+ alias Mobilizon.{Actors, Admin, Events}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Events.Comment, as: CommentModel
@@ -49,7 +47,7 @@ defmodule MobilizonWeb.Resolvers.Comment do
role in [:moderator, :administrator] ->
with {:ok, res} <- do_delete_comment(comment),
%Actor{} = actor <- Actors.get_actor(actor_id) do
- log_action(actor, "delete", comment)
+ Admin.log_action(actor, "delete", comment)
{:ok, res}
end
diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/mobilizon_web/resolvers/event.ex
index 086cdc296..59a0100e8 100644
--- a/lib/mobilizon_web/resolvers/event.ex
+++ b/lib/mobilizon_web/resolvers/event.ex
@@ -3,11 +3,8 @@ defmodule MobilizonWeb.Resolvers.Event do
Handles the event-related GraphQL calls.
"""
- import Mobilizon.Service.Admin.ActionLog
-
- alias Mobilizon.Actors
+ alias Mobilizon.{Actors, Admin, Events}
alias Mobilizon.Actors.Actor
- alias Mobilizon.Events
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
alias Mobilizon.Users.User
@@ -343,7 +340,7 @@ defmodule MobilizonWeb.Resolvers.Event do
role in [:moderator, :administrator] ->
with {:ok, res} <- do_delete_event(event, !is_local),
%Actor{} = actor <- Actors.get_actor(actor_id) do
- log_action(actor, "delete", event)
+ Admin.log_action(actor, "delete", event)
{:ok, res}
end
diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/mobilizon_web/resolvers/user.ex
index 6d09f88db..c9ab7c2b4 100644
--- a/lib/mobilizon_web/resolvers/user.ex
+++ b/lib/mobilizon_web/resolvers/user.ex
@@ -10,7 +10,7 @@ defmodule MobilizonWeb.Resolvers.User do
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User
- alias MobilizonWeb.Email
+ alias MobilizonWeb.{Auth, Email}
require Logger
@@ -94,9 +94,9 @@ defmodule MobilizonWeb.Resolvers.User do
},
_context
) do
- with {:ok, user, _claims} <- MobilizonWeb.Guardian.resource_from_token(refresh_token),
+ with {:ok, user, _claims} <- Auth.Guardian.resource_from_token(refresh_token),
{:ok, _old, {exchanged_token, _claims}} <-
- MobilizonWeb.Guardian.exchange(refresh_token, ["access", "refresh"], "access"),
+ Auth.Guardian.exchange(refresh_token, ["access", "refresh"], "access"),
{:ok, refresh_token} <- Users.generate_refresh_token(user) do
{:ok, %{access_token: exchanged_token, refresh_token: refresh_token}}
else
diff --git a/lib/mobilizon_web/router.ex b/lib/mobilizon_web/router.ex
index 2b92afe32..1f20cf162 100644
--- a/lib/mobilizon_web/router.ex
+++ b/lib/mobilizon_web/router.ex
@@ -6,7 +6,7 @@ defmodule MobilizonWeb.Router do
pipeline :graphql do
# plug(:accepts, ["json"])
- plug(MobilizonWeb.AuthPipeline)
+ plug(MobilizonWeb.Auth.Pipeline)
end
pipeline :well_known do
@@ -14,13 +14,13 @@ defmodule MobilizonWeb.Router do
end
pipeline :activity_pub_signature do
- plug(Mobilizon.Federation.Plugs.HTTPSignatures)
- plug(Mobilizon.Federation.Plugs.MappedSignatureToIdentity)
+ plug(MobilizonWeb.Plugs.HTTPSignatures)
+ plug(MobilizonWeb.Plugs.MappedSignatureToIdentity)
end
pipeline :relay do
- plug(Mobilizon.Federation.Plugs.HTTPSignatures)
- plug(Mobilizon.Federation.Plugs.MappedSignatureToIdentity)
+ plug(MobilizonWeb.Plugs.HTTPSignatures)
+ plug(MobilizonWeb.Plugs.MappedSignatureToIdentity)
plug(:accepts, ["activity-json", "json"])
end
@@ -58,7 +58,7 @@ defmodule MobilizonWeb.Router do
)
end
- forward("/graphiql", Absinthe.Plug.GraphiQL, schema: MobilizonWeb.Schema)
+ ## FEDERATION
scope "/.well-known", MobilizonWeb do
pipe_through(:well_known)
@@ -69,28 +69,6 @@ defmodule MobilizonWeb.Router do
get("/nodeinfo/:version", NodeInfoController, :nodeinfo)
end
- scope "/", MobilizonWeb do
- pipe_through(:atom_and_ical)
-
- get("/@:name/feed/:format", FeedController, :actor)
- get("/events/:uuid/export/:format", FeedController, :event)
- get("/events/going/:token/:format", FeedController, :going)
- end
-
- scope "/", MobilizonWeb do
- pipe_through(:browser)
-
- # Because the "/events/:uuid" route caches all these, we need to force them
- get("/events/create", PageController, :index)
- get("/events/list", PageController, :index)
- get("/events/me", PageController, :index)
- get("/events/explore", PageController, :index)
- get("/events/:uuid/edit", PageController, :index)
-
- # This is a hack to ease link generation into emails
- get("/moderation/reports/:id", PageController, :index, as: "moderation_report")
- end
-
scope "/", MobilizonWeb do
pipe_through(:activity_pub_and_html)
pipe_through(:activity_pub_signature)
@@ -121,6 +99,34 @@ defmodule MobilizonWeb.Router do
post("/inbox", ActivityPubController, :inbox)
end
+ ## FEED
+
+ scope "/", MobilizonWeb do
+ pipe_through(:atom_and_ical)
+
+ get("/@:name/feed/:format", FeedController, :actor)
+ get("/events/:uuid/export/:format", FeedController, :event)
+ get("/events/going/:token/:format", FeedController, :going)
+ end
+
+ ## MOBILIZON
+
+ forward("/graphiql", Absinthe.Plug.GraphiQL, schema: MobilizonWeb.Schema)
+
+ scope "/", MobilizonWeb do
+ pipe_through(:browser)
+
+ # Because the "/events/:uuid" route caches all these, we need to force them
+ get("/events/create", PageController, :index)
+ get("/events/list", PageController, :index)
+ get("/events/me", PageController, :index)
+ get("/events/explore", PageController, :index)
+ get("/events/:uuid/edit", PageController, :index)
+
+ # This is a hack to ease link generation into emails
+ get("/moderation/reports/:id", PageController, :index, as: "moderation_report")
+ end
+
scope "/proxy/", MobilizonWeb do
pipe_through(:remote_media)
diff --git a/lib/mobilizon_web/schema/custom/UUID4.ex b/lib/mobilizon_web/schema/custom/uuid4.ex
similarity index 100%
rename from lib/mobilizon_web/schema/custom/UUID4.ex
rename to lib/mobilizon_web/schema/custom/uuid4.ex
diff --git a/lib/mobilizon_web/upload/filter.ex b/lib/mobilizon_web/upload/filter/filter.ex
similarity index 100%
rename from lib/mobilizon_web/upload/filter.ex
rename to lib/mobilizon_web/upload/filter/filter.ex
diff --git a/lib/mobilizon_web/mime.ex b/lib/mobilizon_web/upload/mime.ex
similarity index 98%
rename from lib/mobilizon_web/mime.ex
rename to lib/mobilizon_web/upload/mime.ex
index ac7ff627f..786c4e7fb 100644
--- a/lib/mobilizon_web/mime.ex
+++ b/lib/mobilizon_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.MIME do
+defmodule MobilizonWeb.Upload.MIME do
@moduledoc """
Returns the mime-type of a binary and optionally a normalized file-name.
"""
diff --git a/lib/mobilizon_web/upload.ex b/lib/mobilizon_web/upload/upload.ex
similarity index 95%
rename from lib/mobilizon_web/upload.ex
rename to lib/mobilizon_web/upload/upload.ex
index 5920ce586..6ddeb2f07 100644
--- a/lib/mobilizon_web/upload.ex
+++ b/lib/mobilizon_web/upload/upload.ex
@@ -27,7 +27,7 @@ defmodule MobilizonWeb.Upload do
Related behaviors:
- * `MobilizonWeb.Uploaders.Uploader`
+ * `MobilizonWeb.Upload.Uploader`
* `MobilizonWeb.Upload.Filter`
"""
@@ -36,7 +36,7 @@ defmodule MobilizonWeb.Upload do
alias Mobilizon.Config
- alias MobilizonWeb.{MIME, Upload, Uploaders}
+ alias MobilizonWeb.Upload.{Filter, MIME, Uploader}
require Logger
@@ -69,8 +69,8 @@ defmodule MobilizonWeb.Upload do
with {:ok, upload} <- prepare_upload(upload, opts),
upload = %__MODULE__{upload | path: upload.path || "#{upload.id}/#{upload.name}"},
- {:ok, upload} <- Upload.Filter.filter(opts.filters, upload),
- {:ok, url_spec} <- Uploaders.Uploader.put_file(opts.uploader, upload) do
+ {:ok, upload} <- Filter.filter(opts.filters, upload),
+ {:ok, url_spec} <- Uploader.put_file(opts.uploader, upload) do
{:ok,
%{
name: Map.get(opts, :description) || upload.name,
@@ -92,7 +92,7 @@ defmodule MobilizonWeb.Upload 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
- Uploaders.Uploader.remove_file(opts.uploader, path)
+ Uploader.remove_file(opts.uploader, path)
else
%URI{} = _uri ->
{:error, "URL doesn't match pattern"}
diff --git a/lib/mobilizon_web/uploaders/local.ex b/lib/mobilizon_web/upload/uploader/local.ex
similarity index 94%
rename from lib/mobilizon_web/uploaders/local.ex
rename to lib/mobilizon_web/upload/uploader/local.ex
index 4e5f0ea99..48ea0eb4e 100644
--- a/lib/mobilizon_web/uploaders/local.ex
+++ b/lib/mobilizon_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.Uploaders.Local do
+defmodule MobilizonWeb.Upload.Uploader.Local do
@moduledoc """
Local uploader for files
"""
- @behaviour MobilizonWeb.Uploaders.Uploader
+ @behaviour MobilizonWeb.Upload.Uploader
alias Mobilizon.Config
diff --git a/lib/mobilizon_web/uploaders/uploader.ex b/lib/mobilizon_web/upload/uploader/uploader.ex
similarity index 98%
rename from lib/mobilizon_web/uploaders/uploader.ex
rename to lib/mobilizon_web/upload/uploader/uploader.ex
index 1f8d0fda4..eb02eecd5 100644
--- a/lib/mobilizon_web/uploaders/uploader.ex
+++ b/lib/mobilizon_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.Uploaders.Uploader do
+defmodule MobilizonWeb.Upload.Uploader do
@moduledoc """
Defines the contract to put and get an uploaded file to any backend.
"""
diff --git a/lib/federation/views/actor_view.ex b/lib/mobilizon_web/views/activity_pub/actor_view.ex
similarity index 100%
rename from lib/federation/views/actor_view.ex
rename to lib/mobilizon_web/views/activity_pub/actor_view.ex
diff --git a/lib/federation/views/object_view.ex b/lib/mobilizon_web/views/activity_pub/object_view.ex
similarity index 100%
rename from lib/federation/views/object_view.ex
rename to lib/mobilizon_web/views/activity_pub/object_view.ex
diff --git a/lib/service/admin/action_log.ex b/lib/service/admin/action_log.ex
deleted file mode 100644
index ebafaad8d..000000000
--- a/lib/service/admin/action_log.ex
+++ /dev/null
@@ -1,39 +0,0 @@
-defmodule Mobilizon.Service.Admin.ActionLog do
- @moduledoc """
- Module to handle action log creations.
- """
-
- alias Mobilizon.Actors.Actor
- alias Mobilizon.{Admin, Users}
- alias Mobilizon.Admin.ActionLog
- alias Mobilizon.Users.User
-
- @doc """
- Log an admin action
- """
- @spec log_action(Actor.t(), String.t(), String.t()) :: {:ok, ActionLog.t()}
- def log_action(%Actor{user_id: user_id, id: actor_id}, action, target) do
- with %User{role: role} <- Users.get_user!(user_id),
- {:role, true} <- {:role, role in [:administrator, :moderator]},
- {:ok, %ActionLog{} = create_action_log} <-
- Admin.create_action_log(%{
- "actor_id" => actor_id,
- "target_type" => to_string(target.__struct__),
- "target_id" => target.id,
- "action" => action,
- "changes" => stringify_struct(target)
- }) do
- {:ok, create_action_log}
- end
- end
-
- defp stringify_struct(%_{} = struct) do
- association_fields = struct.__struct__.__schema__(:associations)
-
- struct
- |> Map.from_struct()
- |> Map.drop(association_fields ++ [:__meta__])
- end
-
- defp stringify_struct(struct), do: struct
-end
diff --git a/lib/service/formatter/html.ex b/lib/service/formatter/html.ex
index 9eccbb217..705411041 100644
--- a/lib/service/formatter/html.ex
+++ b/lib/service/formatter/html.ex
@@ -14,4 +14,3 @@ defmodule Mobilizon.Service.Formatter.HTML do
def filter_tags(html), do: Scrubber.scrub(html, DefaultScrubbler)
end
-
diff --git a/lib/service/workers/helper.ex b/lib/service/workers/helper.ex
index 6f07ac0cc..713eb7095 100644
--- a/lib/service/workers/helper.ex
+++ b/lib/service/workers/helper.ex
@@ -9,6 +9,7 @@ defmodule Mobilizon.Service.Workers.Helper do
"""
alias Mobilizon.Config
+ alias Mobilizon.Service.Workers.Helper
alias Mobilizon.Storage.Repo
def worker_args(queue) do
@@ -40,7 +41,7 @@ defmodule Mobilizon.Service.Workers.Helper do
def enqueue(operation, params, worker_args \\ []) do
params = Map.merge(%{"op" => operation}, params)
queue_atom = String.to_existing_atom(unquote(queue))
- worker_args = worker_args ++ __MODULE__.worker_args(queue_atom)
+ worker_args = worker_args ++ Helper.worker_args(queue_atom)
unquote(caller_module)
|> apply(:new, [params, worker_args])
diff --git a/mix.exs b/mix.exs
index 280cf590f..2d018b403 100644
--- a/mix.exs
+++ b/mix.exs
@@ -181,6 +181,8 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Actors.Member,
Mobilizon.Addresses,
Mobilizon.Addresses.Address,
+ Mobilizon.Admin,
+ Mobilizon.Admin.ActionLog,
Mobilizon.Events,
Mobilizon.Events.Event,
Mobilizon.Events.Comment,
@@ -190,7 +192,7 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Events.Tag,
Mobilizon.Events.TagRelations,
Mobilizon.Events.Track,
- Mobilizon.Event.EventCategory,
+ Mobilizon.Events.EventCategory,
Mobilizon.Events.CommentVisibility,
Mobilizon.Events.EventStatus,
Mobilizon.Events.EventVisibility,
@@ -199,111 +201,184 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Events.Tag.TitleSlug,
Mobilizon.Events.Tag.TitleSlug.Type,
Mobilizon.Events.TagRelation,
+ Mobilizon.Media,
+ Mobilizon.Media.File,
+ Mobilizon.Media.Picture,
+ Mobilizon.Mention,
+ Mobilizon.Reports,
+ Mobilizon.Reports.Note,
+ Mobilizon.Reports.Report,
+ Mobilizon.Share,
+ Mobilizon.Tombstone,
Mobilizon.Users,
Mobilizon.Users.User,
Mobilizon.Users.UserRole,
- Mobilizon.Users.Guards,
- Mobilizon.Storage.Ecto,
- Mobilizon.Storage.Repo,
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
],
Web: [
MobilizonWeb,
- MobilizonWeb.PageView,
+ MobilizonWeb.Endpoint,
MobilizonWeb.Router,
MobilizonWeb.Router.Helpers,
- MobilizonWeb.AuthErrorHandler,
- MobilizonWeb.AuthPipeline,
- MobilizonWeb.Cache,
- MobilizonWeb.ChangesetView,
- MobilizonWeb.Context,
- MobilizonWeb.Endpoint,
- MobilizonWeb.ErrorHelpers,
- MobilizonWeb.ErrorView,
+ MobilizonWeb.Plugs.UploadedMedia,
MobilizonWeb.FallbackController,
MobilizonWeb.FeedController,
- MobilizonWeb.Gettext,
- MobilizonWeb.Guardian,
- MobilizonWeb.Guardian.Plug,
- MobilizonWeb.JsonLD.ObjectView,
+ MobilizonWeb.MediaProxyController,
MobilizonWeb.PageController,
- MobilizonWeb.Uploaders.Avatar,
- MobilizonWeb.Uploaders.Category,
- MobilizonWeb.Uploaders.Category.Type
+ 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
],
Geospatial: [
Mobilizon.Service.Geospatial,
Mobilizon.Service.Geospatial.Addok,
Mobilizon.Service.Geospatial.GoogleMaps,
Mobilizon.Service.Geospatial.MapQuest,
+ Mobilizon.Service.Geospatial.Mimirsbrunn,
Mobilizon.Service.Geospatial.Nominatim,
+ Mobilizon.Service.Geospatial.Pelias,
Mobilizon.Service.Geospatial.Photon,
Mobilizon.Service.Geospatial.Provider
],
+ Localization: [
+ Mobilizon.Cldr,
+ MobilizonWeb.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.Custom.Point,
- MobilizonWeb.Schema.Custom.UUID,
+ 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.Utils,
+ MobilizonWeb.Schema.Custom.Point,
+ MobilizonWeb.Schema.Custom.UUID
],
ActivityPub: [
Mobilizon.Federation.ActivityPub,
+ Mobilizon.Federation.ActivityPub.Audience,
Mobilizon.Federation.ActivityPub.Federator,
+ Mobilizon.Federation.ActivityPub.Relay,
Mobilizon.Federation.ActivityPub.Transmogrifier,
+ Mobilizon.Federation.ActivityPub.Visibility,
Mobilizon.Federation.ActivityPub.Utils,
+ Mobilizon.Federation.ActivityStream.Convertible,
+ Mobilizon.Federation.ActivityStream.Converter,
+ Mobilizon.Federation.ActivityStream.Converter.Actor,
+ Mobilizon.Federation.ActivityStream.Converter.Address,
+ Mobilizon.Federation.ActivityStream.Converter.Comment,
+ Mobilizon.Federation.ActivityStream.Converter.Event,
+ Mobilizon.Federation.ActivityStream.Converter.Flag,
+ Mobilizon.Federation.ActivityStream.Converter.Follower,
+ Mobilizon.Federation.ActivityStream.Converter.Participant,
+ Mobilizon.Federation.ActivityStream.Converter.Picture,
+ Mobilizon.Federation.ActivityStream.Converter.Tombstone,
+ Mobilizon.Federation.ActivityStream.Converter.Utils,
Mobilizon.Federation.HTTPSignatures.Signature,
Mobilizon.Federation.WebFinger,
Mobilizon.Federation.WebFinger.XmlBuilder,
- Mobilizon.Federation.Plugs.HTTPSignatures,
- MobilizonWeb.ActivityPub.ActorView,
- MobilizonWeb.ActivityPub.ObjectView,
+ MobilizonWeb.Plugs.Federating,
+ MobilizonWeb.Plugs.HTTPSignatures,
+ MobilizonWeb.Plugs.MappedSignatureToIdentity,
MobilizonWeb.ActivityPubController,
+ MobilizonWeb.NodeInfoController,
MobilizonWeb.WebFingerController,
- MobilizonWeb.NodeInfoController
+ MobilizonWeb.ActivityPub.ActorView,
+ MobilizonWeb.ActivityPub.ObjectView
],
Services: [
- Mobilizon.Service.EmailChecker,
Mobilizon.Service.Export.Feed,
Mobilizon.Service.Export.ICalendar,
- Mobilizon.Service.Metadata,
Mobilizon.Service.Formatter,
- Mobilizon.Service.Users.Tools
+ Mobilizon.Service.Formatter.HTML,
+ Mobilizon.Service.Formatter.DefaultScrubbler,
+ Mobilizon.Service.Metadata,
+ Mobilizon.Service.Metadata.Actor,
+ Mobilizon.Service.Metadata.Comment,
+ Mobilizon.Service.Metadata.Event,
+ Mobilizon.Service.Metadata.Instance,
+ Mobilizon.Service.Metadata.Utils,
+ Mobilizon.Service.Statistics,
+ Mobilizon.Service.Workers.Background,
+ Mobilizon.Service.Workers.BuildSearch,
+ Mobilizon.Service.Workers.Helper
],
Tools: [
Mobilizon.Application,
+ Mobilizon.Config,
+ Mobilizon.Crypto,
Mobilizon.Factory,
- MobilizonWeb.Email.Mailer,
- MobilizonWeb.Email.User,
- MobilizonWeb.EmailView
+ Mobilizon.Storage.Ecto,
+ Mobilizon.Storage.Page,
+ Mobilizon.Storage.Repo
]
]
end
diff --git a/test/mobilizon/actors/actors_test.exs b/test/mobilizon/actors/actors_test.exs
index a6f1d5828..0d4e5c80a 100644
--- a/test/mobilizon/actors/actors_test.exs
+++ b/test/mobilizon/actors/actors_test.exs
@@ -14,6 +14,8 @@ defmodule Mobilizon.ActorsTest do
alias Mobilizon.Federation.ActivityPub
+ alias MobilizonWeb.Upload.Uploader
+
describe "actors" do
@valid_attrs %{
summary: "some description",
@@ -241,12 +243,12 @@ defmodule Mobilizon.ActorsTest do
%URI{path: "/media/" <> banner_path} = URI.parse(banner_url)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> avatar_path
)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> banner_path
)
@@ -271,12 +273,12 @@ defmodule Mobilizon.ActorsTest do
refute actor.suspended
refute File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> avatar_path
)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> banner_path
)
end
@@ -300,12 +302,12 @@ defmodule Mobilizon.ActorsTest do
%URI{path: "/media/" <> banner_path} = URI.parse(banner_url)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> avatar_path
)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> banner_path
)
@@ -334,12 +336,12 @@ defmodule Mobilizon.ActorsTest do
assert %Tombstone{} = Tombstone.find_tombstone(comment1_url)
refute File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> avatar_path
)
refute File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> banner_path
)
end
diff --git a/test/service/admin/action_log_test.exs b/test/mobilizon/admin/action_log_test.exs
similarity index 88%
rename from test/service/admin/action_log_test.exs
rename to test/mobilizon/admin/action_log_test.exs
index 5b6d61e07..200c54fc1 100644
--- a/test/service/admin/action_log_test.exs
+++ b/test/mobilizon/admin/action_log_test.exs
@@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Admin.ActionLogTest do
use Mobilizon.DataCase
import Mobilizon.Factory
- import Mobilizon.Service.Admin.ActionLog
+ alias Mobilizon.Admin
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Reports.{Note, Report}
@@ -27,7 +27,7 @@ defmodule Mobilizon.Service.Admin.ActionLogTest do
target_id: report_id,
action: :update,
actor: moderator
- }} = log_action(moderator, "update", report)
+ }} = Admin.log_action(moderator, "update", report)
end
test "log the creation of a report note", %{moderator: moderator} do
@@ -40,7 +40,7 @@ defmodule Mobilizon.Service.Admin.ActionLogTest do
target_id: note_id,
action: :create,
actor: moderator
- }} = log_action(moderator, "create", report)
+ }} = Admin.log_action(moderator, "create", report)
end
end
end
diff --git a/test/mobilizon/media/media_test.exs b/test/mobilizon/media/media_test.exs
index 2fb5e3f21..bb16b8b17 100644
--- a/test/mobilizon/media/media_test.exs
+++ b/test/mobilizon/media/media_test.exs
@@ -5,6 +5,8 @@ defmodule Mobilizon.MediaTest do
alias Mobilizon.{Config, Media}
+ alias MobilizonWeb.Upload.Uploader
+
describe "media" do
setup [:ensure_local_uploader]
alias Mobilizon.Media.Picture
@@ -49,7 +51,7 @@ defmodule Mobilizon.MediaTest do
%URI{path: "/media/" <> path} = URI.parse(picture.file.url)
assert File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> path
)
@@ -57,7 +59,7 @@ defmodule Mobilizon.MediaTest do
assert_raise Ecto.NoResultsError, fn -> Media.get_picture!(picture.id) end
refute File.exists?(
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/" <> path
)
end
diff --git a/test/federation/plugs/federating_plug_test.exs b/test/mobilizon_web/plugs/federating_test.exs
similarity index 87%
rename from test/federation/plugs/federating_plug_test.exs
rename to test/mobilizon_web/plugs/federating_test.exs
index 8eaac9f02..9d7045465 100644
--- a/test/federation/plugs/federating_plug_test.exs
+++ b/test/mobilizon_web/plugs/federating_test.exs
@@ -3,10 +3,10 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Mobilizon.Federation.Plug.FederatingTest do
+defmodule MobilizonWeb.Plug.FederatingTest do
use MobilizonWeb.ConnCase
- alias Mobilizon.Federation.Plugs.Federating
+ alias MobilizonWeb.Plugs.Federating
test "returns and halt the conn when federating is disabled" do
Mobilizon.Config.put([:instance, :federating], false)
diff --git a/test/federation/plugs/mapped_identity_to_signature_plug_test.exs b/test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs
similarity index 96%
rename from test/federation/plugs/mapped_identity_to_signature_plug_test.exs
rename to test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs
index 27ab2b6fd..1a24ea866 100644
--- a/test/federation/plugs/mapped_identity_to_signature_plug_test.exs
+++ b/test/mobilizon_web/plugs/mapped_identity_to_signature_test.exs
@@ -3,7 +3,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Mobilizon.Federation.Plugs.MappedSignatureToIdentityTest do
+defmodule MobilizonWeb.Plugs.MappedSignatureToIdentityTest do
use MobilizonWeb.ConnCase
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
diff --git a/test/mobilizon_web/plugs/uploaded_media_plug_test.exs b/test/mobilizon_web/plugs/uploaded_media_test.exs
similarity index 100%
rename from test/mobilizon_web/plugs/uploaded_media_plug_test.exs
rename to test/mobilizon_web/plugs/uploaded_media_test.exs
diff --git a/test/mobilizon_web/media_proxy_test.exs b/test/mobilizon_web/proxy/media_proxy_test.exs
similarity index 100%
rename from test/mobilizon_web/media_proxy_test.exs
rename to test/mobilizon_web/proxy/media_proxy_test.exs
diff --git a/test/mobilizon_web/resolvers/address_resolver_test.exs b/test/mobilizon_web/resolvers/address_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/address_resolver_test.exs
rename to test/mobilizon_web/resolvers/address_test.exs
diff --git a/test/mobilizon_web/resolvers/admin_resolver_test.exs b/test/mobilizon_web/resolvers/admin_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/admin_resolver_test.exs
rename to test/mobilizon_web/resolvers/admin_test.exs
diff --git a/test/mobilizon_web/resolvers/comment_resolver_test.exs b/test/mobilizon_web/resolvers/comment_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/comment_resolver_test.exs
rename to test/mobilizon_web/resolvers/comment_test.exs
diff --git a/test/mobilizon_web/resolvers/config_resolver_test.exs b/test/mobilizon_web/resolvers/config_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/config_resolver_test.exs
rename to test/mobilizon_web/resolvers/config_test.exs
diff --git a/test/mobilizon_web/resolvers/event_resolver_test.exs b/test/mobilizon_web/resolvers/event_test.exs
similarity index 99%
rename from test/mobilizon_web/resolvers/event_resolver_test.exs
rename to test/mobilizon_web/resolvers/event_test.exs
index 44ae7dce0..efa54a9ea 100644
--- a/test/mobilizon_web/resolvers/event_resolver_test.exs
+++ b/test/mobilizon_web/resolvers/event_test.exs
@@ -158,7 +158,11 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event"
{id, ""} = json_response(res, 200)["data"]["createEvent"]["id"] |> Integer.parse()
- assert_enqueued(worker: Workers.BuildSearch, args: %{event_id: id, op: :insert_search_event})
+
+ assert_enqueued(
+ worker: Workers.BuildSearch,
+ args: %{event_id: id, op: :insert_search_event}
+ )
end
test "create_event/3 creates an event and escapes title and description", %{
@@ -204,7 +208,11 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
"My description "
{id, ""} = res["data"]["createEvent"]["id"] |> Integer.parse()
- assert_enqueued(worker: Workers.BuildSearch, args: %{event_id: id, op: :insert_search_event})
+
+ assert_enqueued(
+ worker: Workers.BuildSearch,
+ args: %{event_id: id, op: :insert_search_event}
+ )
end
test "create_event/3 creates an event as a draft", %{conn: conn, actor: actor, user: user} do
diff --git a/test/mobilizon_web/resolvers/feed_token_resolver_test.exs b/test/mobilizon_web/resolvers/feed_token_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/feed_token_resolver_test.exs
rename to test/mobilizon_web/resolvers/feed_token_test.exs
diff --git a/test/mobilizon_web/resolvers/group_resolver_test.exs b/test/mobilizon_web/resolvers/group_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/group_resolver_test.exs
rename to test/mobilizon_web/resolvers/group_test.exs
diff --git a/test/mobilizon_web/resolvers/member_resolver_test.exs b/test/mobilizon_web/resolvers/member_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/member_resolver_test.exs
rename to test/mobilizon_web/resolvers/member_test.exs
diff --git a/test/mobilizon_web/resolvers/participant_resolver_test.exs b/test/mobilizon_web/resolvers/participant_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/participant_resolver_test.exs
rename to test/mobilizon_web/resolvers/participant_test.exs
diff --git a/test/mobilizon_web/resolvers/person_resolver_test.exs b/test/mobilizon_web/resolvers/person_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/person_resolver_test.exs
rename to test/mobilizon_web/resolvers/person_test.exs
diff --git a/test/mobilizon_web/resolvers/picture_resolver_test.exs b/test/mobilizon_web/resolvers/picture_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/picture_resolver_test.exs
rename to test/mobilizon_web/resolvers/picture_test.exs
diff --git a/test/mobilizon_web/resolvers/report_resolver_test.exs b/test/mobilizon_web/resolvers/report_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/report_resolver_test.exs
rename to test/mobilizon_web/resolvers/report_test.exs
diff --git a/test/mobilizon_web/resolvers/search_resolver_test.exs b/test/mobilizon_web/resolvers/search_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/search_resolver_test.exs
rename to test/mobilizon_web/resolvers/search_test.exs
diff --git a/test/mobilizon_web/resolvers/tag_resolver_test.exs b/test/mobilizon_web/resolvers/tag_test.exs
similarity index 100%
rename from test/mobilizon_web/resolvers/tag_resolver_test.exs
rename to test/mobilizon_web/resolvers/tag_test.exs
diff --git a/test/mobilizon_web/resolvers/user_resolver_test.exs b/test/mobilizon_web/resolvers/user_test.exs
similarity index 95%
rename from test/mobilizon_web/resolvers/user_resolver_test.exs
rename to test/mobilizon_web/resolvers/user_test.exs
index 643b714ae..e0dd8194f 100644
--- a/test/mobilizon_web/resolvers/user_resolver_test.exs
+++ b/test/mobilizon_web/resolvers/user_test.exs
@@ -5,10 +5,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
use Bamboo.Test
- alias Mobilizon.{Actors, Users}
+ alias Mobilizon.{Actors, Config, Users}
alias Mobilizon.Actors.Actor
- alias Mobilizon.Service.Users.ResetPassword
- alias Mobilizon.Users
alias Mobilizon.Users.User
alias MobilizonWeb.{AbsintheHelpers, Email}
@@ -321,8 +319,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
end
test "create_user/3 doesn't allow registration when registration is closed", %{conn: conn} do
- Mobilizon.Config.put([:instance, :registrations_open], false)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], [])
+ Config.put([:instance, :registrations_open], false)
+ Config.put([:instance, :registration_email_whitelist], [])
mutation = """
mutation createUser($email: String!, $password: String!) {
@@ -344,14 +342,14 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
)
assert hd(res["errors"])["message"] == "Registrations are not enabled"
- Mobilizon.Config.put([:instance, :registrations_open], true)
+ Config.put([:instance, :registrations_open], true)
end
test "create_user/3 doesn't allow registration when user email is not on the whitelist", %{
conn: conn
} do
- Mobilizon.Config.put([:instance, :registrations_open], false)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], ["random.org"])
+ Config.put([:instance, :registrations_open], false)
+ Config.put([:instance, :registration_email_whitelist], ["random.org"])
mutation = """
mutation createUser($email: String!, $password: String!) {
@@ -373,15 +371,15 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
)
assert hd(res["errors"])["message"] == "Your email is not on the whitelist"
- Mobilizon.Config.put([:instance, :registrations_open], true)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], [])
+ Config.put([:instance, :registrations_open], true)
+ Config.put([:instance, :registration_email_whitelist], [])
end
test "create_user/3 allows registration when user email domain is on the whitelist", %{
conn: conn
} do
- Mobilizon.Config.put([:instance, :registrations_open], false)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], ["demo.tld"])
+ Config.put([:instance, :registrations_open], false)
+ Config.put([:instance, :registration_email_whitelist], ["demo.tld"])
mutation = """
mutation createUser($email: String!, $password: String!) {
@@ -404,13 +402,13 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
refute res["errors"]
assert res["data"]["createUser"]["email"] == @user_creation.email
- Mobilizon.Config.put([:instance, :registrations_open], true)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], [])
+ Config.put([:instance, :registrations_open], true)
+ Config.put([:instance, :registration_email_whitelist], [])
end
test "create_user/3 allows registration when user email is on the whitelist", %{conn: conn} do
- Mobilizon.Config.put([:instance, :registrations_open], false)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], [@user_creation.email])
+ Config.put([:instance, :registrations_open], false)
+ Config.put([:instance, :registration_email_whitelist], [@user_creation.email])
mutation = """
mutation createUser($email: String!, $password: String!) {
@@ -433,8 +431,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
refute res["errors"]
assert res["data"]["createUser"]["email"] == @user_creation.email
- Mobilizon.Config.put([:instance, :registrations_open], true)
- Mobilizon.Config.put([:instance, :registration_email_whitelist], [])
+ Config.put([:instance, :registrations_open], true)
+ Config.put([:instance, :registration_email_whitelist], [])
end
test "register_person/3 doesn't register a profile from an unknown email", context do
@@ -637,7 +635,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
"You requested again a confirmation email too soon"
# Hammer time !
- Mobilizon.Users.update_user(user, %{
+ Users.update_user(user, %{
confirmation_sent_at: Timex.shift(user.confirmation_sent_at, hours: -3)
})
@@ -709,8 +707,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
test "test reset_password/3 with valid email", context do
{:ok, %User{} = user} = Users.register(%{email: "toto@tata.tld", password: "p4ssw0rd"})
%Actor{} = insert(:actor, user: user)
- {:ok, _email_sent} = ResetPassword.send_password_reset_email(user)
- %User{reset_password_token: reset_password_token} = Mobilizon.Users.get_user!(user.id)
+ {:ok, _email_sent} = Email.User.send_password_reset_email(user)
+ %User{reset_password_token: reset_password_token} = Users.get_user!(user.id)
mutation = """
mutation {
@@ -734,8 +732,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
test "test reset_password/3 with a password too short", context do
%User{} = user = insert(:user)
- {:ok, _email_sent} = ResetPassword.send_password_reset_email(user)
- %User{reset_password_token: reset_password_token} = Mobilizon.Users.get_user!(user.id)
+ {:ok, _email_sent} = Email.User.send_password_reset_email(user)
+ %User{reset_password_token: reset_password_token} = Users.get_user!(user.id)
mutation = """
mutation {
@@ -760,8 +758,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
test "test reset_password/3 with an invalid token", context do
%User{} = user = insert(:user)
- {:ok, _email_sent} = ResetPassword.send_password_reset_email(user)
- %User{} = Mobilizon.Users.get_user!(user.id)
+ {:ok, _email_sent} = Email.User.send_password_reset_email(user)
+ %User{} = Users.get_user!(user.id)
mutation = """
mutation {
diff --git a/test/mobilizon_web/upload_test.exs b/test/mobilizon_web/upload/upload_test.exs
similarity index 97%
rename from test/mobilizon_web/upload_test.exs
rename to test/mobilizon_web/upload/upload_test.exs
index c5553adcb..78f2187ed 100644
--- a/test/mobilizon_web/upload_test.exs
+++ b/test/mobilizon_web/upload/upload_test.exs
@@ -9,6 +9,7 @@ defmodule Mobilizon.UploadTest do
alias Mobilizon.Config
alias MobilizonWeb.Upload
+ alias MobilizonWeb.Upload.Uploader
describe "Storing a file with the Local uploader" do
setup [:ensure_local_uploader]
@@ -184,7 +185,7 @@ defmodule Mobilizon.UploadTest do
test "delete a not existing file" do
file =
- Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <>
+ Config.get!([Uploader.Local, :uploads]) <>
"/not_existing/definitely.jpg"
refute File.exists?(file)
@@ -214,6 +215,6 @@ defmodule Mobilizon.UploadTest do
assert String.starts_with?(url, MobilizonWeb.Endpoint.url() <> "/media/")
%URI{path: "/media/" <> path} = URI.parse(url)
- {Config.get!([MobilizonWeb.Uploaders.Local, :uploads]) <> "/" <> path, url}
+ {Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url}
end
end
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 4c10b2d58..18685ea98 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -30,7 +30,7 @@ defmodule MobilizonWeb.ConnCase do
@endpoint MobilizonWeb.Endpoint
def auth_conn(%Plug.Conn{} = conn, %User{} = user) do
- {:ok, token, _claims} = MobilizonWeb.Guardian.encode_and_sign(user)
+ {:ok, token, _claims} = MobilizonWeb.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 30d0d2609..886ef2e29 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -19,6 +19,9 @@ defmodule Mobilizon.DataCase do
alias Mobilizon.Config
alias Mobilizon.Storage.Repo
+ alias MobilizonWeb.Upload
+ alias MobilizonWeb.Upload.Uploader
+
using do
quote do
alias Mobilizon.Storage.Repo
@@ -55,16 +58,16 @@ defmodule Mobilizon.DataCase do
end
def ensure_local_uploader(_context) do
- uploader = Config.get([MobilizonWeb.Upload, :uploader])
- filters = Config.get([MobilizonWeb.Upload, :filters])
+ uploader = Config.get([Upload, :uploader])
+ filters = Config.get([Upload, :filters])
- unless uploader == MobilizonWeb.Uploaders.Local || filters != [] do
- Config.put([MobilizonWeb.Upload, :uploader], MobilizonWeb.Uploaders.Local)
- Config.put([MobilizonWeb.Upload, :filters], [])
+ unless uploader == Uploader.Local || filters != [] do
+ Config.put([Upload, :uploader], Uploader.Local)
+ Config.put([Upload, :filters], [])
on_exit(fn ->
- Config.put([MobilizonWeb.Upload, :uploader], uploader)
- Config.put([MobilizonWeb.Upload, :filters], filters)
+ Config.put([Upload, :uploader], uploader)
+ Config.put([Upload, :filters], filters)
end)
end
diff --git a/test/tasks/users_test.exs b/test/tasks/users_test.exs
index 812666c90..d5165405f 100644
--- a/test/tasks/users_test.exs
+++ b/test/tasks/users_test.exs
@@ -1,10 +1,11 @@
defmodule Mix.Tasks.Mobilizon.UsersTest do
use Mobilizon.DataCase
+ import Mobilizon.Factory
+
alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mix.Tasks.Mobilizon.Users.{New, Delete, Show, Modify}
- import Mobilizon.Factory
Mix.shell(Mix.Shell.Process)