Support blocking via query parameters as well and document the change.
authorMark Felder <feld@FreeBSD.org>
Thu, 23 Jul 2020 17:59:40 +0000 (12:59 -0500)
committerMark Felder <feld@FreeBSD.org>
Thu, 23 Jul 2020 17:59:40 +0000 (12:59 -0500)
CHANGELOG.md
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 75488f026949185417b57569828102a94488df35..4481e8b8f96f7183e990abf0addeb36717cb3b95 100644 (file)
@@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - **Breaking:** Notification Settings API option for hiding push notification
   contents has been renamed to `hide_notification_contents`
 - Mastodon API: Added `pleroma.metadata.post_formats` to /api/v1/instance
+- Mastodon API (legacy): Allow query parameters for `/api/v1/domain_blocks`, e.g. `/api/v1/domain_blocks?domain=badposters.zone`
 </details>
 
 <details>
index 8234394f951e18c0698c7e816df290934eb46da9..1e0da820966146a0a4954ba7e3c1d492dbf4bdf9 100644 (file)
@@ -31,6 +31,7 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do
     }
   end
 
+  # Supporting domain query parameter is deprecated in Mastodon API
   def create_operation do
     %Operation{
       tags: ["domain_blocks"],
@@ -45,11 +46,13 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do
       """,
       operationId: "DomainBlockController.create",
       requestBody: domain_block_request(),
+      parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
       security: [%{"oAuth" => ["follow", "write:blocks"]}],
       responses: %{200 => empty_object_response()}
     }
   end
 
+  # Supporting domain query parameter is deprecated in Mastodon API
   def delete_operation do
     %Operation{
       tags: ["domain_blocks"],
index 117e8942604fe518f08ce862abbd6f94db9dd85f..9c2d093cdb493946d66689b53b362694660e8de2 100644 (file)
@@ -32,6 +32,11 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
     json(conn, %{})
   end
 
+  def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
+    User.block_domain(blocker, domain)
+    json(conn, %{})
+  end
+
   @doc "DELETE /api/v1/domain_blocks"
   def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
     User.unblock_domain(blocker, domain)
index 978290d625da7f23f6aae9ba374b25467ff5434e..66465450003c213770b0b7ffa583eeee019b9d75 100644 (file)
@@ -32,6 +32,20 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
     refute User.blocks?(user, other_user)
   end
 
+  test "blocking a domain via query params" do
+    %{user: user, conn: conn} = oauth_access(["write:blocks"])
+    other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
+
+    ret_conn =
+      conn
+      |> put_req_header("content-type", "application/json")
+      |> post("/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)
+    assert 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"})