Просмотр исходного кода

cannot delete account with unpaid bills

tags/v0.3.0
Jonathan Cobb 5 лет назад
Родитель
Сommit
8b23ff1684
3 измененных файлов: 13 добавлений и 1 удалений
  1. +8
    -1
      bubble-server/src/main/java/bubble/dao/account/AccountDAO.java
  2. +4
    -0
      bubble-server/src/main/java/bubble/dao/bill/BillDAO.java
  3. +1
    -0
      bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties

+ 8
- 1
bubble-server/src/main/java/bubble/dao/account/AccountDAO.java Просмотреть файл

@@ -3,6 +3,7 @@ package bubble.dao.account;
import bubble.cloud.CloudServiceDriver;
import bubble.dao.account.message.AccountMessageDAO;
import bubble.dao.app.*;
import bubble.dao.bill.BillDAO;
import bubble.dao.cloud.AnsibleRoleDAO;
import bubble.dao.cloud.BubbleDomainDAO;
import bubble.dao.cloud.BubbleFootprintDAO;
@@ -10,6 +11,7 @@ import bubble.dao.cloud.CloudServiceDAO;
import bubble.dao.device.DeviceDAO;
import bubble.model.account.*;
import bubble.model.app.*;
import bubble.model.bill.Bill;
import bubble.model.cloud.*;
import bubble.server.BubbleConfiguration;
import bubble.service.boot.SelfNodeService;
@@ -56,6 +58,7 @@ public class AccountDAO extends AbstractCRUDDAO<Account> implements SqlViewSearc
@Autowired private AccountMessageDAO messageDAO;
@Autowired private DeviceDAO deviceDAO;
@Autowired private SelfNodeService selfNodeService;
@Autowired private BillDAO billDAO;

public Account newAccount(Request req, AccountRegistration request, Account parent) {
return create(new Account(request)
@@ -238,7 +241,11 @@ public class AccountDAO extends AbstractCRUDDAO<Account> implements SqlViewSearc
throw invalidEx("err.delete.invalid", "cannot delete account ("+account.getUuid()+") that owns current network ("+configuration.getThisNetwork().getUuid()+")", account.getUuid());
}

// todo: cannot delete an account that has unpaid bills
// cannot delete account with unpaid bills
final List<Bill> unpaid = billDAO.findUnpaidByAccount(uuid);
if (!unpaid.isEmpty()) {
throw invalidEx("err.delete.unpaidBills", "cannot delete account ("+account.getUuid()+") with "+unpaid.size()+" unpaid bills", account.getUuid());
}

final AccountPolicy policy = policyDAO.findSingleByAccount(uuid);



+ 4
- 0
bubble-server/src/main/java/bubble/dao/bill/BillDAO.java Просмотреть файл

@@ -28,6 +28,10 @@ public class BillDAO extends AccountOwnedEntityDAO<Bill> {
return findByFields("accountPlan", accountPlanUuid, "status", BillStatus.unpaid);
}

public List<Bill> findUnpaidByAccount(String accountUuid) {
return findByFields("account", accountUuid, "status", BillStatus.unpaid);
}

public Bill createFirstBill(BubblePlan plan, AccountPlan accountPlan) {
return create(newBill(plan, accountPlan, accountPlan.getCtime()));
}


+ 1
- 0
bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties Просмотреть файл

@@ -474,6 +474,7 @@ err.delegatedPayment.notDelegated=Error locating payment service
err.delegatedPayment.delegateNotFound=Error locating payment service
err.delete.cannotDeleteSelf=You cannot delete yourself (you've still got a chance to win)
err.delete.invalid=You cannot delete the account that owns the current network
err.delete.unpaidBills=Cannot delete account with unpaid bills
err.deletionPolicy.required=Deletion policy is required
err.description.length=Description is too long
err.deviceDir.notFound=Device status directory not found


Загрузка…
Отмена
Сохранить