Move admin approval email logic into User.post_register_action/1

This commit is contained in:
Alex Gleason 2020-10-11 21:44:22 -05:00
parent 521e965884
commit bb8c0614ef
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 14 deletions

View File

@ -779,11 +779,20 @@ defmodule Pleroma.User do
end end
def post_register_action(%User{approval_pending: true} = user) do def post_register_action(%User{approval_pending: true} = user) do
# Send approval pending email # Send approval pending email to user
user user
|> Pleroma.Emails.UserEmail.approval_pending_email() |> Pleroma.Emails.UserEmail.approval_pending_email()
|> Pleroma.Emails.Mailer.deliver_async() |> Pleroma.Emails.Mailer.deliver_async()
# Notify admins
all_superusers()
|> Enum.filter(fn user -> not is_nil(user.email) end)
|> Enum.each(fn superuser ->
superuser
|> Pleroma.Emails.AdminEmail.new_unapproved_registration(user)
|> Pleroma.Emails.Mailer.deliver_async()
end)
{:ok, user} {:ok, user}
end end

View File

@ -45,7 +45,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
case User.register(changeset) do case User.register(changeset) do
{:ok, user} -> {:ok, user} ->
maybe_notify_admins(user)
{:ok, user} {:ok, user}
{:error, changeset} -> {:error, changeset} ->
@ -58,18 +57,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
end end
end end
defp maybe_notify_admins(%User{} = account) do
if Pleroma.Config.get([:instance, :account_approval_required]) do
User.all_superusers()
|> Enum.filter(fn user -> not is_nil(user.email) end)
|> Enum.each(fn superuser ->
superuser
|> Pleroma.Emails.AdminEmail.new_unapproved_registration(account)
|> Pleroma.Emails.Mailer.deliver_async()
end)
end
end
def password_reset(nickname_or_email) do def password_reset(nickname_or_email) do
with true <- is_binary(nickname_or_email), with true <- is_binary(nickname_or_email),
%User{local: true, email: email, deactivated: false} = user when is_binary(email) <- %User{local: true, email: email, deactivated: false} = user when is_binary(email) <-