Fix tagpolicy to also work with Update
Objects who got updated would just pass the TagPolicy, undoing the moderation that was set in place for the Actor. Now we check not only for Create activities, but also Update activities.
This commit is contained in:
parent
9addd8f414
commit
ce517ff4e5
2 changed files with 69 additions and 9 deletions
|
@ -27,22 +27,22 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy 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)
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
defp process_tag(
|
defp process_tag(
|
||||||
"mrf_tag:force-unlisted",
|
"mrf_tag:force-unlisted",
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => type,
|
||||||
"to" => to,
|
"to" => to,
|
||||||
"cc" => cc,
|
"cc" => cc,
|
||||||
"actor" => actor,
|
"actor" => actor,
|
||||||
"object" => object
|
"object" => object
|
||||||
} = message
|
} = message
|
||||||
) do
|
) when type in ["Create", "Update"] do
|
||||||
user = User.get_cached_by_ap_id(actor)
|
user = User.get_cached_by_ap_id(actor)
|
||||||
|
|
||||||
if Enum.member?(to, Pleroma.Constants.as_public()) do
|
if Enum.member?(to, Pleroma.Constants.as_public()) do
|
||||||
|
@ -85,13 +85,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
defp process_tag(
|
defp process_tag(
|
||||||
"mrf_tag:sandbox",
|
"mrf_tag:sandbox",
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => type,
|
||||||
"to" => to,
|
"to" => to,
|
||||||
"cc" => cc,
|
"cc" => cc,
|
||||||
"actor" => actor,
|
"actor" => actor,
|
||||||
"object" => object
|
"object" => object
|
||||||
} = message
|
} = message
|
||||||
) do
|
) when type in ["Create", "Update"] do
|
||||||
user = User.get_cached_by_ap_id(actor)
|
user = User.get_cached_by_ap_id(actor)
|
||||||
|
|
||||||
if Enum.member?(to, Pleroma.Constants.as_public()) or
|
if Enum.member?(to, Pleroma.Constants.as_public()) or
|
||||||
|
@ -152,7 +152,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
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
|
||||||
|
|
|
@ -53,7 +53,24 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
||||||
"cc" => ["d"]
|
"cc" => ["d"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{},
|
||||||
|
"to" => [@public, "f"],
|
||||||
|
"cc" => [@public, "d"]
|
||||||
|
}
|
||||||
|
|
||||||
|
edit_expect_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"to" => ["f", actor.follower_address], "cc" => ["d"]},
|
||||||
|
"to" => ["f", actor.follower_address],
|
||||||
|
"cc" => ["d"]
|
||||||
|
}
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
assert TagPolicy.filter(edit_message) == {:ok, edit_expect_message}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +94,24 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
||||||
"cc" => ["d", @public]
|
"cc" => ["d", @public]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{},
|
||||||
|
"to" => [@public, "f"],
|
||||||
|
"cc" => [actor.follower_address, "d"]
|
||||||
|
}
|
||||||
|
|
||||||
|
edit_expect_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
|
||||||
|
"to" => ["f", actor.follower_address],
|
||||||
|
"cc" => ["d", @public]
|
||||||
|
}
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
assert TagPolicy.filter(edit_message) == {:ok, edit_expect_message}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,7 +131,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
||||||
"object" => %{}
|
"object" => %{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"attachment" => ["file1"]}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit_expect_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{}
|
||||||
|
}
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
assert TagPolicy.filter(edit_message) == {:ok, edit_expect_message}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,7 +164,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
||||||
"object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
|
"object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"tag" => ["test"], "attachment" => ["file1"]}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit_expect_message = %{
|
||||||
|
"actor" => actor.ap_id,
|
||||||
|
"type" => "Update",
|
||||||
|
"object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
|
||||||
|
}
|
||||||
|
|
||||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||||
|
assert TagPolicy.filter(edit_message) == {:ok, edit_expect_message}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue