Delete pending follow requests on user deletion
authorSergey Suprunenko <suprunenko.s@gmail.com>
Sun, 7 Jun 2020 15:31:37 +0000 (17:31 +0200)
committerSergey Suprunenko <suprunenko.s@gmail.com>
Sun, 7 Jun 2020 15:31:37 +0000 (17:31 +0200)
lib/pleroma/following_relationship.ex
lib/pleroma/user.ex
test/user_test.exs

index 3a3082e728037e265bc56a55883f8df7f5e36fe9..093b1f4050d62a94f70c865bc27262f2cb70b6ca 100644 (file)
@@ -141,6 +141,12 @@ defmodule Pleroma.FollowingRelationship do
     |> where([r], r.state == ^:follow_accept)
   end
 
+  def outgoing_pending_follow_requests_query(%User{} = follower) do
+    __MODULE__
+    |> where([r], r.follower_id == ^follower.id)
+    |> where([r], r.state == ^:follow_pending)
+  end
+
   def following(%User{} = user) do
     following =
       following_query(user)
index 72ee2d58e2951a615e247e574faf480c8e1180e2..c5c74d132038825cd10d4763e3ff7fd8123dfc4e 100644 (file)
@@ -1489,6 +1489,8 @@ defmodule Pleroma.User do
 
     delete_user_activities(user)
 
+    delete_outgoing_pending_follow_requests(user)
+
     delete_or_deactivate(user)
   end
 
@@ -1611,6 +1613,12 @@ defmodule Pleroma.User do
 
   defp delete_activity(_activity, _user), do: "Doing nothing"
 
+  defp delete_outgoing_pending_follow_requests(user) do
+    user
+    |> FollowingRelationship.outgoing_pending_follow_requests_query()
+    |> Repo.delete_all()
+  end
+
   def html_filter_policy(%User{no_rich_text: true}) do
     Pleroma.HTML.Scrubber.TwitterText
   end
index 6b344158d8de9cdd05f0bd9f3ff48f3f8709728e..d68b4a58c3bd431cc45cc1753ab0aac2fe11a7a4 100644 (file)
@@ -1159,6 +1159,9 @@ defmodule Pleroma.UserTest do
       follower = insert(:user)
       {:ok, follower} = User.follow(follower, user)
 
+      locked_user = insert(:user, name: "locked", locked: true)
+      {:ok, _} = User.follow(user, locked_user, :follow_pending)
+
       object = insert(:note, user: user)
       activity = insert(:note_activity, user: user, note: object)
 
@@ -1177,6 +1180,8 @@ defmodule Pleroma.UserTest do
       refute User.following?(follower, user)
       assert %{deactivated: true} = User.get_by_id(user.id)
 
+      assert [] == User.get_follow_requests(locked_user)
+
       user_activities =
         user.ap_id
         |> Activity.Queries.by_actor()