Do not put meta[:object_data] for local Updates

This commit is contained in:
Tusooa Zhu 2022-06-25 10:03:19 -04:00 committed by FloatingGhost
parent f4d9633141
commit 9e4c87a152
2 changed files with 42 additions and 1 deletions

View file

@ -129,7 +129,8 @@ def validate(
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
@ -137,6 +138,15 @@ def validate(
|> 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

View file

@ -95,5 +95,36 @@ test "converts object into Pleroma's format" 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