Permanently delete never-paid VMs + super-admin VM purge#176
Open
v0l wants to merge 1 commit into
Open
Conversation
Never-paid (new) VMs are now hard-deleted from the database instead of
soft-deleted, both in the worker's unpaid-VM cleanup and in admin deletes.
Adds a super_admin-only `purge` flag to DELETE /api/admin/v1/vms/{id} to
permanently delete any VM (including ones with payment history), clearing
up all related entities.
- New LNVpsDb::hard_delete_vm removes the VM plus vm_history, vm_firewall_rule,
vm_ip_assignment, and the VM's subscription (line items + payment history)
- WorkJob::DeleteVm gains a purge flag; worker skips vm_history logging on
hard delete (the row is gone)
- AdminAuth::is_super_admin gates the purge flag (403 for non-super-admins)
- Tests: mock + provisioner purge coverage, updated worker cleanup asserts,
e2e RBAC purge-forbidden test + delete_auth_body helper
- Docs: API_CHANGELOG.md + ADMIN_API_ENDPOINTS.md
Fixes #168
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #168
Summary
VMs that have never been paid (their subscription was never set up) are now hard-deleted from the database instead of soft-deleted, both when an admin deletes them and in the worker's hourly unpaid-VM cleanup. Nothing is left behind.
Additionally, super_admins can permanently purge any VM (including ones with payment history) via a new
purgeflag on the delete endpoint — intended for clearing out test VMs.Changes
LNVpsDb::hard_delete_vm(vm_id)(mysql + mock) — removes the VM row plus every related record in one transaction:vm_history,vm_firewall_rule,vm_ip_assignment, and the VM's ownsubscription(+ cascadedsubscription_line_item) and itssubscription_paymenthistory (payments deleted first, since they lackON DELETE CASCADE).WorkJob::DeleteVmgains apurgeflag. The worker computeshard_delete = purge || !ever_paidand skipsvm_historylogging on hard delete (the row is gone → would break the FK).provisioner.delete_vm(vm_id, purge)picks hard vs soft delete.DELETE /api/admin/v1/vms/{id}accepts optionalpurge: true, gated to thesuper_adminrole via newAdminAuth::is_super_admin(checked before the VM lookup, so non-super-admins get403).Tests
test_hard_delete_vm_purges_related_records(mock DB) — full cleanuptest_delete_vm_purge_removes_vm_row(provisioner) — purge removes VM row & hard-deletes IPstest_vm_manager_cannot_purge_vm(e2e RBAC) — non-super-admin purge →403, plus newdelete_auth_bodyclient helperDocs
API_CHANGELOG.mdandADMIN_API_ENDPOINTS.mdupdated for thepurgeflag / new behaviourAll builds pass (
cargo build --workspace), formatting is clean, and unit tests pass forlnvps_db,lnvps_api,lnvps_api_admin, andlnvps_api_common. The mysqlhard_delete_vmand admin endpoint are additionally covered by the e2e suite.