Revert "Delete report notifs when demoting from superuser"
This reverts commit 4504c81080
.
This commit is contained in:
parent
7d68d64d63
commit
3fbd42061c
@ -338,14 +338,6 @@ defmodule Pleroma.Notification do
|
|||||||
|> Repo.delete_all()
|
|> Repo.delete_all()
|
||||||
end
|
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
|
def dismiss(%Pleroma.Activity{} = activity) do
|
||||||
Notification
|
Notification
|
||||||
|> where([n], n.activity_id == ^activity.id)
|
|> where([n], n.activity_id == ^activity.id)
|
||||||
|
@ -1202,24 +1202,10 @@ defmodule Pleroma.User do
|
|||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do
|
def update_and_set_cache(changeset) do
|
||||||
was_superuser_before_update = User.superuser?(user)
|
|
||||||
|
|
||||||
with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do
|
with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do
|
||||||
set_cache(user)
|
set_cache(user)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def get_user_friends_ap_ids(user) do
|
def get_user_friends_ap_ids(user) do
|
||||||
|
@ -548,25 +548,6 @@ defmodule Pleroma.NotificationTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "destroy_multiple_from_types/2" do
|
|
||||||
test "clears all notifications of a certain type for a given user" do
|
|
||||||
report_activity = insert(:report_activity)
|
|
||||||
user1 = insert(:user, is_moderator: true, is_admin: true)
|
|
||||||
user2 = insert(:user, is_moderator: true, is_admin: true)
|
|
||||||
{:ok, _} = Notification.create_notifications(report_activity)
|
|
||||||
|
|
||||||
{:ok, _} =
|
|
||||||
CommonAPI.post(user2, %{
|
|
||||||
status: "hey @#{user1.nickname} !"
|
|
||||||
})
|
|
||||||
|
|
||||||
Notification.destroy_multiple_from_types(user1, ["pleroma:report"])
|
|
||||||
|
|
||||||
assert [%Pleroma.Notification{type: "mention"}] = Notification.for_user(user1)
|
|
||||||
assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "set_read_up_to()" do
|
describe "set_read_up_to()" do
|
||||||
test "it sets all notifications as read up to a specified notification ID" do
|
test "it sets all notifications as read up to a specified notification ID" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
defmodule Pleroma.UserTest do
|
defmodule Pleroma.UserTest do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Builders.UserBuilder
|
alias Pleroma.Builders.UserBuilder
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
@ -2461,26 +2460,6 @@ defmodule Pleroma.UserTest do
|
|||||||
assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||||
assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
|
assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "removes report notifs when user isn't superuser any more" do
|
|
||||||
report_activity = insert(:report_activity)
|
|
||||||
user = insert(:user, is_moderator: true, is_admin: true)
|
|
||||||
{:ok, _} = Notification.create_notifications(report_activity)
|
|
||||||
|
|
||||||
assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
|
|
||||||
|
|
||||||
{:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
|
|
||||||
# is still superuser because still admin
|
|
||||||
assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
|
|
||||||
|
|
||||||
{:ok, user} = user |> User.admin_api_update(%{is_moderator: true, is_admin: false})
|
|
||||||
# is still superuser because still moderator
|
|
||||||
assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
|
|
||||||
|
|
||||||
{:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
|
|
||||||
# is not a superuser any more
|
|
||||||
assert [] = Notification.for_user(user)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "following/followers synchronization" do
|
describe "following/followers synchronization" do
|
||||||
|
Loading…
Reference in New Issue
Block a user