Merge branch 'fix/reports-from-admins' into 'develop'
authorrinpatch <rinpatch@sdf.org>
Mon, 8 Feb 2021 10:31:20 +0000 (10:31 +0000)
committerrinpatch <rinpatch@sdf.org>
Mon, 8 Feb 2021 10:31:20 +0000 (10:31 +0000)
Suppress report notification for admin actors

See merge request pleroma/pleroma!3301

CHANGELOG.md
lib/pleroma/notification.ex
lib/pleroma/web/activity_pub/activity_pub.ex
test/pleroma/notification_test.exs

index 1dbdb3f4e04175052b9396185b8718742a49afbc..9fc138d5405be576849048c5a6d556840f5edec6 100644 (file)
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Improved Apache webserver support: updated sample configuration, MediaProxy cache invalidation verified with the included sample script
 - Improve OAuth 2.0 provider support. A missing `fqn` field was added to the response, but does not expose the user's email address.
 - Provide redirect of external posts from `/notice/:id` to their original URL
+- Admins no longer receive notifications for reports if they are the actor making the report.
 
 <details>
   <summary>API Changes</summary>
index 55b51321287426fd00abb22e0e8185b59066b6ee..1970fbf65d1611ac907fdeaa78aa6f660404e5d2 100644 (file)
@@ -507,8 +507,8 @@ defmodule Pleroma.Notification do
     [object_id]
   end
 
-  def get_potential_receiver_ap_ids(%{data: %{"type" => "Flag"}}) do
-    User.all_superusers() |> Enum.map(fn user -> user.ap_id end)
+  def get_potential_receiver_ap_ids(%{data: %{"type" => "Flag", "actor" => actor}}) do
+    (User.all_superusers() |> Enum.map(fn user -> user.ap_id end)) -- [actor]
   end
 
   def get_potential_receiver_ap_ids(activity) do
index 1a84375fb38166c5d1b9f5e2002736e330c3d2c1..5b45e2ca1dca30c5488b53c4477d73958c25aeb3 100644 (file)
@@ -377,6 +377,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
          :ok <-
            maybe_federate(stripped_activity) do
       User.all_superusers()
+      |> Enum.filter(fn user -> user.ap_id != actor end)
       |> Enum.filter(fn user -> not is_nil(user.email) end)
       |> Enum.each(fn superuser ->
         superuser
index 0c6ebfb761d512cd352be9794c952f669bdce7ac..948587292af35746b5978bf4b30b30224e481607 100644 (file)
@@ -45,6 +45,20 @@ defmodule Pleroma.NotificationTest do
       assert notification.type == "pleroma:report"
     end
 
+    test "suppresses notification to reporter if reporter is an admin" do
+      reporting_admin = insert(:user, is_admin: true)
+      reported_user = insert(:user)
+      other_admin = insert(:user, is_admin: true)
+
+      {:ok, activity} = CommonAPI.report(reporting_admin, %{account_id: reported_user.id})
+
+      {:ok, [notification]} = Notification.create_notifications(activity)
+
+      refute notification.user_id == reporting_admin.id
+      assert notification.user_id == other_admin.id
+      assert notification.type == "pleroma:report"
+    end
+
     test "creates a notification for an emoji reaction" do
       user = insert(:user)
       other_user = insert(:user)