Merge branch 'reject-replies-to-deleted' into 'develop'

Return a 422 when trying to reply to a deleted status

See merge request pleroma/pleroma!4122
This commit is contained in:
lain 2024-05-27 11:41:46 +00:00
commit 6757382abe
4 changed files with 27 additions and 18 deletions

View File

@ -0,0 +1 @@
A 422 error is returned when attempting to reply to a deleted status

View File

@ -129,8 +129,22 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft
defp in_reply_to(%{params: %{in_reply_to_status_id: id}} = draft) when is_binary(id) do defp in_reply_to(%{params: %{in_reply_to_status_id: :deleted}} = draft) do
%__MODULE__{draft | in_reply_to: Activity.get_by_id(id)} add_error(draft, dgettext("errors", "Cannot reply to a deleted status"))
end
defp in_reply_to(%{params: %{in_reply_to_status_id: id} = params} = draft) when is_binary(id) do
activity = Activity.get_by_id(id)
params =
if is_nil(activity) do
# Deleted activities are returned as nil
Map.put(params, :in_reply_to_status_id, :deleted)
else
Map.put(params, :in_reply_to_status_id, activity)
end
in_reply_to(%{draft | params: params})
end end
defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do

View File

@ -859,22 +859,6 @@ defmodule Pleroma.NotificationTest do
assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))
end end
test "replying to a deleted post without tagging does not generate a notification" do
user = insert(:user)
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "test post"})
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
{:ok, _reply_activity} =
CommonAPI.post(other_user, %{
status: "test reply",
in_reply_to_status_id: activity.id
})
assert Enum.empty?(Notification.for_user(user))
end
test "notifications are deleted if a local user is deleted" do test "notifications are deleted if a local user is deleted" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)

View File

@ -235,6 +235,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
end end
test "replying to a deleted status", %{user: user, conn: conn} do
{:ok, status} = CommonAPI.post(user, %{status: "cofe"})
{:ok, _deleted_status} = CommonAPI.delete(status.id, user)
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => status.id})
|> json_response_and_validate_schema(422)
end
test "replying to a direct message with visibility other than direct", %{ test "replying to a direct message with visibility other than direct", %{
user: user, user: user,
conn: conn conn: conn