Hide ChangeControl#isVisible and migrate callers to PermissionBackend

Change-Id: I8cec3c3c182e0ca2b684370e5beeae11a95b69a1
This commit is contained in:
Patrick Hiesel
2017-08-03 08:54:36 +02:00
parent d501e25340
commit 5116a9984a
33 changed files with 242 additions and 115 deletions

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.ChangesCollection;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.permissions.ChangePermission;
import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -68,13 +69,13 @@ public class ChangeArgumentParser {
}
public void addChange(String id, Map<Change.Id, ChangeResource> changes)
throws UnloggedFailure, OrmException {
throws UnloggedFailure, OrmException, PermissionBackendException {
addChange(id, changes, null);
}
public void addChange(
String id, Map<Change.Id, ChangeResource> changes, ProjectControl projectControl)
throws UnloggedFailure, OrmException {
throws UnloggedFailure, OrmException, PermissionBackendException {
addChange(id, changes, projectControl, true);
}
@@ -83,7 +84,7 @@ public class ChangeArgumentParser {
Map<Change.Id, ChangeResource> changes,
ProjectControl projectControl,
boolean useIndex)
throws UnloggedFailure, OrmException {
throws UnloggedFailure, OrmException, PermissionBackendException {
List<ChangeControl> matched =
useIndex ? changeFinder.find(id, currentUser) : changeFromNotesFactory(id, currentUser);
List<ChangeControl> toAdd = new ArrayList<>(changes.size());
@@ -97,7 +98,12 @@ public class ChangeArgumentParser {
for (ChangeControl ctl : matched) {
if (!changes.containsKey(ctl.getId())
&& inProject(projectControl, ctl.getProject())
&& (canMaintainServer || ctl.isVisible(db))) {
&& (canMaintainServer
|| permissionBackend
.user(currentUser)
.change(ctl.getNotes())
.database(db)
.test(ChangePermission.READ))) {
toAdd.add(ctl);
}
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.Index;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.sshd.ChangeArgumentParser;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
@@ -42,7 +43,7 @@ final class IndexChangesCommand extends SshCommand {
void addChange(String token) {
try {
changeArgumentParser.addChange(token, changes, null, false);
} catch (UnloggedFailure | OrmException e) {
} catch (UnloggedFailure | OrmException | PermissionBackendException e) {
writeError("warning", e.getMessage());
}
}

View File

@@ -23,6 +23,7 @@ import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.DeleteReviewer;
import com.google.gerrit.server.change.PostReviewers;
import com.google.gerrit.server.change.ReviewerResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.sshd.ChangeArgumentParser;
import com.google.gerrit.sshd.CommandMetaData;
@@ -79,6 +80,8 @@ public class SetReviewersCommand extends SshCommand {
throw new IllegalArgumentException(e.getMessage(), e);
} catch (OrmException e) {
throw new IllegalArgumentException("database is down", e);
} catch (PermissionBackendException e) {
throw new IllegalArgumentException("can't check permissions", e);
}
}