From c15931b95aaf8ef5256ea1c25474a71e8bea1c88 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Wed, 18 Dec 2019 21:44:21 -0500 Subject: [PATCH] toggle auth flags --- .../java/bubble/model/account/AccountContact.java | 11 ++++++----- .../bubble/resources/account/AccountsResource.java | 9 ++++++++- .../en_US/post_auth/ResourceMessages.properties | 1 - bubble-web | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bubble-server/src/main/java/bubble/model/account/AccountContact.java b/bubble-server/src/main/java/bubble/model/account/AccountContact.java index 6b9cd45f..83f50444 100644 --- a/bubble-server/src/main/java/bubble/model/account/AccountContact.java +++ b/bubble-server/src/main/java/bubble/model/account/AccountContact.java @@ -31,9 +31,15 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx; public class AccountContact implements Serializable { public static final int MAX_NICK_LENGTH = 100; + public static final String[] UPDATE_EXCLUDE_FIELDS = {"uuid", "type", "info"}; public AccountContact(AccountContact other) { copy(this, other); } + public AccountContact update(AccountContact other) { + copy(this, other, null, UPDATE_EXCLUDE_FIELDS); + return this; + } + @Getter @Setter private String uuid = randomUUID().toString(); public boolean hasUuid () { return !empty(uuid); } public AccountContact initUuid () { uuid = randomUUID().toString(); return this; } @@ -78,11 +84,6 @@ public class AccountContact implements Serializable { final List errors = c.getType().validate(c.getInfo()); if (errors != null && !errors.isEmpty()) throw invalidEx(errors); - // there must be at least one contact that can be used to unlock the network - if (!c.requiredForNetworkUnlock() && (contacts == null || Arrays.stream(contacts).noneMatch(AccountContact::requiredForNetworkUnlock))) { - throw invalidEx("err.requiredForNetworkUnlock.atLeastOneNetworkUnlockContactRequired"); - } - if (c.isAuthenticator()) { final AccountContact auth = findAuthenticator(contacts); if (auth != null && !auth.getUuid().equals(c.getUuid())) { 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 75ff4caf..79879a0d 100644 --- a/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java +++ b/bubble-server/src/main/java/bubble/resources/account/AccountsResource.java @@ -147,7 +147,14 @@ public class AccountsResource { final AccountPolicy policy = policyDAO.findSingleByAccount(c.account.getUuid()); final AccountContact existing = policy.findContact(contact); - if (existing != null && existing.isAuthenticator()) return invalid("err.authenticator.configured"); + if (existing != null) { + if (existing.isAuthenticator()) return invalid("err.authenticator.configured"); + + // if it already exists, these fields cannot be changed + contact.setUuid(existing.getUuid()); + contact.setType(existing.getType()); + contact.setInfo(existing.getInfo()); + } policyDAO.update(policy.setContact(contact)); final AccountContact added = policy.findContact(contact); diff --git a/bubble-server/src/main/resources/message_templates/server/en_US/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/server/en_US/post_auth/ResourceMessages.properties index 37b3f7ed..32c3878e 100644 --- a/bubble-server/src/main/resources/message_templates/server/en_US/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/server/en_US/post_auth/ResourceMessages.properties @@ -338,7 +338,6 @@ err.refund.unknownError=An error occurred processing your refund. Please contact err.remoteHost.length=Remote host is too long err.remoteHost.required=Remote host is required err.request.invalid=Request is invalid -err.requiredForNetworkUnlock.atLeastOneNetworkUnlockContactRequired=You must have at least one verified contact method that can unlock a new Bubble err.restoreKey.invalid=Restore key is invalid err.restoreKey.required=Restore key is required err.role.exists=Role already exists with this name diff --git a/bubble-web b/bubble-web index 6e622f75..614895af 160000 --- a/bubble-web +++ b/bubble-web @@ -1 +1 @@ -Subproject commit 6e622f75c645d258af7357991dd893d41d94c5d6 +Subproject commit 614895af758da790d8b80666fbc9ca969172760a