Don't sent reset email when user is disabled

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-13 15:21:00 +02:00
parent 53c4f5dfde
commit 71476ee587
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 18 additions and 1 deletions

View file

@ -383,7 +383,7 @@ defmodule Mobilizon.Users do
defp user_by_email_query(email, true) do defp user_by_email_query(email, true) do
from( from(
u in User, u in User,
where: u.email == ^email and not is_nil(u.confirmed_at), where: u.email == ^email and not is_nil(u.confirmed_at) and not u.disabled,
preload: :default_actor preload: :default_actor
) )
end end

View file

@ -757,6 +757,23 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
assert hd(res["errors"])["message"] == assert hd(res["errors"])["message"] ==
"This user can't reset their password" "This user can't reset their password"
end end
test "test send_reset_password/3 for a deactivated user doesn't send email", %{conn: conn} do
{:ok, %User{email: email} = user} =
Users.register(%{email: "toto@tata.tld", password: "p4ssw0rd"})
Users.update_user(user, %{confirmed_at: DateTime.utc_now(), disabled: true})
res =
conn
|> AbsintheHelpers.graphql_query(
query: @send_reset_password_mutation,
variables: %{email: email}
)
assert hd(res["errors"])["message"] ==
"No user with this email was found"
end
end end
describe "Resolver: Reset user's password" do describe "Resolver: Reset user's password" do