From 1c2454a3f2a5c290d23e2bd12e3abbf5793d90dd Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Wed, 2 Dec 2020 17:18:21 -0500 Subject: [PATCH] validate preferred plan before creation --- .../src/main/java/bubble/dao/account/AccountDAO.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java index f9e7e091..df8952ac 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -10,6 +10,7 @@ import bubble.dao.account.message.AccountMessageDAO; import bubble.dao.app.*; import bubble.dao.bill.AccountPaymentArchivedDAO; import bubble.dao.bill.BillDAO; +import bubble.dao.bill.BubblePlanDAO; import bubble.dao.cloud.BubbleDomainDAO; import bubble.dao.cloud.BubbleFootprintDAO; import bubble.dao.cloud.BubbleNetworkDAO; @@ -71,6 +72,7 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc @Autowired private AppDataDAO dataDAO; @Autowired private AppMessageDAO appMessageDAO; @Autowired private RuleDriverDAO driverDAO; + @Autowired private BubblePlanDAO planDAO; @Autowired private BubbleDomainDAO domainDAO; @Autowired private CloudServiceDAO cloudDAO; @Autowired private BubbleFootprintDAO footprintDAO; @@ -113,6 +115,13 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc account.setShowBlockStats(account.showBlockStats()); // ensure non-null account.setSync(account.sync()); // ensure non-null + // ensure the preferred plan exists, if set + if (account.hasPreferredPlan()) { + final BubblePlan prefPlan = planDAO.findById(account.getPreferredPlan()); + if (prefPlan == null) throw invalidEx("err.preferredPlan.notFound", "Preferred plan not found: "+account.getPreferredPlan(), account.getPreferredPlan()); + account.setPreferredPlan(prefPlan.getUuid()); + } + // check account limit for plan, if there is a plan final BubblePlan plan = selfNodeService.getThisPlan(); if (plan != null && plan.hasMaxAccounts()) {