From 8b8265e425f08ee69d0501efcb1e422923b79514 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 7 Jan 2021 13:29:47 -0500 Subject: [PATCH] root-delete-account no longer fails due to unpaid bills --- .../bubble/resources/account/AccountsResource.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java b/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java index 2e92bdd9..c2c86e43 100644 --- a/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java +++ b/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java @@ -9,11 +9,14 @@ import bubble.dao.SessionDAO; import bubble.dao.account.AccountDAO; import bubble.dao.account.AccountPolicyDAO; import bubble.dao.account.message.AccountMessageDAO; +import bubble.dao.bill.BillDAO; import bubble.model.account.*; import bubble.model.account.message.AccountAction; import bubble.model.account.message.AccountMessage; import bubble.model.account.message.AccountMessageType; import bubble.model.account.message.ActionTarget; +import bubble.model.bill.Bill; +import bubble.model.bill.BillStatus; import bubble.model.cloud.BubbleNetwork; import bubble.model.device.BubbleDeviceType; import bubble.resources.app.AppsResource; @@ -57,6 +60,7 @@ import static bubble.model.account.Account.*; import static bubble.resources.account.AuthResource.forgotPasswordMessage; import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON; import static org.cobbzilla.util.http.HttpStatusCodes.*; +import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.wizard.resources.ResourceUtil.*; import static org.cobbzilla.wizard.server.config.OpenApiConfiguration.API_TAG_UTILITY; import static org.cobbzilla.wizard.server.config.OpenApiConfiguration.SEC_API_KEY; @@ -76,6 +80,7 @@ public class AccountsResource { @Autowired private StandardAuthenticatorService authenticatorService; @Autowired private SelfNodeService selfNodeService; @Autowired private SessionDAO sessionDAO; + @Autowired private BillDAO billDAO; @GET @Operation(security=@SecurityRequirement(name=SEC_API_KEY), @@ -620,6 +625,12 @@ public class AccountsResource { .setAccount(c.account.getUuid()) .setDeletionPolicy(AccountDeletionPolicy.full_delete)); } + } else { + // admin is deleting an account, ensure it has no unpaid bills that + // would prevent deletion (err.delete.unpaidBills) + final List unpaid = billDAO.findUnpaidByAccount(c.account.getUuid()); + log.warn("rootDeleteUser: before deleting user, marking these unpaid bills as paid: "+json(unpaid)); + for (Bill bill : unpaid) billDAO.update(bill.setStatus(BillStatus.paid)); } accountDAO.delete(c.account.getUuid()); return ok(c.account);