mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 17:37:13 +02:00
Add option to registrar_contact command to modify the visible_in_domain_whois_as_abuse flag
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=157588734
This commit is contained in:
parent
009522d078
commit
6cc3ee5e15
2 changed files with 130 additions and 6 deletions
|
@ -110,7 +110,7 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
@Nullable
|
||||
@Parameter(
|
||||
names = "--visible_in_whois_as_admin",
|
||||
description = " Whether this contact is publically visible in WHOIS results as an "
|
||||
description = " Whether this contact is publicly visible in WHOIS results as an "
|
||||
+ "Admin contact.",
|
||||
arity = 1)
|
||||
private Boolean visibleInWhoisAsAdmin;
|
||||
|
@ -118,11 +118,20 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
@Nullable
|
||||
@Parameter(
|
||||
names = "--visible_in_whois_as_tech",
|
||||
description = " Whether this contact is publically visible in WHOIS results as a "
|
||||
description = " Whether this contact is publicly visible in WHOIS results as a "
|
||||
+ "Tech contact.",
|
||||
arity = 1)
|
||||
private Boolean visibleInWhoisAsTech;
|
||||
|
||||
@Nullable
|
||||
@Parameter(
|
||||
names = "--visible_in_domain_whois_as_abuse",
|
||||
description = " Whether this contact is publicly visible in WHOIS domain results as the "
|
||||
+ "registry abuse phone and email. If this flag is set, it will be cleared from all "
|
||||
+ "other contacts for the same registrar.",
|
||||
arity = 1)
|
||||
private Boolean visibleInDomainWhoisAsAbuse;
|
||||
|
||||
@Parameter(
|
||||
names = {"-o", "--output"},
|
||||
description = "Output file when --mode=LIST",
|
||||
|
@ -160,6 +169,7 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
break;
|
||||
case CREATE:
|
||||
stageEntityChange(null, createContact(registrar));
|
||||
unsetOtherWhoisAbuseFlags(contacts, null);
|
||||
break;
|
||||
case UPDATE:
|
||||
oldContact =
|
||||
|
@ -168,7 +178,13 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
"No contact with the given email: %s",
|
||||
email);
|
||||
RegistrarContact newContact = updateContact(oldContact, registrar);
|
||||
checkArgument(
|
||||
!oldContact.getVisibleInDomainWhoisAsAbuse()
|
||||
|| newContact.getVisibleInDomainWhoisAsAbuse(),
|
||||
"Cannot clear visible_in_domain_whois_as_abuse flag, as that would leave no domain"
|
||||
+ " WHOIS abuse contacts; instead, set the flag on another contact");
|
||||
stageEntityChange(oldContact, newContact);
|
||||
unsetOtherWhoisAbuseFlags(contacts, oldContact.getEmailAddress());
|
||||
break;
|
||||
case DELETE:
|
||||
oldContact =
|
||||
|
@ -176,6 +192,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
contactsMap.get(checkNotNull(email, "--email is required when --mode=DELETE")),
|
||||
"No contact with the given email: %s",
|
||||
email);
|
||||
checkArgument(
|
||||
!oldContact.getVisibleInDomainWhoisAsAbuse(),
|
||||
"Cannot delete the domain WHOIS abuse contact; set the flag on another contact first");
|
||||
stageEntityChange(oldContact, null);
|
||||
break;
|
||||
default:
|
||||
|
@ -220,6 +239,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
if (visibleInWhoisAsTech != null) {
|
||||
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
||||
}
|
||||
if (visibleInDomainWhoisAsAbuse != null) {
|
||||
builder.setVisibleInDomainWhoisAsAbuse(visibleInDomainWhoisAsAbuse);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
@ -249,6 +271,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
if (visibleInWhoisAsTech != null) {
|
||||
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
||||
}
|
||||
if (visibleInDomainWhoisAsAbuse != null) {
|
||||
builder.setVisibleInDomainWhoisAsAbuse(visibleInDomainWhoisAsAbuse);
|
||||
}
|
||||
if (allowConsoleAccess != null) {
|
||||
if (allowConsoleAccess.equals(Boolean.TRUE)) {
|
||||
builder.setGaeUserId(checkArgumentNotNull(
|
||||
|
@ -260,4 +285,17 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void unsetOtherWhoisAbuseFlags(
|
||||
ImmutableSet<RegistrarContact> contacts, @Nullable String emailAddressNotToChange) {
|
||||
for (RegistrarContact contact : contacts) {
|
||||
if (((emailAddressNotToChange == null)
|
||||
|| !contact.getEmailAddress().equals(emailAddressNotToChange))
|
||||
&& contact.getVisibleInDomainWhoisAsAbuse()) {
|
||||
RegistrarContact newContact =
|
||||
contact.asBuilder().setVisibleInDomainWhoisAsAbuse(false).build();
|
||||
stageEntityChange(contact, newContact);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setTypes(ImmutableSet.of(WHOIS))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.setVisibleInWhoisAsTech(true)
|
||||
.setVisibleInDomainWhoisAsAbuse(false)
|
||||
.build());
|
||||
persistSimpleResources(contacts);
|
||||
runCommandForced(
|
||||
|
@ -88,7 +89,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
"--fax=+1.2125650001",
|
||||
"--contact_type=WHOIS",
|
||||
"--visible_in_whois_as_admin=true",
|
||||
"--visible_in_whois_as_tech=true",
|
||||
"--visible_in_whois_as_tech=false",
|
||||
"--visible_in_domain_whois_as_abuse=false",
|
||||
"NewRegistrar");
|
||||
RegistrarContact registrarContact =
|
||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||
|
@ -101,7 +103,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setFaxNumber("+1.2125650001")
|
||||
.setTypes(ImmutableSet.of(WHOIS))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.setVisibleInWhoisAsTech(true)
|
||||
.setVisibleInWhoisAsTech(false)
|
||||
.setVisibleInDomainWhoisAsAbuse(false)
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -144,6 +147,67 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
assertThat(registrarContact.getGaeUserId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_unsetOtherWhoisAbuseFlags() throws Exception {
|
||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||
persistSimpleResource(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("John Doe")
|
||||
.setEmailAddress("john.doe@example.com")
|
||||
.setGaeUserId("11111")
|
||||
.build());
|
||||
persistSimpleResource(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("Johnna Doe")
|
||||
.setEmailAddress("johnna.doe@example.com")
|
||||
.setGaeUserId("11112")
|
||||
.setVisibleInDomainWhoisAsAbuse(true)
|
||||
.build());
|
||||
runCommandForced(
|
||||
"--mode=UPDATE",
|
||||
"--email=john.doe@example.com",
|
||||
"--visible_in_domain_whois_as_abuse=true",
|
||||
"NewRegistrar");
|
||||
ImmutableList<RegistrarContact> registrarContacts =
|
||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList();
|
||||
for (RegistrarContact registrarContact : registrarContacts) {
|
||||
if (registrarContact.getName().equals("John Doe")) {
|
||||
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
|
||||
} else {
|
||||
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_cannotUnsetOnlyWhoisAbuseContact() throws Exception {
|
||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||
persistSimpleResource(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("John Doe")
|
||||
.setEmailAddress("john.doe@example.com")
|
||||
.setGaeUserId("11111")
|
||||
.setVisibleInDomainWhoisAsAbuse(true)
|
||||
.build());
|
||||
try {
|
||||
runCommandForced(
|
||||
"--mode=UPDATE",
|
||||
"--email=john.doe@example.com",
|
||||
"--visible_in_domain_whois_as_abuse=false",
|
||||
"NewRegistrar");
|
||||
throw new Exception(
|
||||
"Expected IllegalArgumentException: Cannot clear visible_in_domain_whois_as_abuse flag");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageThat().contains("Cannot clear visible_in_domain_whois_as_abuse flag");
|
||||
}
|
||||
RegistrarContact registrarContact =
|
||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_withAdminType() throws Exception {
|
||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||
|
@ -153,7 +217,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
"--email=jim.doe@example.com",
|
||||
"--contact_type=ADMIN,ABUSE",
|
||||
"--visible_in_whois_as_admin=true",
|
||||
"--visible_in_whois_as_tech=true",
|
||||
"--visible_in_whois_as_tech=false",
|
||||
"--visible_in_domain_whois_as_abuse=true",
|
||||
"NewRegistrar");
|
||||
RegistrarContact registrarContact =
|
||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||
|
@ -164,13 +229,15 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
.setEmailAddress("jim.doe@example.com")
|
||||
.setTypes(ImmutableSet.of(ADMIN, ABUSE))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.setVisibleInWhoisAsTech(true)
|
||||
.setVisibleInWhoisAsTech(false)
|
||||
.setVisibleInDomainWhoisAsAbuse(true)
|
||||
.build());
|
||||
assertThat(registrarContact.getGaeUserId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception {
|
||||
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
|
||||
runCommandForced(
|
||||
"--mode=DELETE",
|
||||
"--email=janedoe@theregistrar.com",
|
||||
|
@ -178,6 +245,25 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete_failsOnDomainWhoisAbuseContact() throws Exception {
|
||||
RegistrarContact registrarContact =
|
||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(0);
|
||||
persistSimpleResource(
|
||||
registrarContact.asBuilder().setVisibleInDomainWhoisAsAbuse(true).build());
|
||||
try {
|
||||
runCommandForced(
|
||||
"--mode=DELETE",
|
||||
"--email=janedoe@theregistrar.com",
|
||||
"NewRegistrar");
|
||||
throw new Exception(
|
||||
"Expected IllegalArgumentException: Cannot delete the domain WHOIS abuse contact");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageThat().contains("Cannot delete the domain WHOIS abuse contact");
|
||||
}
|
||||
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_withConsoleAccessEnabled() throws Exception {
|
||||
runCommandForced(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue