From 654451080245d9d3aa1c02305bb19d8cb5e4683a Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 27 May 2015 15:30:26 +0900 Subject: [PATCH] Move CreateEmail.Input to EmailInput in extension API So it can be used by following change(s) in the account API. Change-Id: I5c216a0f8f630f0882a2277ab6fb412082113127 --- .../extensions/api/accounts/EmailInput.java | 34 +++++++++++++++++++ .../gerrit/server/account/CreateEmail.java | 18 +++------- .../gerrit/server/account/PutEmail.java | 6 ++-- .../sshd/commands/SetAccountCommand.java | 3 +- 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/accounts/EmailInput.java diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/accounts/EmailInput.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/accounts/EmailInput.java new file mode 100644 index 0000000000..5036731ce4 --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/accounts/EmailInput.java @@ -0,0 +1,34 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.extensions.api.accounts; + +import com.google.gerrit.extensions.restapi.DefaultInput; + +/** This entity contains information for registering a new email address. */ +public class EmailInput { + /* The email address. If provided, must match the email address from the URL. */ + @DefaultInput + public String email; + + /* Whether the new email address should become the preferred email address of + * the user. Only supported if {@link #noConfirmation} is set or if the + * authentication type is DEVELOPMENT_BECOME_ANY_ACCOUNT.*/ + public boolean preferred; + + /* Whether the email address should be added without confirmation. In this + * case no verification email is sent to the user. Only Gerrit administrators + * are allowed to add email addresses without confirmation. */ + public boolean noConfirmation; +} 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 441213d1e1..d302a8efe6 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 @@ -15,9 +15,9 @@ package com.google.gerrit.server.account; import com.google.gerrit.common.errors.EmailException; +import com.google.gerrit.extensions.api.accounts.EmailInput; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; -import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.MethodNotAllowedException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; @@ -27,7 +27,6 @@ import com.google.gerrit.reviewdb.client.Account.FieldName; import com.google.gerrit.reviewdb.client.AuthType; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; -import com.google.gerrit.server.account.CreateEmail.Input; import com.google.gerrit.server.account.GetEmails.EmailInfo; import com.google.gerrit.server.config.AuthConfig; import com.google.gerrit.server.mail.RegisterNewEmailSender; @@ -40,16 +39,9 @@ import org.apache.commons.validator.routines.EmailValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class CreateEmail implements RestModifyView { +public class CreateEmail implements RestModifyView { private final Logger log = LoggerFactory.getLogger(getClass()); - public static class Input { - @DefaultInput - public String email; - public boolean preferred; - public boolean noConfirmation; - } - public static interface Factory { CreateEmail create(String email); } @@ -80,7 +72,7 @@ public class CreateEmail implements RestModifyView { } @Override - public Response apply(AccountResource rsrc, Input input) + public Response apply(AccountResource rsrc, EmailInput input) throws AuthException, BadRequestException, ResourceConflictException, ResourceNotFoundException, OrmException, EmailException, MethodNotAllowedException { @@ -90,7 +82,7 @@ public class CreateEmail implements RestModifyView { } if (input == null) { - input = new Input(); + input = new EmailInput(); } if (!EmailValidator.getInstance().isValid(email)) { @@ -105,7 +97,7 @@ public class CreateEmail implements RestModifyView { return apply(rsrc.getUser(), input); } - public Response apply(IdentifiedUser user, Input input) + public Response apply(IdentifiedUser user, EmailInput input) throws AuthException, BadRequestException, ResourceConflictException, ResourceNotFoundException, OrmException, EmailException, MethodNotAllowedException { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutEmail.java index 3831cbfe94..acdbbf4795 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutEmail.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutEmail.java @@ -14,16 +14,16 @@ package com.google.gerrit.server.account; +import com.google.gerrit.extensions.api.accounts.EmailInput; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.server.account.CreateEmail.Input; import com.google.inject.Singleton; @Singleton -public class PutEmail implements RestModifyView { +public class PutEmail implements RestModifyView { @Override - public Response apply(AccountResource.Email rsrc, Input input) + public Response apply(AccountResource.Email rsrc, EmailInput input) throws ResourceConflictException { throw new ResourceConflictException("email exists"); } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java index 1cb442d4ed..974b5c6368 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java @@ -18,6 +18,7 @@ import com.google.common.base.Strings; import com.google.gerrit.common.data.GlobalCapability; import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.extensions.annotations.RequiresCapability; +import com.google.gerrit.extensions.api.accounts.EmailInput; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.RawInput; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; @@ -270,7 +271,7 @@ final class SetAccountCommand extends SshCommand { private void addEmail(String email) throws UnloggedFailure, RestApiException, OrmException { - CreateEmail.Input in = new CreateEmail.Input(); + EmailInput in = new EmailInput(); in.email = email; in.noConfirmation = true; try {