Allow unblocking a domain via query params
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 21 Jul 2020 12:06:46 +0000 (16:06 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 21 Jul 2020 12:06:46 +0000 (16:06 +0400)
lib/pleroma/web/api_spec/operations/domain_block_operation.ex
lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex
test/web/mastodon_api/controllers/domain_block_controller_test.exs

index 049bcf93139c5b1005bc292159c021922269fdd5..8234394f951e18c0698c7e816df290934eb46da9 100644 (file)
@@ -57,6 +57,7 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do
       description: "Remove a domain block, if it exists in the user's array of blocked domains.",
       operationId: "DomainBlockController.delete",
       requestBody: domain_block_request(),
       description: "Remove a domain block, if it exists in the user's array of blocked domains.",
       operationId: "DomainBlockController.delete",
       requestBody: domain_block_request(),
+      parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
       security: [%{"oAuth" => ["follow", "write:blocks"]}],
       responses: %{
         200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
       security: [%{"oAuth" => ["follow", "write:blocks"]}],
       responses: %{
         200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
@@ -71,10 +72,9 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do
         type: :object,
         properties: %{
           domain: %Schema{type: :string}
         type: :object,
         properties: %{
           domain: %Schema{type: :string}
-        },
-        required: [:domain]
+        }
       },
       },
-      required: true,
+      required: false,
       example: %{
         "domain" => "facebook.com"
       }
       example: %{
         "domain" => "facebook.com"
       }
index 825b231ab3b02526041c11af5eece7cbe09cebd5..117e8942604fe518f08ce862abbd6f94db9dd85f 100644 (file)
@@ -37,4 +37,9 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
     User.unblock_domain(blocker, domain)
     json(conn, %{})
   end
     User.unblock_domain(blocker, domain)
     json(conn, %{})
   end
+
+  def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
+    User.unblock_domain(blocker, domain)
+    json(conn, %{})
+  end
 end
 end
index 01a24afcf2225a35589b65b1c7aff63dd49648a4..978290d625da7f23f6aae9ba374b25467ff5434e 100644 (file)
@@ -32,6 +32,24 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
     refute User.blocks?(user, other_user)
   end
 
     refute User.blocks?(user, other_user)
   end
 
+  test "unblocking a domain via query params" do
+    %{user: user, conn: conn} = oauth_access(["write:blocks"])
+    other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
+
+    User.block_domain(user, "dogwhistle.zone")
+    user = refresh_record(user)
+    assert User.blocks?(user, other_user)
+
+    ret_conn =
+      conn
+      |> put_req_header("content-type", "application/json")
+      |> delete("/api/v1/domain_blocks?domain=dogwhistle.zone")
+
+    assert %{} == json_response_and_validate_schema(ret_conn, 200)
+    user = User.get_cached_by_ap_id(user.ap_id)
+    refute User.blocks?(user, other_user)
+  end
+
   test "getting a list of domain blocks" do
     %{user: user, conn: conn} = oauth_access(["read:blocks"])
 
   test "getting a list of domain blocks" do
     %{user: user, conn: conn} = oauth_access(["read:blocks"])