Move Email context under MobilizonWeb

This commit is contained in:
miffigriffi 2019-09-17 02:45:32 +02:00
parent 5f30334bcb
commit c23c00e1c8
14 changed files with 57 additions and 49 deletions

View File

@ -61,7 +61,7 @@ config :phoenix, :stacktrace_depth, 20
# Initialize plugs at runtime for faster development compilation # Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime config :phoenix, :plug_init_mode, :runtime
config :mobilizon, Mobilizon.Email.Mailer, adapter: Bamboo.LocalAdapter config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.LocalAdapter
# Configure your database # Configure your database
config :mobilizon, Mobilizon.Storage.Repo, config :mobilizon, Mobilizon.Storage.Repo,

View File

@ -21,7 +21,7 @@ config :mobilizon, Mobilizon.Storage.Repo,
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432", port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
pool_size: 15 pool_size: 15
config :mobilizon, Mobilizon.Email.Mailer, config :mobilizon, MobilizonWeb.Email.Mailer,
adapter: Bamboo.SMTPAdapter, adapter: Bamboo.SMTPAdapter,
server: "localhost", server: "localhost",
hostname: "localhost", hostname: "localhost",

View File

@ -30,7 +30,7 @@ config :mobilizon, Mobilizon.Storage.Repo,
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost", hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
pool: Ecto.Adapters.SQL.Sandbox pool: Ecto.Adapters.SQL.Sandbox
config :mobilizon, Mobilizon.Email.Mailer, adapter: Bamboo.TestAdapter config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.TestAdapter
config :mobilizon, MobilizonWeb.Upload, filters: [], link_name: false config :mobilizon, MobilizonWeb.Upload, filters: [], link_name: false

View File

@ -1,17 +0,0 @@
defmodule Mobilizon.Email do
@moduledoc """
The Email context.
"""
use Bamboo.Phoenix, view: Mobilizon.EmailView
alias Mobilizon.Config
@spec base_email :: Bamboo.Email.t()
def base_email do
new_email()
|> from(Config.instance_email_from())
|> put_html_layout({Mobilizon.EmailView, "email.html"})
|> put_text_layout({Mobilizon.EmailView, "email.text"})
end
end

View File

@ -1,18 +1,20 @@
defmodule Mobilizon.Email.Admin do defmodule MobilizonWeb.Email.Admin do
@moduledoc """ @moduledoc """
Handles emails sent to admins. Handles emails sent to admins.
""" """
use Bamboo.Phoenix, view: Mobilizon.EmailView use Bamboo.Phoenix, view: MobilizonWeb.EmailView
import Bamboo.{Email, Phoenix} import Bamboo.{Email, Phoenix}
import MobilizonWeb.Gettext import MobilizonWeb.Gettext
alias Mobilizon.{Config, Email} alias Mobilizon.Config
alias Mobilizon.Reports.Report alias Mobilizon.Reports.Report
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias MobilizonWeb.Email
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t() @spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
def report(%User{email: email}, %Report{} = report, locale \\ "en") do def report(%User{email: email}, %Report{} = report, locale \\ "en") do
Gettext.put_locale(locale) Gettext.put_locale(locale)

View File

@ -0,0 +1,17 @@
defmodule MobilizonWeb.Email do
@moduledoc """
The Email context.
"""
use Bamboo.Phoenix, view: MobilizonWeb.EmailView
alias Mobilizon.Config
@spec base_email :: Bamboo.Email.t()
def base_email do
new_email()
|> from(Config.instance_email_from())
|> put_html_layout({MobilizonWeb.EmailView, "email.html"})
|> put_text_layout({MobilizonWeb.EmailView, "email.text"})
end
end

View File

@ -1,4 +1,4 @@
defmodule Mobilizon.Email.Mailer do defmodule MobilizonWeb.Email.Mailer do
@moduledoc """ @moduledoc """
Mobilizon Mailer. Mobilizon Mailer.
""" """

View File

@ -1,17 +1,19 @@
defmodule Mobilizon.Email.User do defmodule MobilizonWeb.Email.User do
@moduledoc """ @moduledoc """
Handles emails sent to users. Handles emails sent to users.
""" """
use Bamboo.Phoenix, view: Mobilizon.EmailView use Bamboo.Phoenix, view: MobilizonWeb.EmailView
import Bamboo.{Email, Phoenix} import Bamboo.{Email, Phoenix}
import MobilizonWeb.Gettext import MobilizonWeb.Gettext
alias Mobilizon.{Config, Email} alias Mobilizon.Config
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias MobilizonWeb.Email
@spec confirmation_email(User.t(), String.t()) :: Bamboo.Email.t() @spec confirmation_email(User.t(), String.t()) :: Bamboo.Email.t()
def confirmation_email( def confirmation_email(
%User{email: email, confirmation_token: confirmation_token}, %User{email: email, confirmation_token: confirmation_token},

View File

@ -1,3 +1,3 @@
defmodule Mobilizon.EmailView do defmodule MobilizonWeb.EmailView do
use MobilizonWeb, :view use MobilizonWeb, :view
end end

View File

@ -25,8 +25,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Mobilizon.Users alias Mobilizon.Users
alias MobilizonWeb.{Email, Endpoint}
alias MobilizonWeb.Router.Helpers, as: Routes alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint
require Logger require Logger
@ -165,8 +165,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
{:ok, %Report{} = report} <- Reports.create_report(data) do {:ok, %Report{} = report} <- Reports.create_report(data) do
Enum.each(Users.list_moderators(), fn moderator -> Enum.each(Users.list_moderators(), fn moderator ->
moderator moderator
|> Mobilizon.Email.Admin.report(moderator, report) |> Email.Admin.report(moderator, report)
|> Mobilizon.Email.Mailer.deliver_later() |> Email.Mailer.deliver_later()
end) end)
{:ok, report} {:ok, report}

View File

@ -1,12 +1,12 @@
defmodule Mobilizon.Service.Users.Activation do defmodule Mobilizon.Service.Users.Activation do
@moduledoc false @moduledoc false
alias Mobilizon.Email.Mailer
alias Mobilizon.Email.User, as: UserEmail
alias Mobilizon.Users alias Mobilizon.Users
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.Service.Users.Tools alias Mobilizon.Service.Users.Tools
alias MobilizonWeb.Email
require Logger require Logger
@doc false @doc false
@ -40,7 +40,7 @@ defmodule Mobilizon.Service.Users.Activation do
def send_confirmation_email(%User{} = user, locale \\ "en") do def send_confirmation_email(%User{} = user, locale \\ "en") do
user user
|> UserEmail.confirmation_email(locale) |> Email.User.confirmation_email(locale)
|> Mailer.deliver_later() |> Email.Mailer.deliver_later()
end end
end end

View File

@ -1,13 +1,13 @@
defmodule Mobilizon.Service.Users.ResetPassword do defmodule Mobilizon.Service.Users.ResetPassword do
@moduledoc false @moduledoc false
alias Mobilizon.Email.Mailer
alias Mobilizon.Email.User, as: UserEmail
alias Mobilizon.Service.Users.Tools alias Mobilizon.Service.Users.Tools
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Mobilizon.Users alias Mobilizon.Users
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias MobilizonWeb.Email
require Logger require Logger
@doc """ @doc """
@ -51,8 +51,8 @@ defmodule Mobilizon.Service.Users.ResetPassword do
) do ) do
mail = mail =
user_updated user_updated
|> UserEmail.reset_password_email(locale) |> Email.User.reset_password_email(locale)
|> Mailer.deliver_later() |> Email.Mailer.deliver_later()
{:ok, mail} {:ok, mail}
else else

View File

@ -315,9 +315,9 @@ defmodule Mobilizon.Mixfile do
Tools: [ Tools: [
Mobilizon.Application, Mobilizon.Application,
Mobilizon.Factory, Mobilizon.Factory,
Mobilizon.Email.Mailer, MobilizonWeb.Email.Mailer,
Mobilizon.EmailView, MobilizonWeb.Email.User,
Mobilizon.Email.User MobilizonWeb.EmailView
] ]
] ]
end end

View File

@ -1,15 +1,19 @@
defmodule MobilizonWeb.Resolvers.UserResolverTest do defmodule MobilizonWeb.Resolvers.UserResolverTest do
use MobilizonWeb.ConnCase use MobilizonWeb.ConnCase
alias Mobilizon.{Actors, Config, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
alias Mobilizon.Users
alias MobilizonWeb.AbsintheHelpers
alias Mobilizon.Service.Users.ResetPassword
import Mobilizon.Factory import Mobilizon.Factory
import Mock import Mock
use Bamboo.Test use Bamboo.Test
alias Mobilizon.{Actors, Config, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Users.ResetPassword
alias Mobilizon.Users.User
alias Mobilizon.Users
alias MobilizonWeb.{AbsintheHelpers, Email}
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"} @valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
@valid_single_actor_params %{preferred_username: "test2", keys: "yolo"} @valid_single_actor_params %{preferred_username: "test2", keys: "yolo"}
@ -503,7 +507,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["data"]["resendConfirmationEmail"] == user.email assert json_response(res, 200)["data"]["resendConfirmationEmail"] == user.email
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user)) assert_delivered_email(Email.User.confirmation_email(user))
end end
test "test resend_confirmation_email/3 with invalid email resends an validation email", test "test resend_confirmation_email/3 with invalid email resends an validation email",