parent
204fd6faae
commit
dc7efcd08b
|
@ -27,22 +27,22 @@ defp get_tags(_), do: []
|
||||||
defp process_tag(
|
defp process_tag(
|
||||||
"mrf_tag:media-force-nsfw",
|
"mrf_tag:media-force-nsfw",
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => type,
|
||||||
"object" => %{"attachment" => child_attachment}
|
"object" => %{"attachment" => child_attachment}
|
||||||
} = message
|
} = message
|
||||||
)
|
)
|
||||||
when length(child_attachment) > 0 do
|
when length(child_attachment) > 0 and type in ["Create", "Update"] do
|
||||||
{:ok, Kernel.put_in(message, ["object", "sensitive"], true)}
|
{:ok, Kernel.put_in(message, ["object", "sensitive"], true)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_tag(
|
defp process_tag(
|
||||||
"mrf_tag:media-strip",
|
"mrf_tag:media-strip",
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => type,
|
||||||
"object" => %{"attachment" => child_attachment} = object
|
"object" => %{"attachment" => child_attachment} = object
|
||||||
} = message
|
} = message
|
||||||
)
|
)
|
||||||
when length(child_attachment) > 0 do
|
when length(child_attachment) > 0 and type in ["Create", "Update"] do
|
||||||
object = Map.delete(object, "attachment")
|
object = Map.delete(object, "attachment")
|
||||||
message = Map.put(message, "object", object)
|
message = Map.put(message, "object", object)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def filter(%{"object" => target_actor, "type" => "Follow"} = message),
|
||||||
do: filter_message(target_actor, message)
|
do: filter_message(target_actor, message)
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"actor" => actor, "type" => "Create"} = message),
|
def filter(%{"actor" => actor, "type" => type} = message) when type in ["Create", "Update"],
|
||||||
do: filter_message(actor, message)
|
do: filter_message(actor, message)
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -99,6 +99,24 @@ test "removes attachments" do
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "removes attachments in Updates" do
|
||||||
|
actor = insert(:user, tags: ["mrf_tag:media-strip"])
|
||||||
|
|
||||||
|
message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"attachment" => ["file1"]}
|
||||||
|
}
|
||||||
|
|
||||||
|
except_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "mrf_tag:media-force-nsfw" do
|
describe "mrf_tag:media-force-nsfw" do
|
||||||
|
@ -119,5 +137,23 @@ test "Mark as sensitive on presence of attachments" do
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Mark as sensitive on presence of attachments in Updates" do
|
||||||
|
actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
|
||||||
|
|
||||||
|
message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"tag" => ["test"], "attachment" => ["file1"]}
|
||||||
|
}
|
||||||
|
|
||||||
|
except_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue