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>
Sat, 2 May 2020 16:05:13 +0000 (19:05 +0300)
CHANGELOG.md
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index 97704917d8030ed5df48ffa5f62b225235b5a126..54a0561b3695a714bd3f91fa44d6ad36a1508cc1 100644 (file)
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Logger configuration through AdminFE
 - HTTP Basic Authentication permissions issue
 - ObjectAgePolicy didn't filter out old messages
+- Mastodon API: do not create a following relationship if the corresponding follow request doesn't exist when calling `POST /api/v1/follow_requests/:id/authorize`
 
 ### Added
 - NodeInfo: ObjectAgePolicy settings to the `federation` list.
index 4618b4bbf335f965af633a66c6068813b633851c..f9db97d24711b66449fed05b10f489459bc83926 100644 (file)
@@ -43,8 +43,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, :follow_accept),
          {:ok, _activity} <-
index c6ccc02c4a4e58daf18cc2685413530d4c52da13..bc0c1a7912506ef768a1f3cc94e74a330c5433bd 100644 (file)
@@ -697,6 +697,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