From 9e6f4694dd21f92bb2292e819d0f7f1cad149887 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 27 Jul 2020 16:39:50 +0200 Subject: [PATCH] Pipeline: Unify embedded_object / object_data, move to validator. --- lib/pleroma/web/activity_pub/object_validator.ex | 7 +++++++ lib/pleroma/web/activity_pub/pipeline.ex | 2 +- lib/pleroma/web/activity_pub/side_effects.ex | 4 ---- test/web/activity_pub/pipeline_test.exs | 4 ++-- test/web/activity_pub/side_effects_test.exs | 5 ++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/activity_pub/object_validator.ex b/lib/pleroma/web/activity_pub/object_validator.ex index df926829c..0dcc7be4d 100644 --- a/lib/pleroma/web/activity_pub/object_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validator.ex @@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do the system. """ + alias Pleroma.Activity alias Pleroma.EctoType.ActivityPub.ObjectValidators alias Pleroma.Object alias Pleroma.User @@ -71,6 +72,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do |> UndoValidator.cast_and_validate() |> Ecto.Changeset.apply_action(:insert) do 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} end end diff --git a/lib/pleroma/web/activity_pub/pipeline.ex b/lib/pleroma/web/activity_pub/pipeline.ex index 50d9016e6..36e325c37 100644 --- a/lib/pleroma/web/activity_pub/pipeline.ex +++ b/lib/pleroma/web/activity_pub/pipeline.ex @@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do if !do_not_federate && local do 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)} else activity diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 33bee1576..1d2c296a5 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -174,10 +174,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do with undone_object <- Activity.get_by_ap_id(undone_object), :ok <- handle_undoing(undone_object) do - meta = - meta - |> Keyword.put(:embedded_object, undone_object.data) - {:ok, object, meta} end end diff --git a/test/web/activity_pub/pipeline_test.exs b/test/web/activity_pub/pipeline_test.exs index 202b5fe61..f2a231eaf 100644 --- a/test/web/activity_pub/pipeline_test.exs +++ b/test/web/activity_pub/pipeline_test.exs @@ -14,10 +14,10 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do :ok 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) 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)} diff --git a/test/web/activity_pub/side_effects_test.exs b/test/web/activity_pub/side_effects_test.exs index d48c235c0..4a08eb7ee 100644 --- a/test/web/activity_pub/side_effects_test.exs +++ b/test/web/activity_pub/side_effects_test.exs @@ -312,13 +312,12 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do } end - test "deletes the original block, but sets `embedded_object`", %{ + test "deletes the original block", %{ block_undo: block_undo, block: block } 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) end -- 2.45.2