MastoAPI: Show source field when deleting
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 26 Jun 2020 05:16:24 +0000 (07:16 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 26 Jun 2020 17:52:20 +0000 (19:52 +0200)
lib/pleroma/web/api_spec/operations/status_operation.ex
lib/pleroma/web/api_spec/schemas/status.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/support/factory.ex
test/web/mastodon_api/controllers/status_controller_test.exs
test/web/mastodon_api/views/status_view_test.exs

index 0b7fad79353e7fef220c6c9044ec23de9505c8ca..5bd4619d519dba85b043fcc95b3ac1d7091be548 100644 (file)
@@ -84,7 +84,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
       operationId: "StatusController.delete",
       parameters: [id_param()],
       responses: %{
-        200 => empty_object_response(),
+        200 => status_response(),
         403 => Operation.response("Forbidden", "application/json", ApiError),
         404 => Operation.response("Not Found", "application/json", ApiError)
       }
index 8b87cb25b24d22291cf4e17bc6fce36243b6feb1..a38b5b40fea0fbabb3773cea2003eb6023774aa3 100644 (file)
@@ -62,6 +62,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
         }
       },
       content: %Schema{type: :string, format: :html, description: "HTML-encoded status content"},
+      text: %Schema{
+        type: :string,
+        description: "Original unformatted content in plain text",
+        nullable: true
+      },
       created_at: %Schema{
         type: :string,
         format: "date-time",
index 468b44b6758ea43f89d67fb7603d6c19a1dabb2b..3f4c53437829b5c4c7c48ce7aea8dbc6c381356a 100644 (file)
@@ -200,11 +200,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
 
   @doc "DELETE /api/v1/statuses/:id"
   def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
-    with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
-      json(conn, %{})
+    with %Activity{} = activity <- Activity.get_by_id_with_object(id),
+         render <-
+           try_render(conn, "show.json",
+             activity: activity,
+             for: user,
+             with_direct_conversation_id: true,
+             with_source: true
+           ),
+         {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
+      render
     else
-      {:error, :not_found} = e -> e
-      _e -> render_error(conn, :forbidden, "Can't delete this post")
+      _e -> {:error, :not_found}
     end
   end
 
index 2c49bedb36760f23698836d988eb952845b9c982..4df47f58471b1e65bec0da9e4e4837855ffa72a4 100644 (file)
@@ -333,6 +333,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       reblog: nil,
       card: card,
       content: content_html,
+      text: opts[:with_source] && object.data["source"],
       created_at: created_at,
       reblogs_count: announcement_count,
       replies_count: object.data["repliesCount"] || 0,
index 6e22b66a417e7837cf4986f0d082b6f9884ef826..af580021c9ba46ecd16867ee047ca84ddd05909b 100644 (file)
@@ -67,6 +67,7 @@ defmodule Pleroma.Factory do
     data = %{
       "type" => "Note",
       "content" => text,
+      "source" => text,
       "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
       "actor" => user.ap_id,
       "to" => ["https://www.w3.org/ns/activitystreams#Public"],
index a98e939e826ced48081a49a926aba488bb54d823..fd2de8d808ff1da608691a9d91d10b53a2ecc7e3 100644 (file)
@@ -760,13 +760,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
     test "when you created it" do
       %{user: author, conn: conn} = oauth_access(["write:statuses"])
       activity = insert(:note_activity, user: author)
+      object = Object.normalize(activity)
 
-      conn =
+      content = object.data["content"]
+      source = object.data["source"]
+
+      result =
         conn
         |> assign(:user, author)
         |> delete("/api/v1/statuses/#{activity.id}")
+        |> json_response_and_validate_schema(200)
 
-      assert %{} = json_response_and_validate_schema(conn, 200)
+      assert match?(%{"content" => ^content, "text" => ^source}, result)
 
       refute Activity.get_by_id(activity.id)
     end
@@ -789,7 +794,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
 
       conn = delete(conn, "/api/v1/statuses/#{activity.id}")
 
-      assert %{"error" => _} = json_response_and_validate_schema(conn, 403)
+      assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)
 
       assert Activity.get_by_id(activity.id) == activity
     end
index 5cbadf0fcc6703e856916df95c1d074328dd45eb..b6ae4d3438e6181d090bf48585b31d38d2f095e1 100644 (file)
@@ -183,6 +183,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       card: nil,
       reblog: nil,
       content: HTML.filter_tags(object_data["content"]),
+      text: nil,
       created_at: created_at,
       reblogs_count: 0,
       replies_count: 0,