Add an optional Account.Id to UserIdentity within PatchSetInfo
This way we can link to a user's dashboard if they were the one who authored or committed a change. Due to the way Git commits are made not every email address field will necessarily match up to a Gerrit account identity, so the field is optional and the client UI doesn't draw a hyperlink of the account field isn't populated. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -16,16 +16,20 @@ package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.Link;
|
||||
import com.google.gerrit.client.SignedInListener;
|
||||
import com.google.gerrit.client.data.ApprovalType;
|
||||
import com.google.gerrit.client.data.ChangeDetail;
|
||||
import com.google.gerrit.client.data.PatchSetDetail;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
import com.google.gerrit.client.reviewdb.PatchSetInfo;
|
||||
import com.google.gerrit.client.reviewdb.UserIdentity;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.DomUtil;
|
||||
import com.google.gerrit.client.ui.RefreshListener;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.ClickListener;
|
||||
@@ -122,8 +126,9 @@ class PatchSetPanel extends Composite implements DisclosureHandler {
|
||||
itfmt.addStyleName(R_COMMITTER, 1, "useridentity");
|
||||
itfmt.addStyleName(R_DOWNLOAD, 1, "command");
|
||||
|
||||
infoTable.setText(R_AUTHOR, 1, format(detail.getInfo().getAuthor()));
|
||||
infoTable.setText(R_COMMITTER, 1, format(detail.getInfo().getCommitter()));
|
||||
final PatchSetInfo info = detail.getInfo();
|
||||
displayUserIdentity(R_AUTHOR, info.getAuthor());
|
||||
displayUserIdentity(R_COMMITTER, info.getCommitter());
|
||||
infoTable.setText(R_DOWNLOAD, 1, Util.M.repoDownload(changeDetail
|
||||
.getChange().getDest().getParentKey().get(), changeDetail.getChange()
|
||||
.getChangeId(), patchSet.getPatchSetId()));
|
||||
@@ -158,26 +163,44 @@ class PatchSetPanel extends Composite implements DisclosureHandler {
|
||||
body.add(patchTable);
|
||||
}
|
||||
|
||||
private String format(final UserIdentity who) {
|
||||
final StringBuilder r = new StringBuilder();
|
||||
if (who.getName() != null) {
|
||||
r.append(who.getName());
|
||||
private void displayUserIdentity(final int row, final UserIdentity who) {
|
||||
if (who == null) {
|
||||
infoTable.clearCell(row, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
final StringBuilder r = new StringBuilder();
|
||||
|
||||
if (who.getName() != null) {
|
||||
final Account.Id aId = who.getAccount();
|
||||
if (aId != null) {
|
||||
r.append("<a href=\"#");
|
||||
r.append(Link.toAccountDashboard(aId));
|
||||
r.append("\">");
|
||||
}
|
||||
r.append(DomUtil.escape(who.getName()));
|
||||
if (aId != null) {
|
||||
r.append("</a>");
|
||||
}
|
||||
}
|
||||
|
||||
if (who.getEmail() != null) {
|
||||
if (r.length() > 0) {
|
||||
r.append(' ');
|
||||
}
|
||||
r.append('<');
|
||||
r.append(who.getEmail());
|
||||
r.append('>');
|
||||
r.append("<");
|
||||
r.append(DomUtil.escape(who.getEmail()));
|
||||
r.append(">");
|
||||
}
|
||||
|
||||
if (who.getDate() != null) {
|
||||
if (r.length() > 0) {
|
||||
r.append(' ');
|
||||
}
|
||||
r.append(FormatUtil.mediumFormat(who.getDate()));
|
||||
r.append(DomUtil.escape(FormatUtil.mediumFormat(who.getDate())));
|
||||
}
|
||||
return r.toString();
|
||||
|
||||
infoTable.setHTML(row, 1, r.toString());
|
||||
}
|
||||
|
||||
private void populateActions(final PatchSetDetail detail) {
|
||||
|
@@ -35,6 +35,10 @@ public final class UserIdentity {
|
||||
@Column
|
||||
protected int tz;
|
||||
|
||||
/** If the user has a Gerrit account, their account identity. */
|
||||
@Column(notNull = false)
|
||||
protected Account.Id accountId;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -66,4 +70,12 @@ public final class UserIdentity {
|
||||
public void setTimeZone(final int offset) {
|
||||
tz = offset;
|
||||
}
|
||||
|
||||
public Account.Id getAccount() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccount(final Account.Id id) {
|
||||
accountId = id;
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.git;
|
||||
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.AccountExternalId;
|
||||
import com.google.gerrit.client.reviewdb.Patch;
|
||||
import com.google.gerrit.client.reviewdb.PatchContent;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
@@ -44,9 +46,11 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Imports a {@link PatchSet} from a {@link Commit}. */
|
||||
public class PatchSetImporter {
|
||||
@@ -148,7 +152,7 @@ public class PatchSetImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private void importInfo() {
|
||||
private void importInfo() throws OrmException {
|
||||
if (info == null) {
|
||||
info = new PatchSetInfo(dst.getId());
|
||||
infoIsNew = true;
|
||||
@@ -171,12 +175,28 @@ public class PatchSetImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private UserIdentity toUserIdentity(final PersonIdent who) {
|
||||
private UserIdentity toUserIdentity(final PersonIdent who)
|
||||
throws OrmException {
|
||||
final UserIdentity u = new UserIdentity();
|
||||
u.setName(who.getName());
|
||||
u.setEmail(who.getEmailAddress());
|
||||
u.setDate(new Timestamp(who.getWhen().getTime()));
|
||||
u.setTimeZone(who.getTimeZoneOffset());
|
||||
|
||||
if (u.getEmail() != null) {
|
||||
// If only one account has access to this email address, select it
|
||||
// as the identity of the user.
|
||||
//
|
||||
final Set<Account.Id> a = new HashSet<Account.Id>();
|
||||
for (final AccountExternalId e : db.accountExternalIds().byEmailAddress(
|
||||
u.getEmail())) {
|
||||
a.add(e.getAccountId());
|
||||
}
|
||||
if (a.size() == 1) {
|
||||
u.setAccount(a.iterator().next());
|
||||
}
|
||||
}
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user