Mastodon API: do not create a following relationship if the corresponding follow...
authoreugenijm <eugenijm@protonmail.com>
Mon, 27 Apr 2020 14:41:38 +0000 (17:41 +0300)
committerrinpatch <rinpatch@sdf.org>
Thu, 30 Apr 2020 21:39:23 +0000 (00:39 +0300)
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index 091011c6b1082abf268221c2b80c2a4169e66cf8..511cae63fa485bf89590721827e07bb5c0b297df 100644 (file)
@@ -39,8 +39,8 @@ defmodule Pleroma.Web.CommonAPI do
   end
 
   def accept_follow_request(follower, followed) do
-    with {:ok, follower} <- User.follow(follower, followed),
-         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
+    with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
+         {:ok, follower} <- User.follow(follower, followed),
          {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
          {:ok, _relationship} <- FollowingRelationship.update(follower, followed, "accept"),
          {:ok, _activity} <-
index b80523160eca66bdf4f85d05c3cf44874a332396..9b7fce3a0900b39d905842a113775f8eb4ff57f8 100644 (file)
@@ -640,6 +640,14 @@ defmodule Pleroma.Web.CommonAPITest do
       assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
       assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
     end
+
+    test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
+      user = insert(:user, locked: true)
+      not_follower = insert(:user)
+      CommonAPI.accept_follow_request(not_follower, user)
+
+      assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
+    end
   end
 
   describe "vote/3" do