summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2022-03-20 18:13:19 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2022-03-20 18:13:19 +0000
commitb76340511d52bb2db50e40de4bc513b3117799e0 (patch)
treef72d71a0c32324f5b97b9a614bdba4c183e76dea /lib
parent2db640632b81fb435456e4b3cc79901d02d7135c (diff)
parentcdc5bbe8369d4fc66d642bb3e845a237d11e34d7 (diff)
downloadpleroma-b76340511d52bb2db50e40de4bc513b3117799e0.tar.gz
pleroma-b76340511d52bb2db50e40de4bc513b3117799e0.zip
Merge branch 'delete_report_notifs_when_demoting_from_superuser' into 'develop'
Delete report notifs when demoting from superuser Closes #2840 See merge request pleroma/pleroma!3642
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/notification.ex8
-rw-r--r--lib/pleroma/user.ex16
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 41385884b..52fd2656b 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 562581be4..65f0dfc70 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1127,10 +1127,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