ListDashboards: move project state check forward
Change-Id: I3be47adb48884023c0992c2a9a54edddf876caa7
This commit is contained in:
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.project;
|
|||||||
|
|
||||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DASHBOARDS;
|
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DASHBOARDS;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -100,15 +101,15 @@ public class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
|
|
||||||
private List<DashboardInfo> scan(ProjectState state, String project, boolean setDefault)
|
private List<DashboardInfo> scan(ProjectState state, String project, boolean setDefault)
|
||||||
throws ResourceNotFoundException, IOException, PermissionBackendException {
|
throws ResourceNotFoundException, IOException, PermissionBackendException {
|
||||||
|
if (!state.statePermitsRead()) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
PermissionBackend.ForProject perm = permissionBackend.currentUser().project(state.getNameKey());
|
PermissionBackend.ForProject perm = permissionBackend.currentUser().project(state.getNameKey());
|
||||||
try (Repository git = gitManager.openRepository(state.getNameKey());
|
try (Repository git = gitManager.openRepository(state.getNameKey());
|
||||||
RevWalk rw = new RevWalk(git)) {
|
RevWalk rw = new RevWalk(git)) {
|
||||||
List<DashboardInfo> all = new ArrayList<>();
|
List<DashboardInfo> all = new ArrayList<>();
|
||||||
for (Ref ref : git.getRefDatabase().getRefsByPrefix(REFS_DASHBOARDS)) {
|
for (Ref ref : git.getRefDatabase().getRefsByPrefix(REFS_DASHBOARDS)) {
|
||||||
if (!state.statePermitsRead()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
perm.ref(ref.getName()).check(RefPermission.READ);
|
perm.ref(ref.getName()).check(RefPermission.READ);
|
||||||
all.addAll(scanDashboards(state.getProject(), git, rw, ref, project, setDefault));
|
all.addAll(scanDashboards(state.getProject(), git, rw, ref, project, setDefault));
|
||||||
|
Reference in New Issue
Block a user