diff --git a/bubble-server/src/main/java/bubble/ApiConstants.java b/bubble-server/src/main/java/bubble/ApiConstants.java index 613ba000..ff54dc3f 100644 --- a/bubble-server/src/main/java/bubble/ApiConstants.java +++ b/bubble-server/src/main/java/bubble/ApiConstants.java @@ -143,6 +143,7 @@ public class ApiConstants { public static final String EP_DOMAINS = DOMAINS_ENDPOINT; public static final String EP_NETWORKS = "/networks"; public static final String EP_PLANS = PLANS_ENDPOINT; + public static final String EP_CURRENT_PLANS = "/currentPlans"; public static final String EP_TAGS = "/tags"; public static final String EP_NODES = "/nodes"; public static final String EP_DEVICES = "/devices"; 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 5fb85716..f7178498 100644 --- a/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java +++ b/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java @@ -17,17 +17,14 @@ import bubble.model.account.message.ActionTarget; import bubble.model.cloud.BubbleNetwork; import bubble.model.device.BubbleDeviceType; import bubble.resources.app.AppsResource; -import bubble.resources.bill.AccountPaymentMethodsResource; -import bubble.resources.bill.AccountPaymentsResource; -import bubble.resources.bill.AccountPlansResource; -import bubble.resources.bill.BillsResource; +import bubble.resources.bill.*; import bubble.resources.cloud.*; import bubble.resources.driver.DriversResource; import bubble.resources.notify.ReceivedNotificationsResource; import bubble.resources.notify.SentNotificationsResource; import bubble.server.BubbleConfiguration; -import bubble.service.account.StandardAuthenticatorService; import bubble.service.account.MitmControlService; +import bubble.service.account.StandardAuthenticatorService; import bubble.service.account.download.AccountDownloadService; import bubble.service.boot.SelfNodeService; import bubble.service.cloud.StandardNetworkService; @@ -536,12 +533,19 @@ public class AccountsResource { } @Path("/{id}"+EP_PLANS) - public AccountPlansResource getPlans(@Context ContainerRequest ctx, - @PathParam("id") String id) { + public AccountPlansResource getAllPlans(@Context ContainerRequest ctx, + @PathParam("id") String id) { final AccountContext c = new AccountContext(ctx, id); return configuration.subResource(AccountPlansResource.class, c.account); } + @Path("/{id}"+EP_CURRENT_PLANS) + public CurrentAccountPlansResource getCurrentPlans(@Context ContainerRequest ctx, + @PathParam("id") String id) { + final AccountContext c = new AccountContext(ctx, id); + return configuration.subResource(CurrentAccountPlansResource.class, c.account); + } + @Path("/{id}"+EP_KEYS) public AccountSshKeysResource getSshKeys(@Context ContainerRequest ctx, @PathParam("id") String id) { diff --git a/bubble-server/src/main/java/bubble/resources/account/MeResource.java b/bubble-server/src/main/java/bubble/resources/account/MeResource.java index 0d483bb9..a4dd85af 100644 --- a/bubble-server/src/main/java/bubble/resources/account/MeResource.java +++ b/bubble-server/src/main/java/bubble/resources/account/MeResource.java @@ -17,10 +17,7 @@ import bubble.model.account.message.AccountMessageType; import bubble.model.account.message.ActionTarget; import bubble.model.device.BubbleDeviceType; import bubble.resources.app.AppsResource; -import bubble.resources.bill.AccountPaymentMethodsResource; -import bubble.resources.bill.AccountPaymentsResource; -import bubble.resources.bill.AccountPlansResource; -import bubble.resources.bill.BillsResource; +import bubble.resources.bill.*; import bubble.resources.cloud.*; import bubble.resources.driver.DriversResource; import bubble.resources.notify.ReceivedNotificationsResource; @@ -300,11 +297,17 @@ public class MeResource { } @Path(EP_PLANS) - public AccountPlansResource getPlans(@Context ContainerRequest ctx) { + public AccountPlansResource getAllPlans(@Context ContainerRequest ctx) { final Account caller = userPrincipal(ctx); return configuration.subResource(AccountPlansResource.class, caller); } + @Path(EP_CURRENT_PLANS) + public CurrentAccountPlansResource getCurrentPlans(@Context ContainerRequest ctx) { + final Account caller = userPrincipal(ctx); + return configuration.subResource(CurrentAccountPlansResource.class, caller); + } + @Path(EP_KEYS) public AccountSshKeysResource getSshKeys(@Context ContainerRequest ctx) { final Account caller = userPrincipal(ctx); diff --git a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java index 730e3909..9c57b49c 100644 --- a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java +++ b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java @@ -51,7 +51,7 @@ public class AccountPlansResource extends AccountOwnedResource list(ContainerRequest ctx) { - return getDao().findByAccountAndNotDeleted(account.getUuid()); - } - - @Override protected AccountPlan find(ContainerRequest ctx, String id) { - return getDao().findByAccountAndIdAndNotDeleted(getAccountUuid(ctx), id); - } - @Override protected AccountPlan findAlternate(ContainerRequest ctx, String id) { // id might be a network uuid final String accountUuid = getAccountUuid(ctx); final BubbleNetwork network = networkDAO.findByAccountAndId(accountUuid, id); - return network == null ? null : getDao().findByAccountAndNetworkAndNotDeleted(accountUuid, network.getUuid()); + return network == null ? null : getDao().findByAccountAndNetwork(accountUuid, network.getUuid()); } @Override protected boolean canCreate(Request req, ContainerRequest ctx, Account caller, AccountPlan request) { diff --git a/bubble-server/src/main/java/bubble/resources/bill/CurrentAccountPlansResource.java b/bubble-server/src/main/java/bubble/resources/bill/CurrentAccountPlansResource.java new file mode 100644 index 00000000..5f1043c5 --- /dev/null +++ b/bubble-server/src/main/java/bubble/resources/bill/CurrentAccountPlansResource.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2020 Bubble, Inc. All rights reserved. + * For personal (non-commercial) use, see license: https://bubblev.com/bubble-license/ + */ +package bubble.resources.bill; + +import bubble.model.account.Account; +import bubble.model.bill.AccountPlan; +import bubble.model.cloud.BubbleNetwork; +import org.glassfish.grizzly.http.server.Request; +import org.glassfish.jersey.server.ContainerRequest; + +import java.util.List; + +public class CurrentAccountPlansResource extends AccountPlansResource { + + public CurrentAccountPlansResource(Account account) { super(account); } + + @Override protected List list(ContainerRequest ctx) { + return getDao().findByAccountAndNotDeleted(account.getUuid()); + } + + @Override protected AccountPlan find(ContainerRequest ctx, String id) { + return getDao().findByAccountAndIdAndNotDeleted(getAccountUuid(ctx), id); + } + + @Override protected AccountPlan findAlternate(ContainerRequest ctx, String id) { + // id might be a network uuid + final String accountUuid = getAccountUuid(ctx); + final BubbleNetwork network = networkDAO.findByAccountAndId(accountUuid, id); + return network == null ? null : getDao().findByAccountAndNetworkAndNotDeleted(accountUuid, network.getUuid()); + } + + @Override protected boolean canCreate(Request req, ContainerRequest ctx, Account caller, AccountPlan request) { + return false; + } + + @Override protected boolean canUpdate(ContainerRequest ctx, Account caller, AccountPlan found, AccountPlan request) { + return false; + } + + @Override protected boolean canDelete(ContainerRequest ctx, Account caller, AccountPlan found) { + return false; + } + +} diff --git a/bubble-server/src/test/resources/models/tests/payment/pay_credit_refund_and_restart.json b/bubble-server/src/test/resources/models/tests/payment/pay_credit_refund_and_restart.json index a0b3bfd9..ae6ff4b1 100644 --- a/bubble-server/src/test/resources/models/tests/payment/pay_credit_refund_and_restart.json +++ b/bubble-server/src/test/resources/models/tests/payment/pay_credit_refund_and_restart.json @@ -224,8 +224,8 @@ }, { - "comment": "verify no plans exist", - "request": { "uri": "me/plans" }, + "comment": "verify no current plans exist", + "request": { "uri": "me/currentPlans" }, "response": { "check": [ {"condition": "json.length === 0"} ] } diff --git a/bubble-web b/bubble-web index fce6adf4..d0617bba 160000 --- a/bubble-web +++ b/bubble-web @@ -1 +1 @@ -Subproject commit fce6adf44d1ea052deebf19ed6c964447c4af9b7 +Subproject commit d0617bbadd003f5b65f1d712b5a84aa527ee841d