From 7c4ef9f15ddec31d6e0d3d2d462a1d898057bc13 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 23 Jul 2020 04:13:06 -0400 Subject: [PATCH] add syncPassword flag to account, update messages, add max_users to public config --- .../main/java/bubble/dao/account/AccountDAO.java | 2 +- .../main/java/bubble/model/account/Account.java | 6 +++++- .../notify/NotificationHandler_sync_password.java | 4 ++++ .../java/bubble/server/BubbleConfiguration.java | 15 +++++++++++++-- .../account/StandardSyncPasswordService.java | 4 ++++ .../V2020072302__add_account_syncpassword.sql | 2 ++ .../server/post_auth/ResourceMessages.properties | 4 ++-- bubble-web | 2 +- 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 bubble-server/src/main/resources/db/migration/V2020072302__add_account_syncpassword.sql 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 7aad6710..da0092e6 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -181,7 +181,7 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc } if (context instanceof Account) { final Account previousState = (Account) context; - if (previousState.isHashedPasswordChanged() && !previousState.skipSyncPassword()) { + if (account.syncPassword() && previousState.isHashedPasswordChanged() && !previousState.skipSyncPassword()) { syncPasswordService.syncPassword(account); } } diff --git a/bubble-server/src/main/java/bubble/model/account/Account.java b/bubble-server/src/main/java/bubble/model/account/Account.java index 1e553558..12245178 100644 --- a/bubble-server/src/main/java/bubble/model/account/Account.java +++ b/bubble-server/src/main/java/bubble/model/account/Account.java @@ -82,7 +82,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx; @Entity @NoArgsConstructor @Accessors(chain=true) @Slf4j public class Account extends IdentifiableBaseParentEntity implements TokenPrincipal, SqlViewSearchResult { - public static final String[] UPDATE_FIELDS = {"url", "description", "autoUpdatePolicy"}; + public static final String[] UPDATE_FIELDS = {"url", "description", "autoUpdatePolicy", "syncPassword"}; public static final String[] ADMIN_UPDATE_FIELDS = ArrayUtil.append(UPDATE_FIELDS, "suspended", "admin"); public static final String[] CREATE_FIELDS = ArrayUtil.append(ADMIN_UPDATE_FIELDS, "name", "termsAgreed", "preferredPlan"); @@ -169,6 +169,10 @@ public class Account extends IdentifiableBaseParentEntity implements TokenPrinci @Getter @Setter private Long termsAgreed; public Account setTermsAgreed() { return setTermsAgreed(now()); } + @ECField(index=130) + @Getter @Setter private Boolean syncPassword; + public boolean syncPassword() { return syncPassword == null ? true : syncPassword; } + @JsonIgnore @Embedded @Getter private HashedPassword hashedPassword; public Account setHashedPassword (HashedPassword newPass) { this.hashedPassword = newPass; diff --git a/bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_password.java b/bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_password.java index 4f42880d..edac1a7a 100644 --- a/bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_password.java +++ b/bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_password.java @@ -35,6 +35,10 @@ public class NotificationHandler_sync_password extends ReceivedNotificationHandl reportError("sync_password: account not found: "+notification.getAccountUuid()); return; } + if (!account.syncPassword()) { + log.info("sync_password: account "+account.getName()+" has syncPassword disabled, not synchronizing"); + return; + } account.getHashedPassword().setHashedPassword(notification.getHashedPassword()); diff --git a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java index 1c3fcebe..77e3a4c0 100644 --- a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java +++ b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java @@ -10,7 +10,11 @@ import bubble.auth.PromoCodePolicy; import bubble.client.BubbleApiClient; import bubble.cloud.CloudServiceDriver; import bubble.dao.account.AccountDAO; +import bubble.dao.bill.AccountPlanDAO; +import bubble.dao.bill.BubblePlanDAO; import bubble.dao.cloud.CloudServiceDAO; +import bubble.model.bill.AccountPlan; +import bubble.model.bill.BubblePlan; import bubble.model.cloud.*; import bubble.model.device.DeviceSecurityLevel; import bubble.server.listener.BubbleFirstTimeListener; @@ -38,7 +42,10 @@ import org.cobbzilla.wizard.cache.redis.HasRedisConfiguration; import org.cobbzilla.wizard.cache.redis.RedisConfiguration; import org.cobbzilla.wizard.client.ApiClientBase; import org.cobbzilla.wizard.server.RestServerHarness; -import org.cobbzilla.wizard.server.config.*; +import org.cobbzilla.wizard.server.config.HasDatabaseConfiguration; +import org.cobbzilla.wizard.server.config.LegalInfo; +import org.cobbzilla.wizard.server.config.PgRestServerConfiguration; +import org.cobbzilla.wizard.server.config.RecaptchaConfig; import org.cobbzilla.wizard.util.ClasspathScanner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -92,6 +99,7 @@ public class BubbleConfiguration extends PgRestServerConfiguration public static final String TAG_RESTORING_IN_PROGRESS = "restoreInProgress"; public static final String TAG_JAR_VERSION = "jarVersion"; public static final String TAG_JAR_UPGRADE_AVAILABLE = "jarUpgradeAvailable"; + public static final String TAG_MAX_USERS = "maxUsers"; public static final String DEFAULT_LOCAL_STORAGE_DIR = HOME_DIR + "/.bubble_local_storage"; @@ -336,6 +344,8 @@ public class BubbleConfiguration extends PgRestServerConfiguration final AccountDAO accountDAO = getBean(AccountDAO.class); final CloudServiceDAO cloudDAO = getBean(CloudServiceDAO.class); final ActivationService activationService = getBean(ActivationService.class); + final AccountPlan accountPlan = thisNetwork == null ? null : getBean(AccountPlanDAO.class).findByNetwork(thisNetwork.getUuid()); + final BubblePlan plan = accountPlan == null ? null : getBean(BubblePlanDAO.class).findByUuid(accountPlan.getPlan()); publicSystemConfigs.set(MapBuilder.build(new Object[][]{ {TAG_ALLOW_REGISTRATION, thisNetwork == null ? null : thisNetwork.getBooleanTag(TAG_ALLOW_REGISTRATION, false)}, @@ -357,7 +367,8 @@ public class BubbleConfiguration extends PgRestServerConfiguration {TAG_SUPPORT, getSupport()}, {TAG_SECURITY_LEVELS, DeviceSecurityLevel.values()}, {TAG_JAR_VERSION, getVersion()}, - {TAG_JAR_UPGRADE_AVAILABLE, getJarUpgradeAvailable() ? getSageVersion() : null} + {TAG_JAR_UPGRADE_AVAILABLE, getJarUpgradeAvailable() ? getSageVersion() : null}, + {TAG_MAX_USERS, plan == null ? null : plan.getMaxAccounts()} })); } else { // some things has to be refreshed all the time in some cases: diff --git a/bubble-server/src/main/java/bubble/service/account/StandardSyncPasswordService.java b/bubble-server/src/main/java/bubble/service/account/StandardSyncPasswordService.java index 1c06e6b8..17067ab1 100644 --- a/bubble-server/src/main/java/bubble/service/account/StandardSyncPasswordService.java +++ b/bubble-server/src/main/java/bubble/service/account/StandardSyncPasswordService.java @@ -39,6 +39,10 @@ public class StandardSyncPasswordService implements SyncPasswordService { log.info("syncPassword: not syncing non-admin password"); return; } + if (!account.syncPassword()) { + log.info("syncPassword: password sync disabled for account: "+account.getName()); + return; + } final AnsibleInstallType installType = thisNetwork.getInstallType(); final SyncPasswordNotification notification = new SyncPasswordNotification(account); if (installType == AnsibleInstallType.sage) { diff --git a/bubble-server/src/main/resources/db/migration/V2020072302__add_account_syncpassword.sql b/bubble-server/src/main/resources/db/migration/V2020072302__add_account_syncpassword.sql new file mode 100644 index 00000000..921268ba --- /dev/null +++ b/bubble-server/src/main/resources/db/migration/V2020072302__add_account_syncpassword.sql @@ -0,0 +1,2 @@ +ALTER TABLE account ADD COLUMN sync_password BOOLEAN; +UPDATE account set sync_password = true; diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties index 9ceea4a0..5d60ee0f 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties @@ -25,9 +25,9 @@ field_label_url=URL field_label_administrator=Administrator field_label_suspended=Suspended field_label_sendWelcomeEmail=Send Welcome Email -field_label_auto_update_policy=Auto-Update Policy +field_label_auto_update_policy=Automatic Upgrades field_label_auto_update_jar=Automatic Updates for Bubble Software -field_label_auto_update_apps=Automatic Updates for Apps +field_label_auto_update_apps=Automatic Updates for VPN Apps button_label_update_profile=Update link_label_change_password=Change Password link_label_account_ssh_keys=Manage SSH Keys diff --git a/bubble-web b/bubble-web index 44dab2f8..74117dcc 160000 --- a/bubble-web +++ b/bubble-web @@ -1 +1 @@ -Subproject commit 44dab2f86b4922d22099ef2330c083f84879d918 +Subproject commit 74117dccae90c8905c8f4f54d16fcf19ce5eb27e