diff options
author | Ilja <ilja@ilja.space> | 2022-03-06 17:36:30 +0100 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2022-11-27 04:20:11 +0100 |
commit | 4504c810802e2253599f06ddf6d58d3389fb23ac (patch) | |
tree | 9dcc475de42a41c4183e844fd285df0fa7d86650 /lib | |
parent | 508b438b535bbd7b691661ad17e7005cb6b4cc68 (diff) | |
download | pleroma-4504c810802e2253599f06ddf6d58d3389fb23ac.tar.gz pleroma-4504c810802e2253599f06ddf6d58d3389fb23ac.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.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/user.ex | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 7efbdc49a..71f57e6b2 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -328,6 +328,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 62506f37a..03c5f91cc 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1087,10 +1087,24 @@ 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, true) do + if 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 |