summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2021-05-04 13:30:00 +0000
committerfeld <feld@feld.me>2021-05-04 13:30:00 +0000
commit745375bdcf2679ff803dd4ebc4a8313a7b5fb157 (patch)
tree0b0c6996a0a1bea713851f53489e496e0087a0ab
parentd5263bfcf37cb1f6190d0848c6b417d33d8fb979 (diff)
parent90770e0841d3ffea87627b35627bfe38cad52f07 (diff)
Merge branch 'dont-crash-email-settings' into 'develop'
Don't crash so hard when email settings are invalid Closes #2606 See merge request pleroma/pleroma!3400
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/pleroma/application_requirements.ex38
-rw-r--r--test/pleroma/application_requirements_test.exs18
-rw-r--r--test/pleroma/user_test.exs18
4 files changed, 50 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ed6e548dd..5bb4b1e73 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- MRF (`FollowBotPolicy`): New MRF Policy which makes a designated local Bot account attempt to follow all users in public Notes received by your instance. Users who require approving follower requests or have #nobot in their profile are excluded.
- Return OAuth token `id` (primary key) in POST `/oauth/token`.
+### Fixed
+- Don't crash so hard when email settings are invalid.
+
## Unreleased (Patch)
### Fixed
diff --git a/lib/pleroma/application_requirements.ex b/lib/pleroma/application_requirements.ex
index 6ef65b263..c412dec5e 100644
--- a/lib/pleroma/application_requirements.ex
+++ b/lib/pleroma/application_requirements.ex
@@ -34,15 +34,16 @@ defmodule Pleroma.ApplicationRequirements do
defp check_welcome_message_config!(:ok) do
if Pleroma.Config.get([:welcome, :email, :enabled], false) and
not Pleroma.Emails.Mailer.enabled?() do
- Logger.error("""
- To send welcome email do you need to enable mail.
- \nconfig :pleroma, Pleroma.Emails.Mailer, enabled: true
- """)
+ Logger.warn("""
+ To send welcome emails, you need to enable the mailer.
+ Welcome emails will NOT be sent with the current config.
- {:error, "The mail disabled."}
- else
- :ok
+ Enable the mailer:
+ config :pleroma, Pleroma.Emails.Mailer, enabled: true
+ """)
end
+
+ :ok
end
defp check_welcome_message_config!(result), do: result
@@ -51,18 +52,21 @@ defmodule Pleroma.ApplicationRequirements do
#
def check_confirmation_accounts!(:ok) do
if Pleroma.Config.get([:instance, :account_activation_required]) &&
- not Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled]) do
- Logger.error(
- "Account activation enabled, but no Mailer settings enabled.\n" <>
- "Please set config :pleroma, :instance, account_activation_required: false\n" <>
- "Otherwise setup and enable Mailer."
- )
+ not Pleroma.Emails.Mailer.enabled?() do
+ Logger.warn("""
+ Account activation is required, but the mailer is disabled.
+ Users will NOT be able to confirm their accounts with this config.
+ Either disable account activation or enable the mailer.
- {:error,
- "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails."}
- else
- :ok
+ Disable account activation:
+ config :pleroma, :instance, account_activation_required: false
+
+ Enable the mailer:
+ config :pleroma, Pleroma.Emails.Mailer, enabled: true
+ """)
end
+
+ :ok
end
def check_confirmation_accounts!(result), do: result
diff --git a/test/pleroma/application_requirements_test.exs b/test/pleroma/application_requirements_test.exs
index 683ac8c96..a54c37968 100644
--- a/test/pleroma/application_requirements_test.exs
+++ b/test/pleroma/application_requirements_test.exs
@@ -35,13 +35,13 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:welcome])
setup do: clear_config([Pleroma.Emails.Mailer])
- test "raises if welcome email enabled but mail disabled" do
+ test "warns if welcome email enabled but mail disabled" do
clear_config([:welcome, :email, :enabled], true)
clear_config([Pleroma.Emails.Mailer, :enabled], false)
- assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
- capture_log(&Pleroma.ApplicationRequirements.verify!/0)
- end
+ assert capture_log(fn ->
+ assert Pleroma.ApplicationRequirements.verify!() == :ok
+ end) =~ "Welcome emails will NOT be sent"
end
end
@@ -57,15 +57,13 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:instance, :account_activation_required])
- test "raises if account confirmation is required but mailer isn't enable" do
+ test "warns if account confirmation is required but mailer isn't enabled" do
clear_config([:instance, :account_activation_required], true)
clear_config([Pleroma.Emails.Mailer, :enabled], false)
- assert_raise Pleroma.ApplicationRequirements.VerifyError,
- "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
- fn ->
- capture_log(&Pleroma.ApplicationRequirements.verify!/0)
- end
+ assert capture_log(fn ->
+ assert Pleroma.ApplicationRequirements.verify!() == :ok
+ end) =~ "Users will NOT be able to confirm their accounts"
end
test "doesn't do anything if account confirmation is disabled" do
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index d81c1b8eb..c6b631499 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -572,6 +572,24 @@ defmodule Pleroma.UserTest do
)
end
+ test "it fails gracefully with invalid email config" do
+ cng = User.register_changeset(%User{}, @full_user_data)
+
+ # Disable the mailer but enable all the things that want to send emails
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_approval_required], true)
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], "lain@lain.com")
+
+ # The user is still created
+ assert {:ok, %User{nickname: "nick"}} = User.register(cng)
+
+ # No emails are sent
+ ObanHelpers.perform_all()
+ refute_email_sent()
+ end
+
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
clear_config([:instance, :account_activation_required], true)