From 63238a7078f5d53c5386e36eaa7baeaf2ab0dc0c Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 24 Jun 2015 11:34:20 +0200 Subject: [PATCH] Let plugins create email addresses even when the realm disallows it CreateEmail#apply(IdentifiedUser, EmailInput) is only used by plugins. By using this method plugins can reuse the code to create new email addresses. Move the check whether the realm allows creating email addresses to CreateEmail#apply(AccountResource, EmailInput) so that it doesn't apply for plugins. Skipping this check makes e.g. sense for the service-user plugin. While normal users (e.g. LDAP users) should not be able to register additional email addresses, email addresses for service users still need to be set in Gerrit. Having an email address is required when a service user should be able to push commits and tags to Gerrit. Change-Id: Ic25f07e553f03a237b55b8c6811b736edf503414 Signed-off-by: Edwin Kempin --- .../com/google/gerrit/server/account/CreateEmail.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateEmail.java index d302a8efe6..a0fadb5a3f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateEmail.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateEmail.java @@ -94,17 +94,16 @@ public class CreateEmail implements RestModifyView throw new AuthException("not allowed to use no_confirmation"); } + if (!realm.allowsEdit(FieldName.REGISTER_NEW_EMAIL)) { + throw new MethodNotAllowedException("realm does not allow adding emails"); + } + return apply(rsrc.getUser(), input); } public Response apply(IdentifiedUser user, EmailInput input) throws AuthException, BadRequestException, ResourceConflictException, - ResourceNotFoundException, OrmException, EmailException, - MethodNotAllowedException { - if (!realm.allowsEdit(FieldName.REGISTER_NEW_EMAIL)) { - throw new MethodNotAllowedException("realm does not allow adding emails"); - } - + ResourceNotFoundException, OrmException, EmailException { if (input.email != null && !email.equals(input.email)) { throw new BadRequestException("email address must match URL"); }