Do not put meta[:object_data] for local Updates
This commit is contained in:
parent
9c6dae942d
commit
5321fd0012
2 changed files with 42 additions and 1 deletions
|
@ -146,7 +146,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||||
meta
|
meta
|
||||||
)
|
)
|
||||||
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
||||||
with {:ok, object_data} <- cast_and_apply(object),
|
with {_, false} <- {:local, Access.get(meta, :local, false)},
|
||||||
|
{:ok, object_data} <- cast_and_apply(object),
|
||||||
meta = Keyword.put(meta, :object_data, object_data |> stringify_keys),
|
meta = Keyword.put(meta, :object_data, object_data |> stringify_keys),
|
||||||
{:ok, update_activity} <-
|
{:ok, update_activity} <-
|
||||||
update_activity
|
update_activity
|
||||||
|
@ -154,6 +155,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||||
|> Ecto.Changeset.apply_action(:insert) do
|
|> Ecto.Changeset.apply_action(:insert) do
|
||||||
update_activity = stringify_keys(update_activity)
|
update_activity = stringify_keys(update_activity)
|
||||||
{:ok, update_activity, meta}
|
{:ok, update_activity, meta}
|
||||||
|
else
|
||||||
|
{:local, _} ->
|
||||||
|
with {:ok, object} <-
|
||||||
|
update_activity
|
||||||
|
|> UpdateValidator.cast_and_validate()
|
||||||
|
|> Ecto.Changeset.apply_action(:insert) do
|
||||||
|
object = stringify_keys(object)
|
||||||
|
{:ok, object, meta}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -95,5 +95,36 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
|
||||||
assert %{"emoji" => %{"some_emoji" => "https://somewhere.org/emoji/url/1.png"}} =
|
assert %{"emoji" => %{"some_emoji" => "https://somewhere.org/emoji/url/1.png"}} =
|
||||||
meta[:object_data]
|
meta[:object_data]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns no object_data in meta for a local Update" do
|
||||||
|
user = insert(:user)
|
||||||
|
note = insert(:note, user: user)
|
||||||
|
|
||||||
|
updated_note =
|
||||||
|
note.data
|
||||||
|
|> Map.put("content", "edited content")
|
||||||
|
|
||||||
|
{:ok, update, _} = Builder.update(user, updated_note)
|
||||||
|
|
||||||
|
assert {:ok, _update, meta} = ObjectValidator.validate(update, local: true)
|
||||||
|
assert is_nil(meta[:object_data])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns object_data in meta for a remote Update" do
|
||||||
|
user = insert(:user)
|
||||||
|
note = insert(:note, user: user)
|
||||||
|
|
||||||
|
updated_note =
|
||||||
|
note.data
|
||||||
|
|> Map.put("content", "edited content")
|
||||||
|
|
||||||
|
{:ok, update, _} = Builder.update(user, updated_note)
|
||||||
|
|
||||||
|
assert {:ok, _update, meta} = ObjectValidator.validate(update, local: false)
|
||||||
|
assert meta[:object_data]
|
||||||
|
|
||||||
|
assert {:ok, _update, meta} = ObjectValidator.validate(update, [])
|
||||||
|
assert meta[:object_data]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue