Add Edit, Reload next to non-editable Full Name field

On {android-review,gerrit-review}.googlesource.com the user database
is actually an external system. To configure a name the needs to go
edit fields on another server, and then re-import their account data
by going through a login cycle. This is highly similiar to LDAP where
the directory provides account data and its refreshed every time the
user visits the /login/ URL handler.

Allow CUSTOM_EXTENSION auth type to supply a URL in the web UI
that links the user to the other account system, where they can
edit their name, and then use another reload URL to cycle through
the /login/ step and refresh the data cached by Gerrit Code Review.

Like the rest of the CUSTOM_EXTENSION stuff, this is hack that will
eventually go away when we have proper support for authentication
plugins. Until that time, wedge in something slightly more useful
to the average user.

Change-Id: I244e10967c90311c5ad51d019a5abfc333a65688
This commit is contained in:
Shawn O. Pearce
2012-05-17 16:52:22 -07:00
parent de5bf0172d
commit 6fa1e9121d
7 changed files with 48 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ public class GerritConfig implements Cloneable {
protected String gitDaemonUrl;
protected String gitHttpUrl;
protected String sshdAddress;
protected String editFullNameUrl;
protected Project.NameKey wildProject;
protected ApprovalTypes approvalTypes;
protected Set<Account.FieldName> editableAccountFields;
@@ -55,6 +56,14 @@ public class GerritConfig implements Cloneable {
registerUrl = u;
}
public String getEditFullNameUrl() {
return editFullNameUrl;
}
public void setEditFullNameUrl(String u) {
editFullNameUrl = u;
}
public String getHttpPasswordUrl() {
return httpPasswordUrl;
}

View File

@@ -266,7 +266,7 @@ public class Gerrit implements EntryPoint {
}
}
private static String loginRedirect(String token) {
public static String loginRedirect(String token) {
if (token == null) {
token = "";
} else if (token.startsWith("/")) {

View File

@@ -57,6 +57,8 @@ public interface AccountConstants extends Constants {
String buttonClearPassword();
String buttonGeneratePassword();
String linkObtainPassword();
String linkEditFullName();
String linkReloadContact();
String invalidUserName();
String invalidUserEmail();

View File

@@ -38,6 +38,8 @@ buttonChangeUserName = Change Username
buttonClearPassword = Clear Password
buttonGeneratePassword = Generate Password
linkObtainPassword = Obtain Password
linkEditFullName = Edit
linkReloadContact = Reload
invalidUserName = Username must contain only letters, numbers, _, - or .
invalidUserEmail = Email format is wrong.
sshKeyInvalid = Invalid Key

View File

@@ -18,17 +18,18 @@ import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Account;
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.ContactInformation;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
@@ -41,6 +42,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwtexpui.globalkey.client.NpTextBox;
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
import com.google.gwtjsonrpc.common.AsyncCallback;
import java.util.ArrayList;
import java.util.Collections;
@@ -108,7 +110,31 @@ class ContactPanelShort extends Composite {
row(infoPlainText, row++, Util.C.userName(), new UsernameField());
}
row(infoPlainText, row++, Util.C.contactFieldFullName(), nameTxt);
if (!canEditFullName()) {
FlowPanel nameLine = new FlowPanel();
nameLine.add(nameTxt);
if (Gerrit.getConfig().getEditFullNameUrl() != null) {
Button edit = new Button(Util.C.linkEditFullName());
edit.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open(Gerrit.getConfig().getEditFullNameUrl(), "_blank", null);
}
});
nameLine.add(edit);
}
Button reload = new Button(Util.C.linkReloadContact());
reload.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.Location.replace(Gerrit.loginRedirect(PageLinks.SETTINGS_CONTACT));
}
});
nameLine.add(reload);
row(infoPlainText, row++, Util.C.contactFieldFullName(), nameLine);
} else {
row(infoPlainText, row++, Util.C.contactFieldFullName(), nameTxt);
}
row(infoPlainText, row++, Util.C.contactFieldEmail(), emailLine);
infoPlainText.getCellFormatter().addStyleName(0, 0, Gerrit.RESOURCES.css().topmost());

View File

@@ -1111,6 +1111,9 @@ a:hover.downloadLink {
.accountInfoBlock {
margin-bottom: 10px;
}
.accountInfoBlock .gwt-Button {
margin-left: 10px;
}
.accountContactPrivacyDetails {
margin-left: 10px;
margin-top: 5px;

View File

@@ -93,10 +93,12 @@ class GerritConfigProvider implements Provider<GerritConfig> {
case LDAP:
case LDAP_BIND:
config.setRegisterUrl(cfg.getString("auth", null, "registerurl"));
config.setEditFullNameUrl(cfg.getString("auth", null, "editFullNameUrl"));
break;
case CUSTOM_EXTENSION:
config.setRegisterUrl(cfg.getString("auth", null, "registerurl"));
config.setEditFullNameUrl(cfg.getString("auth", null, "editFullNameUrl"));
config.setHttpPasswordUrl(cfg.getString("auth", null, "httpPasswordUrl"));
break;
}