WIP: post editing #103

Closed
Ghost wants to merge 48 commits from (deleted):feat/editing into develop
2 changed files with 42 additions and 1 deletions
Showing only changes of commit acd1daf9ea - Show all commits

View file

@ -129,7 +129,8 @@ def validate(
meta
)
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),
{:ok, update_activity} <-
update_activity
@ -137,6 +138,15 @@ def validate(
|> Ecto.Changeset.apply_action(:insert) do
update_activity = stringify_keys(update_activity)
{: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

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"}} =
meta[:object_data]
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