Make User.confirm/1 and User.approve/1 idempotent
This commit is contained in:
parent
6ebec50df6
commit
cb29769a22
2 changed files with 26 additions and 2 deletions
|
@ -1590,7 +1590,7 @@ defmodule Pleroma.User do
|
|||
end)
|
||||
end
|
||||
|
||||
def approve(%User{} = user) do
|
||||
def approve(%User{approval_pending: true} = user) do
|
||||
with chg <- change(user, approval_pending: false),
|
||||
{:ok, user} <- update_and_set_cache(chg) do
|
||||
post_register_action(user)
|
||||
|
@ -1598,6 +1598,8 @@ defmodule Pleroma.User do
|
|||
end
|
||||
end
|
||||
|
||||
def approve(%User{} = user), do: {:ok, user}
|
||||
|
||||
def confirm(users) when is_list(users) do
|
||||
Repo.transaction(fn ->
|
||||
Enum.map(users, fn user ->
|
||||
|
@ -1606,7 +1608,7 @@ defmodule Pleroma.User do
|
|||
end)
|
||||
end
|
||||
|
||||
def confirm(%User{} = user) do
|
||||
def confirm(%User{confirmation_pending: true} = user) do
|
||||
with chg <- confirmation_changeset(user, need_confirmation: false),
|
||||
{:ok, user} <- update_and_set_cache(chg) do
|
||||
post_register_action(user)
|
||||
|
@ -1614,6 +1616,8 @@ defmodule Pleroma.User do
|
|||
end
|
||||
end
|
||||
|
||||
def confirm(%User{} = user), do: {:ok, user}
|
||||
|
||||
def update_notification_settings(%User{} = user, settings) do
|
||||
user
|
||||
|> cast(%{notification_settings: settings}, [])
|
||||
|
|
|
@ -1371,6 +1371,17 @@ defmodule Pleroma.UserTest do
|
|||
html_body: "Welcome to #{instance_name}"
|
||||
)
|
||||
end
|
||||
|
||||
test "approving an approved user does not trigger post-register actions" do
|
||||
clear_config([:welcome, :email, :enabled], true)
|
||||
|
||||
user = insert(:user, approval_pending: false)
|
||||
User.approve(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_no_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
describe "confirm" do
|
||||
|
@ -1424,6 +1435,15 @@ defmodule Pleroma.UserTest do
|
|||
html_body: admin_email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "confirming a confirmed user does not trigger post-register actions" do
|
||||
user = insert(:user, confirmation_pending: false, approval_pending: true)
|
||||
User.confirm(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_no_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete" do
|
||||
|
|
Loading…
Reference in a new issue