Support to register a new email address via REST

By PUT on /accounts/<account-id>/emails/<email-id> a new email address
can be registered for an account. A verification email is sent with a
link that needs to be visited to confirm the email address.

The WebUI was adapted to use this REST endpoint for registering email
addresses. The old RPC to do this was removed.

Change-Id: I39c1f72a0c3e0d50883c76c975bbd464f1894095
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-05-16 16:41:24 +02:00
parent e1f8288fc7
commit 315066a9fc
13 changed files with 249 additions and 85 deletions

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2013 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.client.account;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* A collection of static methods which work on the Gerrit REST API for specific
* accounts.
*/
public class AccountApi {
/** Register a new email address */
public static void registerEmail(String account, String email,
AsyncCallback<NativeString> cb) {
JavaScriptObject in = JavaScriptObject.createObject();
new RestApi("/accounts/").id(account).view("emails").id(email)
.ifNoneMatch().put(in, cb);
}
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.account;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.errors.EmailException;
@@ -283,13 +284,16 @@ class ContactPanelShort extends Composite {
inEmail.setEnabled(false);
register.setEnabled(false);
Util.ACCOUNT_SEC.registerEmail(addr, new GerritCallback<Account>() {
public void onSuccess(Account currentUser) {
AccountApi.registerEmail("self", addr, new GerritCallback<NativeString>() {
@Override
public void onSuccess(NativeString result) {
box.hide();
if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
currentEmail = addr;
if (emailPick.getItemCount() == 0) {
onSaveSuccess(currentUser);
final Account me = Gerrit.getUserAccount();
me.setPreferredEmail(addr);
onSaveSuccess(me);
} else {
save.setEnabled(true);
}