Fully delete users with status :approval_pending
authorAlex Gleason <alex@alexgleason.me>
Fri, 17 Jul 2020 17:19:41 +0000 (12:19 -0500)
committerAlex Gleason <alex@alexgleason.me>
Fri, 17 Jul 2020 17:19:41 +0000 (12:19 -0500)
lib/pleroma/user.ex
test/user_test.exs

index 8e2c9fbe2d9403edfe391d859506b11ef7d5edf8..23288d434307fa744ffa43313a793aa2ddf9bc2d 100644 (file)
@@ -1525,12 +1525,13 @@ defmodule Pleroma.User do
   defp delete_or_deactivate(%User{local: true} = user) do
     status = account_status(user)
 
-    if status == :confirmation_pending do
-      delete_and_invalidate_cache(user)
-    else
-      user
-      |> change(%{deactivated: true, email: nil})
-      |> update_and_set_cache()
+    case status do
+      :confirmation_pending -> delete_and_invalidate_cache(user)
+      :approval_pending -> delete_and_invalidate_cache(user)
+      _ ->
+        user
+        |> change(%{deactivated: true, email: nil})
+        |> update_and_set_cache()
     end
   end
 
index cd39e162323cf63f0e38ab144f417a0f5e2a8617..57cc054af9d734c6d1a512b7838b89a4567a9dda 100644 (file)
@@ -1314,6 +1314,17 @@ defmodule Pleroma.UserTest do
     end
   end
 
+  test "delete/1 when approval is pending deletes the user" do
+    user = insert(:user, approval_pending: true)
+    {:ok, user: user}
+
+    {:ok, job} = User.delete(user)
+    {:ok, _} = ObanHelpers.perform(job)
+
+    refute User.get_cached_by_id(user.id)
+    refute User.get_by_id(user.id)
+  end
+
   test "get_public_key_for_ap_id fetches a user that's not in the db" do
     assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
   end