Allow users to remove their emails if instance does not need email to register
This commit is contained in:
parent
6b1282a829
commit
198250dcef
5 changed files with 95 additions and 6 deletions
|
|
@ -2199,11 +2199,40 @@ defmodule Pleroma.UserTest do
|
|||
[user: insert(:user)]
|
||||
end
|
||||
|
||||
test "blank email returns error", %{user: user} do
|
||||
test "blank email returns error if we require an email on registration", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
|
||||
end
|
||||
|
||||
test "blank email should be fine if we do not require an email on registration", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:ok, %User{email: nil}} = User.change_email(user, "")
|
||||
assert {:ok, %User{email: nil}} = User.change_email(user, nil)
|
||||
end
|
||||
|
||||
test "non unique email returns error", %{user: user} do
|
||||
%{email: email} = insert(:user)
|
||||
|
||||
|
|
@ -2219,6 +2248,25 @@ defmodule Pleroma.UserTest do
|
|||
test "changes email", %{user: user} do
|
||||
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
|
||||
end
|
||||
|
||||
test "adds email", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:ok, _} = User.change_email(user, "")
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
assert {:ok, %User{email: "cofe2@cofe.party"}} = User.change_email(user, "cofe2@cofe.party")
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_cached_by_nickname_or_id" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue