Adapt WebUI to use REST endpoint to retrieve emails of an account
Change-Id: I637b7e17fc5025460c61be5b1fcda990b22491c5 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:

committed by
Edwin Kempin

parent
c950bcca7e
commit
20092b132e
@@ -29,9 +29,15 @@ import java.util.Set;
|
|||||||
* accounts.
|
* accounts.
|
||||||
*/
|
*/
|
||||||
public class AccountApi {
|
public class AccountApi {
|
||||||
|
/** Retrieve email addresses */
|
||||||
|
public static void getEmails(String account,
|
||||||
|
AsyncCallback<JsArray<EmailInfo>> cb) {
|
||||||
|
new RestApi("/accounts/").id(account).view("emails").get(cb);
|
||||||
|
}
|
||||||
|
|
||||||
/** Register a new email address */
|
/** Register a new email address */
|
||||||
public static void registerEmail(String account, String email,
|
public static void registerEmail(String account, String email,
|
||||||
AsyncCallback<NativeString> cb) {
|
AsyncCallback<EmailInfo> cb) {
|
||||||
JavaScriptObject in = JavaScriptObject.createObject();
|
JavaScriptObject in = JavaScriptObject.createObject();
|
||||||
new RestApi("/accounts/").id(account).view("emails").id(email)
|
new RestApi("/accounts/").id(account).view("emails").id(email)
|
||||||
.ifNoneMatch().put(in, cb);
|
.ifNoneMatch().put(in, cb);
|
||||||
|
@@ -17,15 +17,15 @@ package com.google.gerrit.client.account;
|
|||||||
import com.google.gerrit.client.ErrorDialog;
|
import com.google.gerrit.client.ErrorDialog;
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.client.rpc.NativeString;
|
import com.google.gerrit.client.rpc.Natives;
|
||||||
import com.google.gerrit.client.ui.OnEditEnabler;
|
import com.google.gerrit.client.ui.OnEditEnabler;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Account.FieldName;
|
import com.google.gerrit.reviewdb.client.Account.FieldName;
|
||||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
|
||||||
import com.google.gerrit.reviewdb.client.AuthType;
|
import com.google.gerrit.reviewdb.client.AuthType;
|
||||||
import com.google.gerrit.reviewdb.client.ContactInformation;
|
import com.google.gerrit.reviewdb.client.ContactInformation;
|
||||||
|
import com.google.gwt.core.client.JsArray;
|
||||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
@@ -46,12 +46,6 @@ import com.google.gwtexpui.globalkey.client.NpTextBox;
|
|||||||
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
|
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
|
||||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class ContactPanelShort extends Composite {
|
class ContactPanelShort extends Composite {
|
||||||
protected final FlowPanel body;
|
protected final FlowPanel body;
|
||||||
protected int labelIdx, fieldIdx;
|
protected int labelIdx, fieldIdx;
|
||||||
@@ -210,28 +204,19 @@ class ContactPanelShort extends Composite {
|
|||||||
postLoad();
|
postLoad();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Util.ACCOUNT_SEC
|
AccountApi.getEmails("self", new GerritCallback<JsArray<EmailInfo>>() {
|
||||||
.myExternalIds(new GerritCallback<List<AccountExternalId>>() {
|
@Override
|
||||||
public void onSuccess(final List<AccountExternalId> result) {
|
public void onSuccess(JsArray<EmailInfo> result) {
|
||||||
if (!isAttached()) {
|
if (!isAttached()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Set<String> emails = new HashSet<String>();
|
for (EmailInfo i : Natives.asList(result)) {
|
||||||
for (final AccountExternalId i : result) {
|
emailPick.addItem(i.email());
|
||||||
if (i.getEmailAddress() != null
|
}
|
||||||
&& i.getEmailAddress().length() > 0) {
|
haveEmails = true;
|
||||||
emails.add(i.getEmailAddress());
|
postLoad();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
final List<String> addrs = new ArrayList<String>(emails);
|
|
||||||
Collections.sort(addrs);
|
|
||||||
for (String s : addrs) {
|
|
||||||
emailPick.addItem(s);
|
|
||||||
}
|
|
||||||
haveEmails = true;
|
|
||||||
postLoad();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postLoad() {
|
private void postLoad() {
|
||||||
@@ -284,9 +269,9 @@ class ContactPanelShort extends Composite {
|
|||||||
|
|
||||||
inEmail.setEnabled(false);
|
inEmail.setEnabled(false);
|
||||||
register.setEnabled(false);
|
register.setEnabled(false);
|
||||||
AccountApi.registerEmail("self", addr, new GerritCallback<NativeString>() {
|
AccountApi.registerEmail("self", addr, new GerritCallback<EmailInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(NativeString result) {
|
public void onSuccess(EmailInfo result) {
|
||||||
box.hide();
|
box.hide();
|
||||||
if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
|
if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
|
||||||
currentEmail = addr;
|
currentEmail = addr;
|
||||||
|
@@ -0,0 +1,26 @@
|
|||||||
|
// 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.gwt.core.client.JavaScriptObject;
|
||||||
|
|
||||||
|
public class EmailInfo extends JavaScriptObject {
|
||||||
|
public final native String email() /*-{ return this.email; }-*/;
|
||||||
|
public final native boolean isPreferred() /*-{ return this['preferred'] ? true : false; }-*/;
|
||||||
|
public final native boolean isConfirmationPending() /*-{ return this['pending_confirmation'] ? true : false; }-*/;
|
||||||
|
|
||||||
|
protected EmailInfo() {
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user