Hack in HTTP URL to always be available on changes

The {android-review,gerrit-review}.googlesource.com servers have a
weird failure condition where draft changes do not make available
the PULL, CHECKOUT, or CHERRY_PICK options on a patch set because
the change is not yet visible to anonymous users. This leaves the
change owner with only a "repo download" link, which is useless
for Gerrit development itself.

The root cause is these servers don't really have user names for
end users... for reasons I won't get into in this commit message.

Work around the problem by detecting a condition that only exists on
the {android-review,gerrit-review} environment and showing the HTTP
URL no matter what. The condition is gerrit.gitHttpUrl exists, and
AuthType is CUSTOM_EXTENSION. These servers are the only known uses
of CUSTOM_EXTENSION, as implementing such a backend is extremely
non-trivial.

While we are providing this hack, also hide the username field in
the contexts that it shows up empty. Showing an empty box the user
cannot edit doesn't help anyone on these sites.

Eventually this hack can be backed out when we get moved over to
authentication backends being fully supported through the new plugin
system. But we aren't there yet, and won't be for several months
(due to the amount of refactoring and schema changes involved to
make that possible). So hack the UI for now.

Change-Id: I1b30c4dec4cdf9f6726d7b966f7608b26b59a069
This commit is contained in:
Shawn O. Pearce
2012-05-17 16:16:46 -07:00
parent e3d23d64eb
commit de5bf0172d
4 changed files with 50 additions and 22 deletions

View File

@@ -16,9 +16,10 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.auth.openid.OpenIdProviderPattern;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gwtexpui.safehtml.client.RegexFindReplace;
import java.util.List;
@@ -199,4 +200,13 @@ public class GerritConfig implements Cloneable {
public void setAnonymousCowardName(final String anonymousCowardName) {
this.anonymousCowardName = anonymousCowardName;
}
public boolean siteHasUsernames() {
if (getAuthType() == AuthType.CUSTOM_EXTENSION
&& getHttpPasswordUrl() != null
&& !canEdit(FieldName.USER_NAME)) {
return false;
}
return true;
}
}

View File

@@ -102,7 +102,8 @@ class ContactPanelShort extends Composite {
}
int row = 0;
if (!Gerrit.getConfig().canEdit(FieldName.USER_NAME)) {
if (!Gerrit.getConfig().canEdit(FieldName.USER_NAME)
&& Gerrit.getConfig().siteHasUsernames()) {
infoPlainText.resizeRows(infoPlainText.getRowCount() + 1);
row(infoPlainText, row++, Util.C.userName(), new UsernameField());
}

View File

@@ -38,21 +38,24 @@ public class MyProfileScreen extends SettingsScreen {
fieldIdx = 1;
}
info = new Grid(5, 2);
info = new Grid((Gerrit.getConfig().siteHasUsernames() ? 1 : 0) + 4, 2);
info.setStyleName(Gerrit.RESOURCES.css().infoBlock());
info.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());
add(info);
infoRow(0, Util.C.userName());
infoRow(1, Util.C.fullName());
infoRow(2, Util.C.preferredEmail());
infoRow(3, Util.C.registeredOn());
infoRow(4, Util.C.accountId());
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
infoRow(row++, Util.C.userName());
}
infoRow(row++, Util.C.fullName());
infoRow(row++, Util.C.preferredEmail());
infoRow(row++, Util.C.registeredOn());
infoRow(row++, Util.C.accountId());
final CellFormatter fmt = info.getCellFormatter();
fmt.addStyleName(0, 0, Gerrit.RESOURCES.css().topmost());
fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().topmost());
fmt.addStyleName(4, 0, Gerrit.RESOURCES.css().bottomheader());
fmt.addStyleName(row - 1, 0, Gerrit.RESOURCES.css().bottomheader());
}
@Override
@@ -69,10 +72,13 @@ public class MyProfileScreen extends SettingsScreen {
}
void display(final Account account) {
info.setWidget(0, fieldIdx, new UsernameField());
info.setText(1, fieldIdx, account.getFullName());
info.setText(2, fieldIdx, account.getPreferredEmail());
info.setText(3, fieldIdx, mediumFormat(account.getRegisteredOn()));
info.setText(4, fieldIdx, account.getId().toString());
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
info.setWidget(row++, fieldIdx, new UsernameField());
}
info.setText(row++, fieldIdx, account.getFullName());
info.setText(row++, fieldIdx, account.getPreferredEmail());
info.setText(row++, fieldIdx, mediumFormat(account.getRegisteredOn()));
info.setText(row++, fieldIdx, account.getId().toString());
}
}

View File

@@ -30,6 +30,7 @@ import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.Patch;
@@ -232,9 +233,8 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
.anonymousDownload("HTTP"), r.toString()));
}
if (Gerrit.getConfig().getSshdAddress() != null && Gerrit.isSignedIn()
&& Gerrit.getUserAccount().getUserName() != null
&& Gerrit.getUserAccount().getUserName().length() > 0
if (Gerrit.getConfig().getSshdAddress() != null
&& hasUserName()
&& (allowedSchemes.contains(DownloadScheme.SSH) ||
allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
String sshAddr = Gerrit.getConfig().getSshdAddress();
@@ -256,13 +256,12 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
urls.add(new DownloadUrlLink(DownloadScheme.SSH, "SSH", r.toString()));
}
if (Gerrit.isSignedIn() && Gerrit.getUserAccount().getUserName() != null
&& Gerrit.getUserAccount().getUserName().length() > 0
&& (allowedSchemes.contains(DownloadScheme.HTTP) ||
allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
if ((hasUserName() || siteReliesOnHttp())
&& (allowedSchemes.contains(DownloadScheme.HTTP)
|| allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
final StringBuilder r = new StringBuilder();
if (Gerrit.getConfig().getGitHttpUrl() != null
&& changeDetail.isAllowsAnonymous()) {
&& (changeDetail.isAllowsAnonymous() || siteReliesOnHttp())) {
r.append(Gerrit.getConfig().getGitHttpUrl());
} else {
String base = hostPageUrl;
@@ -372,6 +371,18 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
infoTable.setWidget(R_DOWNLOAD, 1, fp);
}
private static boolean siteReliesOnHttp() {
return Gerrit.getConfig().getGitHttpUrl() != null
&& Gerrit.getConfig().getAuthType() == AuthType.CUSTOM_EXTENSION
&& !Gerrit.getConfig().siteHasUsernames();
}
private static boolean hasUserName() {
return Gerrit.isSignedIn()
&& Gerrit.getUserAccount().getUserName() != null
&& Gerrit.getUserAccount().getUserName().length() > 0;
}
private void displayUserIdentity(final int row, final UserIdentity who) {
if (who == null) {
infoTable.clearCell(row, 1);