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:
		| @@ -583,7 +583,8 @@ the link:#capability-info[CapabilityInfo] entity. | |||||||
| [[email-id]] | [[email-id]] | ||||||
| \{email-id\} | \{email-id\} | ||||||
| ~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~ | ||||||
| An email address. | An email address, or `preferred` for the preferred email address of the | ||||||
|  | user. | ||||||
|  |  | ||||||
| [[username]] | [[username]] | ||||||
| \{username\} | \{username\} | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ | |||||||
|  |  | ||||||
| package com.google.gerrit.server.account; | package com.google.gerrit.server.account; | ||||||
|  |  | ||||||
|  | import com.google.common.base.Strings; | ||||||
| import com.google.gerrit.extensions.registration.DynamicMap; | import com.google.gerrit.extensions.registration.DynamicMap; | ||||||
| import com.google.gerrit.extensions.restapi.AuthException; | import com.google.gerrit.extensions.restapi.AuthException; | ||||||
| import com.google.gerrit.extensions.restapi.ChildCollection; | import com.google.gerrit.extensions.restapi.ChildCollection; | ||||||
| @@ -52,6 +53,14 @@ public class Emails implements | |||||||
|   @Override |   @Override | ||||||
|   public AccountResource.Email parse(AccountResource parent, IdString id) |   public AccountResource.Email parse(AccountResource parent, IdString id) | ||||||
|       throws AuthException, ResourceNotFoundException { |       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)) { |     if (!(self.get() instanceof IdentifiedUser)) { | ||||||
|       throw new AuthException("Authentication required"); |       throw new AuthException("Authentication required"); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Edwin Kempin
					Edwin Kempin