summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIlja <ilja@ilja.space>2022-03-06 17:36:30 +0100
committerIlja <ilja@ilja.space>2022-03-06 17:36:30 +0100
commit89667189b840fc79d85336739e6b2512684d7be0 (patch)
tree0219fd97f477195431c809f947354dfb9332aeb8 /lib
parentee05abe052a0e56faf67711362b270893a4ab703 (diff)
downloadpleroma-89667189b840fc79d85336739e6b2512684d7be0.tar.gz
pleroma-89667189b840fc79d85336739e6b2512684d7be0.zip
Delete report notifs when demoting from superuser
When someone isn't a superuser any more, they shouldn't see the reporsts any more either. Here we delete the report notifications from a user when that user gets updated from being a superuser to a non-superuser.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/notification.ex8
-rw-r--r--lib/pleroma/user.ex19
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 9e0ce0329..2ab09495d 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -341,6 +341,14 @@ defmodule Pleroma.Notification do
|> Repo.delete_all()
end
+ def destroy_multiple_from_types(%{id: user_id}, types) do
+ from(n in Notification,
+ where: n.user_id == ^user_id,
+ where: n.type in ^types
+ )
+ |> Repo.delete_all()
+ end
+
def dismiss(%Pleroma.Activity{} = activity) do
Notification
|> where([n], n.activity_id == ^activity.id)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 36177bda3..7ecd37337 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1127,10 +1127,27 @@ defmodule Pleroma.User do
|> update_and_set_cache()
end
- def update_and_set_cache(changeset) do
+ def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do
+ was_superuser_before_update = User.superuser?(user)
+
with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do
set_cache(user)
end
+ |> maybe_remove_report_notifications(was_superuser_before_update)
+ end
+
+ defp maybe_remove_report_notifications(
+ {:ok, %Pleroma.User{} = user} = result,
+ was_superuser_before_update
+ ) do
+ if was_superuser_before_update and not User.superuser?(user),
+ do: user |> Notification.destroy_multiple_from_types(["pleroma:report"])
+
+ result
+ end
+
+ defp maybe_remove_report_notifications(result, _) do
+ result
end
def get_user_friends_ap_ids(user) do