mirror of
https://github.com/google/nomulus.git
synced 2025-05-29 17:00:11 +02:00
Better handle syncing contacts when creating RegistrarContacts
This also adds a test that should've been there already. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149583500
This commit is contained in:
parent
27b9244126
commit
ad840ad4d6
2 changed files with 48 additions and 30 deletions
|
@ -54,8 +54,6 @@ import javax.annotation.Nullable;
|
|||
commandDescription = "Create/read/update/delete the various contact lists for a Registrar.")
|
||||
final class RegistrarContactCommand extends MutatingCommand {
|
||||
|
||||
private enum Mode { LIST, CREATE, UPDATE, DELETE }
|
||||
|
||||
@Parameter(
|
||||
description = "Client identifier of the registrar account.",
|
||||
required = true)
|
||||
|
@ -131,6 +129,11 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
validateWith = PathParameter.OutputFile.class)
|
||||
private Path output = Paths.get("/dev/stdout");
|
||||
|
||||
private enum Mode { LIST, CREATE, UPDATE, DELETE }
|
||||
|
||||
private static final ImmutableSet<Mode> MODES_REQUIRING_CONTACT_SYNC =
|
||||
ImmutableSet.of(Mode.CREATE, Mode.UPDATE, Mode.DELETE);
|
||||
|
||||
@Nullable
|
||||
private Set<RegistrarContact.Type> contactTypes;
|
||||
|
||||
|
@ -178,7 +181,7 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
if (mode == Mode.CREATE || mode == Mode.UPDATE || mode == Mode.DELETE) {
|
||||
if (MODES_REQUIRING_CONTACT_SYNC.contains(mode)) {
|
||||
stageEntityChange(registrar, registrar.asBuilder().setContactsRequireSyncing(true).build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static google.registry.model.registrar.RegistrarContact.Type.ABUSE;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.ADMIN;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -44,7 +45,9 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
@Test
|
||||
public void testList() throws Exception {
|
||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||
RegistrarContact.updateContacts(registrar, ImmutableSet.of(
|
||||
RegistrarContact.updateContacts(
|
||||
registrar,
|
||||
ImmutableSet.of(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("John Doe")
|
||||
|
@ -52,8 +55,9 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setTypes(ImmutableSet.of(ADMIN))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.build()));
|
||||
runCommand("-f", "--mode=LIST", "--output=" + output, "NewRegistrar");
|
||||
assertThat(Files.readAllLines(Paths.get(output), UTF_8)).containsExactly(
|
||||
runCommandForced("--mode=LIST", "--output=" + output, "NewRegistrar");
|
||||
assertThat(Files.readAllLines(Paths.get(output), UTF_8))
|
||||
.containsExactly(
|
||||
"John Doe",
|
||||
"john.doe@example.com",
|
||||
"Types: [ADMIN]",
|
||||
|
@ -74,8 +78,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setVisibleInWhoisAsTech(true)
|
||||
.build());
|
||||
persistSimpleResources(contacts);
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=UPDATE",
|
||||
"--name=Judith Registrar",
|
||||
"--email=judith.doe@example.com",
|
||||
|
@ -109,8 +112,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setName("Jane Doe")
|
||||
.setEmailAddress("jane.doe@example.com")
|
||||
.build());
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=UPDATE",
|
||||
"--email=jane.doe@example.com",
|
||||
"--allow_console_access=true",
|
||||
|
@ -130,8 +132,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setEmailAddress("judith.doe@example.com")
|
||||
.setGaeUserId("11111")
|
||||
.build());
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=UPDATE",
|
||||
"--email=judith.doe@example.com",
|
||||
"--allow_console_access=false",
|
||||
|
@ -144,8 +145,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
@Test
|
||||
public void testCreate_withAdminType() throws Exception {
|
||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=CREATE",
|
||||
"--name=Jim Doe",
|
||||
"--email=jim.doe@example.com",
|
||||
|
@ -169,8 +169,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
|
||||
@Test
|
||||
public void testDelete() throws Exception {
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=DELETE",
|
||||
"--email=janedoe@theregistrar.com",
|
||||
"NewRegistrar");
|
||||
|
@ -179,8 +178,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
|
||||
@Test
|
||||
public void testCreate_withConsoleAccessEnabled() throws Exception {
|
||||
runCommand(
|
||||
"--force",
|
||||
runCommandForced(
|
||||
"--mode=CREATE",
|
||||
"--name=Jim Doe",
|
||||
"--email=jim.doe@example.com",
|
||||
|
@ -191,4 +189,21 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||
assertThat(registrarContact.getGaeUserId()).matches("-?[0-9]+");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_syncingRequiredSetToTrue() throws Exception {
|
||||
persistResource(
|
||||
Registrar.loadByClientId("NewRegistrar")
|
||||
.asBuilder()
|
||||
.setContactsRequireSyncing(false)
|
||||
.build());
|
||||
|
||||
assertThat(Registrar.loadByClientId("NewRegistrar").getContactsRequireSyncing()).isFalse();
|
||||
runCommandForced(
|
||||
"--mode=CREATE",
|
||||
"--name=Jim Doe",
|
||||
"--email=jim.doe@example.com",
|
||||
"NewRegistrar");
|
||||
assertThat(Registrar.loadByClientId("NewRegistrar").getContactsRequireSyncing()).isTrue();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue