diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt index 71115bdc67..1e403ac45e 100644 --- a/Documentation/rest-api-accounts.txt +++ b/Documentation/rest-api-accounts.txt @@ -583,7 +583,8 @@ the link:#capability-info[CapabilityInfo] entity. [[email-id]] \{email-id\} ~~~~~~~~~~~~~~ -An email address. +An email address, or `preferred` for the preferred email address of the +user. [[username]] \{username\} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/Emails.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/Emails.java index 583e539800..59f04ac406 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/Emails.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/Emails.java @@ -14,6 +14,7 @@ package com.google.gerrit.server.account; +import com.google.common.base.Strings; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.ChildCollection; @@ -52,6 +53,14 @@ public class Emails implements @Override public AccountResource.Email parse(AccountResource parent, IdString id) throws AuthException, ResourceNotFoundException { + if ("preferred".equals(id.get())) { + String preferredEmail = parent.getUser().getAccount().getPreferredEmail(); + if (!Strings.isNullOrEmpty(preferredEmail)) { + return new AccountResource.Email(parent.getUser(), preferredEmail); + } + throw new ResourceNotFoundException(); + } + if (!(self.get() instanceof IdentifiedUser)) { throw new AuthException("Authentication required"); }