Account queries: Add option to include secondary emails
If an account is suggested due to a match on a secondary email address the UI needs to have the secondary email address available to show it in the suggestion (see Ife5e3 for more details). Change-Id: I23c72630f54250e7ac0a7ff26d4b28e8a6af0df3 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -294,6 +294,34 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
assertThat(ai.avatars).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSecondaryEmails() throws Exception {
|
||||
AccountInfo user1 =
|
||||
newAccount("myuser", "My User", "my.user@example.com", true);
|
||||
String[] secondaryEmails =
|
||||
new String[] {"bar@example.com", "foo@example.com"};
|
||||
addEmails(user1, secondaryEmails);
|
||||
|
||||
|
||||
List<AccountInfo> result = assertQuery(user1.username, user1);
|
||||
assertThat(result.get(0).secondaryEmails).isNull();
|
||||
|
||||
result = assertQuery(
|
||||
newQuery(user1.username).withOption(ListAccountsOption.DETAILS), user1);
|
||||
assertThat(result.get(0).secondaryEmails).isNull();
|
||||
|
||||
result = assertQuery(
|
||||
newQuery(user1.username).withOption(ListAccountsOption.ALL_EMAILS),
|
||||
user1);
|
||||
assertThat(result.get(0).secondaryEmails)
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
||||
|
||||
result = assertQuery(newQuery(user1.username).withOptions(
|
||||
ListAccountsOption.DETAILS, ListAccountsOption.ALL_EMAILS), user1);
|
||||
assertThat(result.get(0).secondaryEmails)
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
||||
}
|
||||
|
||||
protected AccountInfo newAccount(String username) throws Exception {
|
||||
return newAccountWithEmail(username, null);
|
||||
}
|
||||
@@ -359,6 +387,15 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void addEmails(AccountInfo account, String... emails)
|
||||
throws Exception {
|
||||
Account.Id id = new Account.Id(account._accountId);
|
||||
for (String email : emails) {
|
||||
accountManager.link(id, AuthRequest.forEmail(email));
|
||||
}
|
||||
accountCache.evict(id);
|
||||
}
|
||||
|
||||
protected QueryRequest newQuery(Object query) throws RestApiException {
|
||||
return gApi.accounts().query(query.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user