forked from AkkomaGang/akkoma
Merge branch 'features/mastoapi-2.9.0-status_text' into 'develop'
MastoAPI 2.9.0: status text on deletion See merge request pleroma/pleroma!2690
This commit is contained in:
commit
c2a052a346
10 changed files with 32 additions and 8 deletions
|
@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- **Breaking:** Emoji API: changed methods and renamed routes.
|
- **Breaking:** Emoji API: changed methods and renamed routes.
|
||||||
- Streaming: Repeats of a user's posts will no longer be pushed to the user's stream.
|
- Streaming: Repeats of a user's posts will no longer be pushed to the user's stream.
|
||||||
- Mastodon API: Added `pleroma.metadata.fields_limits` to /api/v1/instance
|
- Mastodon API: Added `pleroma.metadata.fields_limits` to /api/v1/instance
|
||||||
|
- Mastodon API: On deletion, returns the original post text.
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
|
@ -84,7 +84,7 @@ def delete_operation do
|
||||||
operationId: "StatusController.delete",
|
operationId: "StatusController.delete",
|
||||||
parameters: [id_param()],
|
parameters: [id_param()],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => empty_object_response(),
|
200 => status_response(),
|
||||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
403 => Operation.response("Forbidden", "application/json", ApiError),
|
||||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
content: %Schema{type: :string, format: :html, description: "HTML-encoded status content"},
|
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{
|
created_at: %Schema{
|
||||||
type: :string,
|
type: :string,
|
||||||
format: "date-time",
|
format: "date-time",
|
||||||
|
|
|
@ -186,6 +186,7 @@ defp object(draft) do
|
||||||
draft.poll
|
draft.poll
|
||||||
)
|
)
|
||||||
|> Map.put("emoji", emoji)
|
|> Map.put("emoji", emoji)
|
||||||
|
|> Map.put("source", draft.status)
|
||||||
|
|
||||||
%__MODULE__{draft | object: object}
|
%__MODULE__{draft | object: object}
|
||||||
end
|
end
|
||||||
|
|
|
@ -200,11 +200,18 @@ def show(%{assigns: %{user: user}} = conn, %{id: id}) do
|
||||||
|
|
||||||
@doc "DELETE /api/v1/statuses/:id"
|
@doc "DELETE /api/v1/statuses/:id"
|
||||||
def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
|
def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
|
||||||
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
|
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||||
json(conn, %{})
|
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
|
else
|
||||||
{:error, :not_found} = e -> e
|
_e -> {:error, :not_found}
|
||||||
_e -> render_error(conn, :forbidden, "Can't delete this post")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
||||||
reblog: nil,
|
reblog: nil,
|
||||||
card: card,
|
card: card,
|
||||||
content: content_html,
|
content: content_html,
|
||||||
|
text: opts[:with_source] && object.data["source"],
|
||||||
created_at: created_at,
|
created_at: created_at,
|
||||||
reblogs_count: announcement_count,
|
reblogs_count: announcement_count,
|
||||||
replies_count: object.data["repliesCount"] || 0,
|
replies_count: object.data["repliesCount"] || 0,
|
||||||
|
|
|
@ -67,6 +67,7 @@ def note_factory(attrs \\ %{}) do
|
||||||
data = %{
|
data = %{
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
"content" => text,
|
"content" => text,
|
||||||
|
"source" => text,
|
||||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||||
"actor" => user.ap_id,
|
"actor" => user.ap_id,
|
||||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
|
|
@ -491,6 +491,7 @@ test "it filters out obviously bad tags when accepting a post as HTML" do
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||||
|
assert object.data["source"] == post
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it filters out obviously bad tags when accepting a post as Markdown" do
|
test "it filters out obviously bad tags when accepting a post as Markdown" do
|
||||||
|
@ -507,6 +508,7 @@ test "it filters out obviously bad tags when accepting a post as Markdown" do
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||||
|
assert object.data["source"] == post
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not allow replies to direct messages that are not direct messages themselves" do
|
test "it does not allow replies to direct messages that are not direct messages themselves" do
|
||||||
|
|
|
@ -760,13 +760,18 @@ test "if user is authenticated", %{local: local, remote: remote} do
|
||||||
test "when you created it" do
|
test "when you created it" do
|
||||||
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
||||||
activity = insert(:note_activity, user: author)
|
activity = insert(:note_activity, user: author)
|
||||||
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
conn =
|
content = object.data["content"]
|
||||||
|
source = object.data["source"]
|
||||||
|
|
||||||
|
result =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, author)
|
|> assign(:user, author)
|
||||||
|> delete("/api/v1/statuses/#{activity.id}")
|
|> 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)
|
refute Activity.get_by_id(activity.id)
|
||||||
end
|
end
|
||||||
|
@ -789,7 +794,7 @@ test "when you didn't create it" do
|
||||||
|
|
||||||
conn = delete(conn, "/api/v1/statuses/#{activity.id}")
|
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
|
assert Activity.get_by_id(activity.id) == activity
|
||||||
end
|
end
|
||||||
|
|
|
@ -183,6 +183,7 @@ test "a note activity" do
|
||||||
card: nil,
|
card: nil,
|
||||||
reblog: nil,
|
reblog: nil,
|
||||||
content: HTML.filter_tags(object_data["content"]),
|
content: HTML.filter_tags(object_data["content"]),
|
||||||
|
text: nil,
|
||||||
created_at: created_at,
|
created_at: created_at,
|
||||||
reblogs_count: 0,
|
reblogs_count: 0,
|
||||||
replies_count: 0,
|
replies_count: 0,
|
||||||
|
|
Loading…
Reference in a new issue