Hide change if project can't be found in ChangeIsVisibleToPredicate

A recent refactoring added a permission backend check to
ChangeIsVisibleToPredicate. This check would error out with HTTP 500 if
the index data is stale and the project can't be found.

This commit fixes that.

Change-Id: Iba07eb140be0ad11d4d9de2393bb5633bcadd592
This commit is contained in:
Patrick Hiesel
2017-10-11 14:15:21 +02:00
parent 14c3be0d4d
commit e021b02ef3
2 changed files with 10 additions and 1 deletions

View File

@@ -75,7 +75,7 @@ public class DefaultPermissionBackend extends PermissionBackend {
if (state != null) {
return state.controlFor(user).asForProject().database(db);
}
return FailedPermissionBackend.project("not found");
return FailedPermissionBackend.project("not found", new NoSuchProjectException(project));
} catch (IOException e) {
return FailedPermissionBackend.project("unavailable", e);
}

View File

@@ -23,10 +23,15 @@ import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.permissions.ChangePermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData> {
private static final Logger logger = LoggerFactory.getLogger(ChangeIsVisibleToPredicate.class);
protected final Provider<ReviewDb> db;
protected final ChangeNotes.Factory notesFactory;
protected final CurrentUser user;
@@ -64,6 +69,10 @@ public class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData>
.database(db)
.test(ChangePermission.READ);
} catch (PermissionBackendException e) {
if (e.getCause() instanceof NoSuchProjectException) {
logger.info("No such project: {}", cd.project());
return false;
}
throw new OrmException("unable to check permissions", e);
}
if (visible) {