Pipeline: Unify embedded_object / object_data, move to validator.

This commit is contained in:
lain 2020-07-27 16:39:50 +02:00
parent 762c9ea564
commit 9e6f4694dd
5 changed files with 12 additions and 10 deletions

View file

@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
the system. the system.
""" """
alias Pleroma.Activity
alias Pleroma.EctoType.ActivityPub.ObjectValidators alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
@ -71,6 +72,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|> UndoValidator.cast_and_validate() |> UndoValidator.cast_and_validate()
|> Ecto.Changeset.apply_action(:insert) do |> Ecto.Changeset.apply_action(:insert) do
object = stringify_keys(object) object = stringify_keys(object)
undone_object = Activity.get_by_ap_id(object["object"])
meta =
meta
|> Keyword.put(:object_data, undone_object.data)
{:ok, object, meta} {:ok, object, meta}
end end
end end

View file

@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
if !do_not_federate && local do if !do_not_federate && local do
activity = activity =
if object = Keyword.get(meta, :embedded_object) do if object = Keyword.get(meta, :object_data) do
%{activity | data: Map.put(activity.data, "object", object)} %{activity | data: Map.put(activity.data, "object", object)}
else else
activity activity

View file

@ -174,10 +174,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do
with undone_object <- Activity.get_by_ap_id(undone_object), with undone_object <- Activity.get_by_ap_id(undone_object),
:ok <- handle_undoing(undone_object) do :ok <- handle_undoing(undone_object) do
meta =
meta
|> Keyword.put(:embedded_object, undone_object.data)
{:ok, object, meta} {:ok, object, meta}
end end
end end

View file

@ -14,10 +14,10 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
:ok :ok
end end
test "when given an `embedded_object` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do test "when given an `object_data` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do
activity = insert(:note_activity) activity = insert(:note_activity)
object = %{"id" => "1", "type" => "Love"} object = %{"id" => "1", "type" => "Love"}
meta = [local: true, embedded_object: object] meta = [local: true, object_data: object]
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)} activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}

View file

@ -312,13 +312,12 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
} }
end end
test "deletes the original block, but sets `embedded_object`", %{ test "deletes the original block", %{
block_undo: block_undo, block_undo: block_undo,
block: block block: block
} do } do
{:ok, _block_undo, meta} = SideEffects.handle(block_undo) {:ok, _block_undo, _meta} = SideEffects.handle(block_undo)
assert meta[:embedded_object] == block.data
refute Activity.get_by_id(block.id) refute Activity.get_by_id(block.id)
end end