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)
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 ->
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)
end
end
+ def confirm(%User{} = user), do: {:ok, user}
+
def update_notification_settings(%User{} = user, settings) do
user
|> cast(%{notification_settings: settings}, [])
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
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