Fix not being able to post empty statuses with attachments
authorrinpatch <rinpatch@sdf.org>
Fri, 27 Sep 2019 22:56:20 +0000 (01:56 +0300)
committerrinpatch <rinpatch@sdf.org>
Fri, 27 Sep 2019 22:58:06 +0000 (01:58 +0300)
Attachment field was filled in after the empty status check

lib/pleroma/web/common_api/activity_draft.ex
test/web/mastodon_api/controllers/status_controller_test.exs

index aa7c8c3812bd36aea8ce98d444a8acdfd1569c6a..f7da81b349b5e6acff49fa365375b9710bec1cc1 100644 (file)
@@ -40,11 +40,11 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
     |> put_params(params)
     |> status()
     |> summary()
+    |> with_valid(&attachments/1)
     |> full_payload()
     |> expires_at()
     |> poll()
     |> with_valid(&in_reply_to/1)
-    |> with_valid(&attachments/1)
     |> with_valid(&in_reply_to_conversation/1)
     |> with_valid(&visibility/1)
     |> content()
index cbd4bafe8a84ad4b594e9aff6795ba2135644d10..c0121ac63b8208603602b3db48ba209408152a77 100644 (file)
@@ -99,6 +99,28 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
                NaiveDateTime.to_iso8601(expiration.scheduled_at)
     end
 
+    test "posting an empty status with an attachment", %{conn: conn} do
+      user = insert(:user)
+
+      file = %Plug.Upload{
+        content_type: "image/jpg",
+        path: Path.absname("test/fixtures/image.jpg"),
+        filename: "an_image.jpg"
+      }
+
+      {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+
+      conn =
+        conn
+        |> assign(:user, user)
+        |> post("/api/v1/statuses", %{
+          "media_ids" => [to_string(upload.id)],
+          "status" => ""
+        })
+
+      assert json_response(conn, 200)
+    end
+
     test "replying to a status", %{conn: conn} do
       user = insert(:user)
       {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})