Skip to content

Commit

Permalink
Merge "Only show draft change dependency if current user is owner or …
Browse files Browse the repository at this point in the history
…reviewer"
  • Loading branch information
spearce authored and gerrit code review committed Jun 27, 2012
2 parents 1d69cab + c4e5006 commit 9d92e48
Showing 1 changed file with 27 additions and 2 deletions.
Expand Up @@ -32,6 +32,7 @@
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.ProjectUtil;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
Expand All @@ -41,6 +42,7 @@
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.workflow.CategoryFunction;
import com.google.gerrit.server.workflow.FunctionState;
import com.google.gwtorm.server.OrmException;
Expand Down Expand Up @@ -252,6 +254,15 @@ private void load() throws OrmException, NoSuchChangeException {
detail.setApprovals(ad.values());
}

private boolean isReviewer(Change change) {
// Return true if the currently logged in user is a reviewer of the change.
try {
return control.isReviewer(db, new ChangeData(change));
} catch (OrmException e) {
return false;
}
}

private void loadCurrentPatchSet() throws OrmException,
NoSuchEntityException, PatchSetInfoNotAvailableException,
NoSuchChangeException {
Expand Down Expand Up @@ -292,19 +303,33 @@ private void loadCurrentPatchSet() throws OrmException,
final Map<Change.Id, Change> m =
db.changes().toMap(db.changes().get(changesToGet));

final CurrentUser currentUser = control.getCurrentUser();
Account.Id currentUserId = null;
if (currentUser instanceof IdentifiedUser) {
currentUserId = ((IdentifiedUser) currentUser).getAccountId();
}

final ArrayList<ChangeInfo> dependsOn = new ArrayList<ChangeInfo>();
for (final Change.Id a : ancestorOrder) {
final Change ac = m.get(a);
if (ac != null && ac.getProject().equals(detail.getChange().getProject())) {
dependsOn.add(newChangeInfo(ac, ancestorPatchIds));
if (ac.getStatus().getCode() != Change.STATUS_DRAFT
|| ac.getOwner().equals(currentUserId)
|| isReviewer(ac)) {
dependsOn.add(newChangeInfo(ac, ancestorPatchIds));
}
}
}

final ArrayList<ChangeInfo> neededBy = new ArrayList<ChangeInfo>();
for (final PatchSet.Id a : descendants) {
final Change ac = m.get(a.getParentKey());
if (ac != null && ac.currentPatchSetId().equals(a)) {
neededBy.add(newChangeInfo(ac, null));
if (ac.getStatus().getCode() != Change.STATUS_DRAFT
|| ac.getOwner().equals(currentUserId)
|| isReviewer(ac)) {
neededBy.add(newChangeInfo(ac, null));
}
}
}

Expand Down

0 comments on commit 9d92e48

Please sign in to comment.