Fix Reblog API
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 18 Jan 2021 16:15:57 +0000 (20:15 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 18 Jan 2021 16:15:57 +0000 (20:15 +0400)
Do not set visibility parameter to `public` by default and let CommonAPI to infer it from status.

lib/pleroma/web/api_spec/operations/status_operation.ex
test/pleroma/web/common_api_test.exs
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs

index 765fbd67bbaddf3f133c793fbbfa0071df6ba5c1..fd29f5139882137eb12d9642f7e7c4a3da37b624 100644 (file)
@@ -117,7 +117,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
         request_body("Parameters", %Schema{
           type: :object,
           properties: %{
-            visibility: %Schema{allOf: [VisibilityScope], default: "public"}
+            visibility: %Schema{allOf: [VisibilityScope]}
           }
         }),
       responses: %{
index 2ece9280663e406fb6c7b29c8bccf09f1c4053b6..2f7dc38e41f89e87413768a5f9c479fdcc471e80 100644 (file)
@@ -744,6 +744,17 @@ defmodule Pleroma.Web.CommonAPITest do
       refute Visibility.visible_for_user?(announce_activity, nil)
     end
 
+    test "author can repeat own private statuses" do
+      user = insert(:user)
+
+      {:ok, activity} = CommonAPI.post(user, %{status: "cofe", visibility: "private"})
+
+      {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
+
+      assert Visibility.is_private?(announce_activity)
+      refute Visibility.visible_for_user?(announce_activity, nil)
+    end
+
     test "favoriting a status" do
       user = insert(:user)
       other_user = insert(:user)
index 8a2267099c590e24e6ec82a7019c092f7aa875e4..bfb44374ea596a32c1efe7d3ae8a2dac5f7c147c 100644 (file)
@@ -954,6 +954,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
 
       assert to_string(activity.id) == id
     end
+
+    test "author can reblog own private status", %{conn: conn, user: user} do
+      {:ok, activity} = CommonAPI.post(user, %{status: "cofe", visibility: "private"})
+
+      conn =
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/v1/statuses/#{activity.id}/reblog")
+
+      assert %{
+               "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
+               "reblogged" => true,
+               "visibility" => "private"
+             } = json_response_and_validate_schema(conn, 200)
+
+      assert to_string(activity.id) == id
+    end
   end
 
   describe "unreblogging" do