Strip internal fields in formerRepresentation
This commit is contained in:
parent
b613a9ec6b
commit
410e177b2a
|
@ -902,7 +902,24 @@ def prepare_attachments(object) do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
defp strip_internal_tags(%{"tag" => tags} = object) do
|
||||
|
|
|
@ -575,4 +575,58 @@ test "puts dimensions into attachment url field" do
|
|||
assert Transmogrifier.fix_attachments(object) == expected
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue