Merge "Fix resolving accounts from commit footers to use exact matching"
This commit is contained in:
@@ -567,6 +567,25 @@ public class AccountResolver {
|
||||
input, nameOrEmailSearchers, visibilitySupplierCanSee(), accountActivityPredicate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #resolveByNameOrEmail(String)}, but with exact matching for the full name, email
|
||||
* and full name.
|
||||
*
|
||||
* @param input input string.
|
||||
* @return a result describing matching accounts. Never null even if the result set is empty.
|
||||
* @throws ConfigInvalidException if an error occurs.
|
||||
* @throws IOException if an error occurs.
|
||||
* @deprecated for use only by MailUtil for parsing commit footers; that class needs to be
|
||||
* reevaluated.
|
||||
*/
|
||||
public Result resolveByExactNameOrEmail(String input) throws ConfigInvalidException, IOException {
|
||||
return searchImpl(
|
||||
input,
|
||||
ImmutableList.of(new ByNameAndEmail(), new ByEmail(), new ByFullName(), new ByUsername()),
|
||||
visibilitySupplierCanSee(),
|
||||
accountActivityPredicate());
|
||||
}
|
||||
|
||||
private Supplier<Predicate<AccountState>> visibilitySupplierCanSee() {
|
||||
return () -> accountControlFactory.get()::canSee;
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class MailUtil {
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Account.Id toAccountId(AccountResolver accountResolver, String nameOrEmail)
|
||||
throws UnprocessableEntityException, IOException, ConfigInvalidException {
|
||||
return accountResolver.resolveByNameOrEmail(nameOrEmail).asUnique().account().id();
|
||||
return accountResolver.resolveByExactNameOrEmail(nameOrEmail).asUnique().account().id();
|
||||
}
|
||||
|
||||
private static boolean isReviewer(FooterLine candidateFooterLine) {
|
||||
|
@@ -170,6 +170,33 @@ public class AccountResolverIT extends AbstractDaemonTest {
|
||||
assertThat(resolveByNameOrEmail(input)).containsExactly(idWithEmail);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byUserNameOrFullNameOrEmailExact() throws Exception {
|
||||
String userName = "UserFoo";
|
||||
String fullName = "Name Foo";
|
||||
String email = "emailfoo@something.com";
|
||||
Account.Id id =
|
||||
accountOperations
|
||||
.newAccount()
|
||||
.username(userName)
|
||||
.fullname(fullName)
|
||||
.preferredEmail(email)
|
||||
.create();
|
||||
|
||||
// resolver returns results for exact matches
|
||||
assertThat(resolveByExactNameOrEmail(userName)).containsExactly(id);
|
||||
assertThat(resolveByExactNameOrEmail(fullName)).containsExactly(id);
|
||||
assertThat(resolveByExactNameOrEmail(email)).containsExactly(id);
|
||||
|
||||
// resolver does not match with prefixes
|
||||
assertThat(resolveByExactNameOrEmail("UserF")).isEmpty();
|
||||
assertThat(resolveByExactNameOrEmail("Name F")).isEmpty();
|
||||
assertThat(resolveByExactNameOrEmail("emailf")).isEmpty();
|
||||
|
||||
/* The default name/email resolver accepts prefix matches */
|
||||
assertThat(resolveByNameOrEmail("emai")).containsExactly(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byNameAndEmailPrefersAccountsWithMatchingFullName() throws Exception {
|
||||
String email = name("user@example.com");
|
||||
@@ -334,6 +361,11 @@ public class AccountResolverIT extends AbstractDaemonTest {
|
||||
return accountResolver.resolveByNameOrEmail(input.toString()).asIdSet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private ImmutableSet<Account.Id> resolveByExactNameOrEmail(Object input) throws Exception {
|
||||
return accountResolver.resolveByExactNameOrEmail(input.toString()).asIdSet();
|
||||
}
|
||||
|
||||
private void setPreferredEmailBypassingUniquenessCheck(Account.Id id, String email)
|
||||
throws Exception {
|
||||
Optional<AccountState> result =
|
||||
|
Reference in New Issue
Block a user