Correctly purge a remote user

This commit is contained in:
Alex Gleason 2021-06-29 21:45:38 -05:00
parent b221d77a6d
commit be2da95c36
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 28 additions and 6 deletions

View File

@ -1713,6 +1713,12 @@ defmodule Pleroma.User do
}) })
end end
def purge(%User{} = user) do
user
|> purge_user_changeset()
|> update_and_set_cache()
end
def delete(users) when is_list(users) do def delete(users) when is_list(users) do
for user <- users, do: delete(user) for user <- users, do: delete(user)
end end
@ -1726,9 +1732,9 @@ defmodule Pleroma.User do
Repo.delete(user) Repo.delete(user)
end end
defp delete_or_deactivate(%User{local: false} = user), do: delete_and_invalidate_cache(user) defp delete_or_purge(%User{local: false} = user), do: purge(user)
defp delete_or_deactivate(%User{local: true} = user) do defp delete_or_purge(%User{local: true} = user) do
status = account_status(user) status = account_status(user)
case status do case status do
@ -1739,9 +1745,7 @@ defmodule Pleroma.User do
delete_and_invalidate_cache(user) delete_and_invalidate_cache(user)
_ -> _ ->
user purge(user)
|> purge_user_changeset()
|> update_and_set_cache()
end end
end end
@ -1769,7 +1773,7 @@ defmodule Pleroma.User do
delete_outgoing_pending_follow_requests(user) delete_outgoing_pending_follow_requests(user)
delete_or_deactivate(user) delete_or_purge(user)
end end
def perform(:set_activation_async, user, status), do: set_activation(user, status) def perform(:set_activation_async, user, status), do: set_activation(user, status)

View File

@ -1684,6 +1684,24 @@ defmodule Pleroma.UserTest do
} = user } = user
end end
test "delete/1 purges a remote user" do
user =
insert(:user, %{
name: "qqqqqqq",
avatar: %{"a" => "b"},
banner: %{"a" => "b"},
local: false
})
{:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job)
user = User.get_by_id(user.id)
assert user.name == nil
assert user.avatar == %{}
assert user.banner == %{}
end
test "get_public_key_for_ap_id fetches a user that's not in the db" do test "get_public_key_for_ap_id fetches a user that's not in the db" do
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin") assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end end