Fix blocks import
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 22 Apr 2020 14:13:13 +0000 (18:13 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 22 Apr 2020 15:27:28 +0000 (19:27 +0400)
lib/pleroma/web/twitter_api/controllers/util_controller.ex
test/web/twitter_api/util_controller_test.exs

index 824951d599d07d7c0d3286e9f1d83472b3b09cd4..d5d5ce08f817938c9508e05af72b7e463a499178 100644 (file)
@@ -216,7 +216,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
   end
 
   def blocks_import(%{assigns: %{user: blocker}} = conn, %{"list" => list}) do
-    User.blocks_import(blocker, _blocked_identifiers = String.split(list))
+    blocked_identifiers = list |> String.split() |> Enum.map(&String.trim_leading(&1, "@"))
+    User.blocks_import(blocker, blocked_identifiers)
     json(conn, "job started")
   end
 
index 85aaab19b33b95efdfd5a9db05dc2d2538149f97..d835331ae303c584f78bd4bbe577f3358e8d91ca 100644 (file)
@@ -96,7 +96,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       end
     end
 
-    test "it imports with different nickname variations", %{conn: conn} do
+    test "it imports follows with different nickname variations", %{conn: conn} do
       [user2, user3, user4, user5, user6] = insert_list(5, :user)
 
       identifiers =
@@ -160,6 +160,29 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
                )
       end
     end
+
+    test "it imports blocks with different nickname variations", %{conn: conn} do
+      [user2, user3, user4, user5, user6] = insert_list(5, :user)
+
+      identifiers =
+        [
+          user2.ap_id,
+          user3.nickname,
+          "@" <> user4.nickname,
+          user5.nickname <> "@localhost",
+          "@" <> user6.nickname <> "@localhost"
+        ]
+        |> Enum.join(" ")
+
+      response =
+        conn
+        |> post("/api/pleroma/blocks_import", %{"list" => identifiers})
+        |> json_response(:ok)
+
+      assert response == "job started"
+      assert [job_result] = ObanHelpers.perform_all()
+      assert job_result == [user2, user3, user4, user5, user6]
+    end
   end
 
   describe "PUT /api/pleroma/notification_settings" do