Merge branch 'deleted-reply-error' into 'develop'

Return an error if replying to a deleted status

Closes #119

See merge request soapbox-pub/rebased!198
This commit is contained in:
Alex Gleason 2022-11-03 16:30:56 +00:00
commit d02c5f4480
3 changed files with 14 additions and 18 deletions

View file

@ -128,7 +128,13 @@ defp attachments(%{params: params} = draft) do
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
%__MODULE__{draft | in_reply_to: Activity.get_by_id(id)}
case Activity.get_by_id(id) do
%Activity{} = activity ->
%__MODULE__{draft | in_reply_to: activity}
_ ->
add_error(draft, dgettext("errors", "The post being replied to was deleted"))
end
end
defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do

View file

@ -1045,23 +1045,6 @@ test "repeating an activity which is already deleted does not generate a notific
assert Enum.empty?(Notification.for_user(user))
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
})
Pleroma.Tests.ObanHelpers.perform_all()
assert Enum.empty?(Notification.for_user(user))
end
test "notifications are deleted if a local user is deleted" do
user = insert(:user)
other_user = insert(:user)

View file

@ -773,6 +773,13 @@ test "quote posting visibility" do
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: unlisted.id})
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id})
end
test "block replying to a deleted or non-existant status" do
user = insert(:user)
assert {:error, "The post being replied to was deleted"} =
CommonAPI.post(user, %{status: "hi", in_reply_to_id: "nonexistant"})
end
end
describe "reactions" do