forked from AkkomaGang/akkoma
Deletions: preserve account status fields during purge, fix checks
This commit is contained in:
parent
01c2d2a296
commit
a7929c4d89
2 changed files with 14 additions and 12 deletions
|
@ -1692,9 +1692,7 @@ def purge_user_changeset(user) do
|
||||||
follower_count: 0,
|
follower_count: 0,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
is_locked: false,
|
is_locked: false,
|
||||||
is_confirmed: true,
|
|
||||||
password_reset_pending: false,
|
password_reset_pending: false,
|
||||||
is_approved: true,
|
|
||||||
registration_reason: nil,
|
registration_reason: nil,
|
||||||
confirmation_token: nil,
|
confirmation_token: nil,
|
||||||
domain_blocks: [],
|
domain_blocks: [],
|
||||||
|
@ -1710,9 +1708,15 @@ def purge_user_changeset(user) do
|
||||||
raw_fields: [],
|
raw_fields: [],
|
||||||
is_discoverable: false,
|
is_discoverable: false,
|
||||||
also_known_as: []
|
also_known_as: []
|
||||||
|
# id: preserved
|
||||||
|
# ap_id: preserved
|
||||||
|
# nickname: preserved
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Purge doesn't delete the user from the database.
|
||||||
|
# It just nulls all its fields and deactivates it.
|
||||||
|
# See `User.purge_user_changeset/1` above.
|
||||||
def purge(%User{} = user) do
|
def purge(%User{} = user) do
|
||||||
user
|
user
|
||||||
|> purge_user_changeset()
|
|> purge_user_changeset()
|
||||||
|
@ -1729,20 +1733,18 @@ def delete(%User{} = user) do
|
||||||
BackgroundWorker.enqueue("delete_user", %{"user_id" => user.id})
|
BackgroundWorker.enqueue("delete_user", %{"user_id" => user.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# *Actually* delete the user from the DB
|
||||||
defp delete_from_db(%User{} = user) do
|
defp delete_from_db(%User{} = user) do
|
||||||
invalidate_cache(user)
|
invalidate_cache(user)
|
||||||
Repo.delete(user)
|
Repo.delete(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_delete_from_db(%User{local: true} = user) do
|
# If the user never finalized their account, it's safe to delete them.
|
||||||
status = account_status(user)
|
defp maybe_delete_from_db(%User{local: true, is_confirmed: false} = user),
|
||||||
|
do: delete_from_db(user)
|
||||||
|
|
||||||
if status in [:confirmation_pending, :approval_pending] do
|
defp maybe_delete_from_db(%User{local: true, is_approved: false} = user),
|
||||||
delete_from_db(user)
|
do: delete_from_db(user)
|
||||||
else
|
|
||||||
{:ok, user}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_delete_from_db(user), do: {:ok, user}
|
defp maybe_delete_from_db(user), do: {:ok, user}
|
||||||
|
|
||||||
|
|
|
@ -1663,9 +1663,9 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
|
||||||
follower_count: 0,
|
follower_count: 0,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
is_locked: false,
|
is_locked: false,
|
||||||
is_confirmed: true,
|
is_confirmed: false,
|
||||||
password_reset_pending: false,
|
password_reset_pending: false,
|
||||||
is_approved: true,
|
is_approved: false,
|
||||||
registration_reason: nil,
|
registration_reason: nil,
|
||||||
confirmation_token: nil,
|
confirmation_token: nil,
|
||||||
domain_blocks: [],
|
domain_blocks: [],
|
||||||
|
|
Loading…
Reference in a new issue