From 76f732766ba36c3a94cf6b8b39fb745c1cf3f49a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 3 Feb 2021 12:32:44 -0600 Subject: [PATCH 1/3] Exclude reporter from receiving notifications from their own reports. Currently only works if the reporting actor is an admin, but if we include moderators with those who receive notification reports it will work for them. --- lib/pleroma/notification.ex | 4 ++-- lib/pleroma/web/activity_pub/activity_pub.ex | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 55b513212..1970fbf65 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -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 diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1a84375fb..5b45e2ca1 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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 From 5bb5949048b6eeb236cca450c8399ac412fbd2a8 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 3 Feb 2021 12:54:53 -0600 Subject: [PATCH 2/3] Validate admin making report doesn't get their own report notification, but other admins do --- test/pleroma/notification_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 0c6ebfb76..948587292 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -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) From 000d3365c391fb3613c5365f73f5bd51d2555840 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 3 Feb 2021 14:52:49 -0600 Subject: [PATCH 3/3] Document admin actors not getting report notifications --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47009abc9..777847fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Deprecated `Pleroma.Uploaders.S3, :public_endpoint`. Now `Pleroma.Upload, :base_url` is the standard configuration key for all uploaders. - 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. +- Admins no longer receive notifications for reports if they are the actor making the report.
API Changes