From a4c1c678a283bd3b837c19de23cd68a3c05369c6 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 10 Dec 2020 19:38:24 -0500 Subject: [PATCH] fix userApps population when user is template owner --- bubble-server/src/main/java/bubble/model/app/BubbleApp.java | 5 +++++ .../main/java/bubble/service/dbfilter/EntityIterator.java | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/main/java/bubble/model/app/BubbleApp.java b/bubble-server/src/main/java/bubble/model/app/BubbleApp.java index dc8ccedd..542b2250 100644 --- a/bubble-server/src/main/java/bubble/model/app/BubbleApp.java +++ b/bubble-server/src/main/java/bubble/model/app/BubbleApp.java @@ -118,6 +118,11 @@ public class BubbleApp extends IdentifiableBaseParentEntity implements AccountTe @ECField(index=70) @Column(length=UUID_MAXLEN, updatable=false) @Getter @Setter private String templateApp; + public boolean hasTemplateApp() { return !empty(templateApp); } + + public String getTemplateAppOrSelf() { + return hasTemplateApp() ? templateApp : template() ? getUuid() : null; + } @ECSearchable @ECField(index=80) @ECIndex @Column(nullable=false) diff --git a/bubble-server/src/main/java/bubble/service/dbfilter/EntityIterator.java b/bubble-server/src/main/java/bubble/service/dbfilter/EntityIterator.java index b4e33295..7173255c 100644 --- a/bubble-server/src/main/java/bubble/service/dbfilter/EntityIterator.java +++ b/bubble-server/src/main/java/bubble/service/dbfilter/EntityIterator.java @@ -203,7 +203,7 @@ public abstract class EntityIterator implements Iterator { // only copy enabled apps, make them templates if (log.isDebugEnabled()) log.debug("addEntities: starting with planApps="+json(planApps.stream().map(BubblePlanApp::getApp).collect(Collectors.toList()))); userApps = new ArrayList<>(); - entities.stream().filter(app -> planAppEnabled(((BubbleApp) app).getTemplateApp(), planApps)) + entities.stream().filter(app -> planAppEnabled(((BubbleApp) app).getTemplateAppOrSelf(), planApps)) .map(app -> ((BubbleApp) app).setTemplate(true)) .forEach(app -> { userApps.add(app); // save these for later, we will need them when copying BubblePlanApps below @@ -229,7 +229,7 @@ public abstract class EntityIterator implements Iterator { .filter(app -> app.getTemplateApp().equals(systemPlanApp.getApp())) .findFirst().orElse(null); if (userApp == null) { - if (log.isInfoEnabled()) log.info("addEntities: system BubblePlanApp " + systemPlanApp.getUuid() + ": no matching BubbleApp not found in userApps (not adding): " + names(userApps)); + if (log.isInfoEnabled()) log.info("addEntities: system BubblePlanApp " + systemPlanApp.getUuid() + ": no matching BubbleApp found in userApps (not adding): " + names(userApps)); } else { // systemPlanApp will now be associated with "root"'s BubblePlan, but user's BubbleApp if (log.isInfoEnabled()) log.info("addEntities: rewrote app for " + systemPlanApp.getUuid() + " -> " + userApp.getName() + "/" + userApp.getUuid());