WIP: post editing #103

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

View file

@ -921,7 +921,24 @@ def prepare_attachments(object) do
end end
def strip_internal_fields(object) do def strip_internal_fields(object) do
Map.drop(object, Pleroma.Constants.object_internal_fields()) outer = Map.drop(object, Pleroma.Constants.object_internal_fields())
case outer do
%{"formerRepresentations" => %{"orderedItems" => list}} when is_list(list) ->
update_in(
outer["formerRepresentations"]["orderedItems"],
&Enum.map(
&1,
fn
item when is_map(item) -> Map.drop(item, Pleroma.Constants.object_internal_fields())
item -> item
end
)
)
_ ->
outer
end
end end
defp strip_internal_tags(%{"tag" => tags} = object) do defp strip_internal_tags(%{"tag" => tags} = object) do

View file

@ -550,4 +550,58 @@ test "puts dimensions into attachment url field" do
assert Transmogrifier.fix_attachments(object) == expected assert Transmogrifier.fix_attachments(object) == expected
end end
end end
describe "strip_internal_fields/1" do
test "it strips internal fields in formerRepresentations" do
original = %{
"formerRepresentations" => %{
"orderedItems" => [
%{"generator" => %{}}
]
}
}
stripped = Transmogrifier.strip_internal_fields(original)
refute Map.has_key?(
Enum.at(stripped["formerRepresentations"]["orderedItems"], 0),
"generator"
)
end
test "it strips internal fields in maybe badly-formed formerRepresentations" do
original = %{
"formerRepresentations" => %{
"orderedItems" => [
%{"generator" => %{}},
"https://example.com/1"
]
}
}
stripped = Transmogrifier.strip_internal_fields(original)
refute Map.has_key?(
Enum.at(stripped["formerRepresentations"]["orderedItems"], 0),
"generator"
)
assert Enum.at(stripped["formerRepresentations"]["orderedItems"], 1) ==
"https://example.com/1"
end
test "it ignores if formerRepresentations does not look like an OrderedCollection" do
original = %{
"formerRepresentations" => %{
"items" => [
%{"generator" => %{}}
]
}
}
stripped = Transmogrifier.strip_internal_fields(original)
assert Map.has_key?(Enum.at(stripped["formerRepresentations"]["items"], 0), "generator")
end
end
end end