Move Email context under MobilizonWeb

This commit is contained in:
miffigriffi 2019-09-17 02:45:32 +02:00
parent ac77a7d28a
commit da97c29340
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
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
config :mobilizon, Mobilizon.Storage.Repo,

View file

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

View file

@ -30,7 +30,7 @@ config :mobilizon, Mobilizon.Storage.Repo,
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
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

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 """
Handles emails sent to admins.
"""
use Bamboo.Phoenix, view: Mobilizon.EmailView
use Bamboo.Phoenix, view: MobilizonWeb.EmailView
import Bamboo.{Email, Phoenix}
import MobilizonWeb.Gettext
alias Mobilizon.{Config, Email}
alias Mobilizon.Config
alias Mobilizon.Reports.Report
alias Mobilizon.Users.User
alias MobilizonWeb.Email
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
def report(%User{email: email}, %Report{} = report, locale \\ "en") do
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 """
Mobilizon Mailer.
"""

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,15 +1,19 @@
defmodule MobilizonWeb.Resolvers.UserResolverTest do
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 Mock
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_single_actor_params %{preferred_username: "test2", keys: "yolo"}
@ -503,7 +507,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
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
test "test resend_confirmation_email/3 with invalid email resends an validation email",