Support 'preferred' as ID for the preferred email address of a user

GET on /accounts/<account-id>/emails/preferred returns the preferred
email address of the user.

Change-Id: I1f4d244bed733beb596ebbe83184ec126e8c0da7
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-05-16 13:52:53 +02:00
parent 493efd5d02
commit 0ae7af022a
2 changed files with 11 additions and 1 deletions

View File

@@ -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");
}