Handle both ways the UI passes in booleans (#500)

* Handle both ways the UI passes in booleans

* fix the JS test

* Quote the value
This commit is contained in:
gbrodman 2020-03-02 12:49:09 -05:00 committed by GitHub
parent e8ff4081a9
commit fec806ef8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -37,6 +37,7 @@ import google.registry.util.X509Utils;
import java.security.cert.CertificateParsingException; import java.security.cert.CertificateParsingException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -204,8 +205,10 @@ public final class RegistrarFormFields {
public static final FormField<String, String> CONTACT_GAE_USER_ID_FIELD = public static final FormField<String, String> CONTACT_GAE_USER_ID_FIELD =
FormFields.NAME.asBuilderNamed("gaeUserId").build(); FormFields.NAME.asBuilderNamed("gaeUserId").build();
public static final FormField<Boolean, Boolean> CONTACT_ALLOWED_TO_SET_REGISTRY_LOCK_PASSWORD = public static final FormField<Object, Boolean> CONTACT_ALLOWED_TO_SET_REGISTRY_LOCK_PASSWORD =
FormField.named("allowedToSetRegistryLockPassword", Boolean.class).build(); FormField.named("allowedToSetRegistryLockPassword", Object.class)
.transform(Boolean.class, b -> Boolean.valueOf(Objects.toString(b)))
.build();
public static final FormField<String, String> CONTACT_REGISTRY_LOCK_PASSWORD_FIELD = public static final FormField<String, String> CONTACT_REGISTRY_LOCK_PASSWORD_FIELD =
FormFields.NAME.asBuilderNamed("registryLockPassword").build(); FormFields.NAME.asBuilderNamed("registryLockPassword").build();
@ -384,6 +387,8 @@ public final class RegistrarFormFields {
builder.setFaxNumber(CONTACT_FAX_NUMBER_FIELD.extractUntyped(args).orElse(null)); builder.setFaxNumber(CONTACT_FAX_NUMBER_FIELD.extractUntyped(args).orElse(null));
builder.setTypes(CONTACT_TYPES.extractUntyped(args).orElse(ImmutableSet.of())); builder.setTypes(CONTACT_TYPES.extractUntyped(args).orElse(ImmutableSet.of()));
builder.setGaeUserId(CONTACT_GAE_USER_ID_FIELD.extractUntyped(args).orElse(null)); builder.setGaeUserId(CONTACT_GAE_USER_ID_FIELD.extractUntyped(args).orElse(null));
// The parser is inconsistent with whether it retrieves boolean values as strings or booleans.
// As a result, use a potentially-redundant converter that can deal with both.
builder.setAllowedToSetRegistryLockPassword( builder.setAllowedToSetRegistryLockPassword(
CONTACT_ALLOWED_TO_SET_REGISTRY_LOCK_PASSWORD.extractUntyped(args).orElse(false)); CONTACT_ALLOWED_TO_SET_REGISTRY_LOCK_PASSWORD.extractUntyped(args).orElse(false));

View file

@ -256,10 +256,13 @@
{param placeholder: $placeholder /} {param placeholder: $placeholder /}
{/call} {/call}
{/if} {/if}
{if isNonnull($item['allowedToSetRegistryLockPassword'])} <input type="hidden" name="{$namePrefix}allowedToSetRegistryLockPassword"
<input type="hidden" name="allowedToSetRegistryLockPassword" {if isNonnull($item['allowedToSetRegistryLockPassword'])}
value="{$item['allowedToSetRegistryLockPassword']}"> value="{$item['allowedToSetRegistryLockPassword']}"
{/if} {else}
value="false"
{/if}
>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<hr> <hr>

View file

@ -335,7 +335,8 @@ describe("contact settings test", function() {
visibleInWhoisAsAdmin: false, visibleInWhoisAsAdmin: false,
visibleInWhoisAsTech: false, visibleInWhoisAsTech: false,
visibleInDomainWhoisAsAbuse: false, visibleInDomainWhoisAsAbuse: false,
types: 'ADMIN' types: 'ADMIN',
allowedToSetRegistryLockPassword: 'false'
}; };
} }