summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2024-08-13 13:59:25 +0000
committerfeld <feld@feld.me>2024-08-13 13:59:25 +0000
commit7388c4b5ca803ea29547619badb9a22c56643209 (patch)
tree5934742a275335d3318520cde24006b94bce5bc5
parent4e7928c9850251f6d92409d5c6e97c7438499798 (diff)
parentb0c64945c2cfd622b9f2c68d594bda4fd4c1b9eb (diff)
downloadpleroma-7388c4b5ca803ea29547619badb9a22c56643209.tar.gz
pleroma-7388c4b5ca803ea29547619badb9a22c56643209.zip
Merge branch 'mrf-tests' into 'develop'
MRF.FODirectReply: use Visibility module to verify the scope See merge request pleroma/pleroma!4218
-rw-r--r--changelog.d/mrf-fodirectreply.add2
-rw-r--r--lib/pleroma/web/activity_pub/mrf/fo_direct_reply.ex20
-rw-r--r--test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs30
-rw-r--r--test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs26
4 files changed, 61 insertions, 17 deletions
diff --git a/changelog.d/mrf-fodirectreply.add b/changelog.d/mrf-fodirectreply.add
index c144e1bc0..10fd5d16a 100644
--- a/changelog.d/mrf-fodirectreply.add
+++ b/changelog.d/mrf-fodirectreply.add
@@ -1 +1 @@
-Added MRF.FODirectReply which changes replies to followers-only posts to be direct
+Added MRF.FODirectReply which changes replies to followers-only posts to be direct.
diff --git a/lib/pleroma/web/activity_pub/mrf/fo_direct_reply.ex b/lib/pleroma/web/activity_pub/mrf/fo_direct_reply.ex
index 4eb97afa8..2cf22745a 100644
--- a/lib/pleroma/web/activity_pub/mrf/fo_direct_reply.ex
+++ b/lib/pleroma/web/activity_pub/mrf/fo_direct_reply.ex
@@ -7,7 +7,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.FODirectReply do
FODirectReply alters the scope of replies to activities which are Followers Only to be Direct. The purpose of this policy is to prevent broken threads for followers of the reply author because their response was to a user that they are not also following.
"""
+ alias Pleroma.Object
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Visibility
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
@@ -25,7 +27,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.FODirectReply do
) do
with true <- is_binary(in_reply_to),
%User{follower_address: followers_collection, local: true} <- User.get_by_ap_id(actor),
- true <- followers_only?(in_reply_to) do
+ %Object{} = in_reply_to_object <- Object.get_by_ap_id(in_reply_to),
+ "private" <- Visibility.get_visibility(in_reply_to_object) do
direct_to = to -- [followers_collection]
updated_activity =
@@ -47,19 +50,4 @@ defmodule Pleroma.Web.ActivityPub.MRF.FODirectReply do
@impl true
def describe, do: {:ok, %{}}
-
- defp followers_only?(parent_ap_id) do
- with %Pleroma.Object{} = object <- Pleroma.Object.get_by_ap_id(parent_ap_id),
- object_data <- Map.get(object, :data),
- %Pleroma.User{} = user <- User.get_cached_by_ap_id(object_data["actor"]) do
- if user.follower_address in object_data["to"] do
- true
- else
- false
- end
- else
- _ ->
- false
- end
- end
end
diff --git a/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs b/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs
index 7afc83ffc..2d6af3b68 100644
--- a/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs
@@ -48,6 +48,36 @@ defmodule Pleroma.Web.ActivityPub.MRF.FODirectReplyTest do
assert expected_cc == filtered["object"]["cc"]
end
+ test "replies to unlisted posts are unmodified" do
+ batman = insert(:user, nickname: "batman")
+ robin = insert(:user, nickname: "robin")
+
+ {:ok, post} =
+ CommonAPI.post(batman, %{
+ status: "Has anyone seen Selina Kyle's latest selfies?",
+ visibility: "unlisted"
+ })
+
+ reply = %{
+ "type" => "Create",
+ "actor" => robin.ap_id,
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "object" => %{
+ "type" => "Note",
+ "actor" => robin.ap_id,
+ "content" => "@batman 🤤 ❤️ 🐈<200d>⬛",
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ assert {:ok, filtered} = FODirectReply.filter(reply)
+
+ assert match?(^filtered, reply)
+ end
+
test "replies to public posts are unmodified" do
batman = insert(:user, nickname: "batman")
robin = insert(:user, nickname: "robin")
diff --git a/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs b/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs
index 35e321fd1..79e64d650 100644
--- a/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs
@@ -50,6 +50,32 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuietReplyTest do
assert expected_cc == filtered["object"]["cc"]
end
+ test "replying to unlisted post is unmodified" do
+ batman = insert(:user, nickname: "batman")
+ robin = insert(:user, nickname: "robin")
+
+ {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!", visibility: "private"})
+
+ reply = %{
+ "type" => "Create",
+ "actor" => robin.ap_id,
+ "to" => [batman.ap_id],
+ "cc" => [],
+ "object" => %{
+ "type" => "Note",
+ "actor" => robin.ap_id,
+ "content" => "@batman Wait up, I forgot my spandex!",
+ "to" => [batman.ap_id],
+ "cc" => [],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ assert {:ok, filtered} = QuietReply.filter(reply)
+
+ assert match?(^filtered, reply)
+ end
+
test "replying direct is unmodified" do
batman = insert(:user, nickname: "batman")
robin = insert(:user, nickname: "robin")