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 <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-06-24 11:34:20 +02:00
parent e42d6ad70e
commit 63238a7078

View File

@@ -94,17 +94,16 @@ public class CreateEmail implements RestModifyView<AccountResource, EmailInput>
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<EmailInfo> 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");
}