From db9195665b0994e9a6fd36a5dec02fa24e5ee14b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 13 Oct 2020 15:21:00 +0200 Subject: [PATCH] Don't sent reset email when user is disabled Signed-off-by: Thomas Citharel --- lib/mobilizon/users/users.ex | 2 +- test/graphql/resolvers/user_test.exs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/mobilizon/users/users.ex b/lib/mobilizon/users/users.ex index d4c02aa93..458cb227e 100644 --- a/lib/mobilizon/users/users.ex +++ b/lib/mobilizon/users/users.ex @@ -383,7 +383,7 @@ defmodule Mobilizon.Users do defp user_by_email_query(email, true) do from( 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 ) end diff --git a/test/graphql/resolvers/user_test.exs b/test/graphql/resolvers/user_test.exs index d989a4b42..0f3dd5cd1 100644 --- a/test/graphql/resolvers/user_test.exs +++ b/test/graphql/resolvers/user_test.exs @@ -757,6 +757,23 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do assert hd(res["errors"])["message"] == "This user can't reset their password" 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 describe "Resolver: Reset user's password" do