Change behavior when searching contacts by name

We no longer find contacts by name if the request is not authorized to see the name.

Several changes cascade from this. Previously, the code assumed that deleted contacts might still have full names, and therefore be searchable. This is not possible in all cases, because Datastore doesn't have the right index to find deleted contacts by name with a matching registrar. However, luckily, this situation can never occur, because contacts always have their name fields nulled out when they are deleted.

So instead, we simply ignore deleted records when searching by name, knowing that none can ever match.

The tests were then changed so that deleted records look the way the really will, meaning devoid of personal information.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172776926
This commit is contained in:
mountford 2017-10-19 11:51:03 -07:00 committed by jianglai
parent f89ad27e17
commit ac822053cc
5 changed files with 182 additions and 67 deletions

View file

@ -228,6 +228,25 @@ public final class FullFieldsTestEntityHelper {
return builder.build();
}
public static ContactResource makeWipedOutContactResource(
String id,
@Nullable Registrar registrar,
@Nullable DateTime deletionTime) {
ContactResource.Builder builder = new ContactResource.Builder()
.setContactId(id)
.setRepoId(generateNewContactHostRoid())
.setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"));
if (registrar != null) {
builder
.setCreationClientId(registrar.getClientId())
.setPersistedCurrentSponsorClientId(registrar.getClientId());
}
if (deletionTime != null) {
builder.setDeletionTime(deletionTime);
}
return builder.build();
}
public static ContactResource makeAndPersistContactResource(
String id,
String name,
@ -284,6 +303,20 @@ public final class FullFieldsTestEntityHelper {
return contactResource;
}
public static ContactResource makeAndPersistDeletedContactResource(
String id,
DateTime creationTime,
Registrar registrar,
DateTime deletionTime) {
ContactResource contactResource =
persistResource(makeWipedOutContactResource(id, registrar, deletionTime));
persistResource(makeHistoryEntry(
contactResource, HistoryEntry.Type.CONTACT_CREATE, null, "created", creationTime));
persistResource(makeHistoryEntry(
contactResource, HistoryEntry.Type.CONTACT_DELETE, null, "deleted", deletionTime));
return contactResource;
}
public static DomainResource makeDomainResource(
String domain,
@Nullable ContactResource registrant,