Verified Commit be2da95c authored by Alex Gleason's avatar Alex Gleason
Browse files

Correctly purge a remote user

parent b221d77a
...@@ -1713,6 +1713,12 @@ def purge_user_changeset(user) do ...@@ -1713,6 +1713,12 @@ def purge_user_changeset(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 @@ defp delete_and_invalidate_cache(%User{} = user) do ...@@ -1726,9 +1732,9 @@ defp delete_and_invalidate_cache(%User{} = 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 @@ defp delete_or_deactivate(%User{local: true} = user) do ...@@ -1739,9 +1745,7 @@ defp delete_or_deactivate(%User{local: true} = 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 @@ def perform(:delete, %User{} = user) do ...@@ -1769,7 +1773,7 @@ def perform(:delete, %User{} = 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)
......
...@@ -1684,6 +1684,24 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do ...@@ -1684,6 +1684,24 @@ test "delete/1 purges a user when they wouldn't be fully deleted" 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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment