Correctly purge a remote user
This commit is contained in:
parent
b221d77a6d
commit
be2da95c36
|
@ -1713,6 +1713,12 @@ def purge_user_changeset(user) do
|
|||
})
|
||||
end
|
||||
|
||||
def purge(%User{} = user) do
|
||||
user
|
||||
|> purge_user_changeset()
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
|
||||
def delete(users) when is_list(users) do
|
||||
for user <- users, do: delete(user)
|
||||
end
|
||||
|
@ -1726,9 +1732,9 @@ defp delete_and_invalidate_cache(%User{} = user) do
|
|||
Repo.delete(user)
|
||||
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)
|
||||
|
||||
case status do
|
||||
|
@ -1739,9 +1745,7 @@ defp delete_or_deactivate(%User{local: true} = user) do
|
|||
delete_and_invalidate_cache(user)
|
||||
|
||||
_ ->
|
||||
user
|
||||
|> purge_user_changeset()
|
||||
|> update_and_set_cache()
|
||||
purge(user)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1769,7 +1773,7 @@ def perform(:delete, %User{} = user) do
|
|||
|
||||
delete_outgoing_pending_follow_requests(user)
|
||||
|
||||
delete_or_deactivate(user)
|
||||
delete_or_purge(user)
|
||||
end
|
||||
|
||||
def perform(:set_activation_async, user, status), do: set_activation(user, status)
|
||||
|
|
|
@ -1684,6 +1684,24 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
|
|||
} = user
|
||||
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
|
||||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue