Flat-map registry lock emails to avoid unclean errors in bad situations (#525)

* Flat map to avoid unclean errors in bad situations

Also properly reflect that for admins, we will use their user email

* Make MS's GAE user ID a public static field
This commit is contained in:
gbrodman 2020-03-23 11:45:49 -04:00 committed by GitHub
parent f37b0bd915
commit 0b6a84b84c
5 changed files with 8 additions and 6 deletions

View file

@ -159,9 +159,10 @@ public final class RegistryLockGetAction implements JsonGetAction {
isAdmin || contactOptional.map(RegistrarContact::isRegistryLockAllowed).orElse(false); isAdmin || contactOptional.map(RegistrarContact::isRegistryLockAllowed).orElse(false);
// Use the contact's registry lock email if it's present, else use the login email (for admins) // Use the contact's registry lock email if it's present, else use the login email (for admins)
String relevantEmail = String relevantEmail =
contactOptional isAdmin
.map(contact -> contact.getRegistryLockEmailAddress().get()) ? user.getEmail()
.orElse(user.getEmail()); // if the contact isn't present, we shouldn't display the email anyway so empty is fine
: contactOptional.flatMap(RegistrarContact::getRegistryLockEmailAddress).orElse("");
return ImmutableMap.of( return ImmutableMap.of(
LOCK_ENABLED_FOR_CONTACT_PARAM, LOCK_ENABLED_FOR_CONTACT_PARAM,
isRegistryLockAllowed, isRegistryLockAllowed,

View file

@ -62,7 +62,7 @@ public final class RegistryTestServerMain {
@Parameter( @Parameter(
names = "--login_user_id", names = "--login_user_id",
description = "GAE User ID for App Engine Local User Service.") description = "GAE User ID for App Engine Local User Service.")
private String loginUserId = AppEngineRule.THE_REGISTRAR_GAE_USER_ID; private String loginUserId = AppEngineRule.MARLA_SINGER_GAE_USER_ID;
@Parameter( @Parameter(
names = "--login_is_admin", names = "--login_is_admin",

View file

@ -71,6 +71,7 @@ public final class AppEngineRule extends ExternalResource {
public static final String NEW_REGISTRAR_GAE_USER_ID = "666"; public static final String NEW_REGISTRAR_GAE_USER_ID = "666";
public static final String THE_REGISTRAR_GAE_USER_ID = "31337"; public static final String THE_REGISTRAR_GAE_USER_ID = "31337";
public static final String MARLA_SINGER_GAE_USER_ID = "12345";
/** /**
* The GAE testing library requires queue.xml to be a file, not a resource in a jar, so we read it * The GAE testing library requires queue.xml to be a file, not a resource in a jar, so we read it
@ -250,7 +251,7 @@ public final class AppEngineRule extends ExternalResource {
.setRegistryLockEmailAddress("Marla.Singer.RegistryLock@crr.com") .setRegistryLockEmailAddress("Marla.Singer.RegistryLock@crr.com")
.setPhoneNumber("+1.2128675309") .setPhoneNumber("+1.2128675309")
.setTypes(ImmutableSet.of(RegistrarContact.Type.TECH)) .setTypes(ImmutableSet.of(RegistrarContact.Type.TECH))
.setGaeUserId("12345") .setGaeUserId(MARLA_SINGER_GAE_USER_ID)
.setAllowedToSetRegistryLockPassword(true) .setAllowedToSetRegistryLockPassword(true)
.setRegistryLockPassword("hi") .setRegistryLockPassword("hi")
.build(); .build();

View file

@ -304,7 +304,7 @@ public final class RegistryLockGetActionTest {
"lockEnabledForContact", "lockEnabledForContact",
true, true,
"email", "email",
"Marla.Singer.RegistryLock@crr.com", "Marla.Singer@crr.com",
"clientId", "clientId",
"TheRegistrar", "TheRegistrar",
"locks", "locks",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Before After
Before After