Obsolete PermissionBackend#indexedChange

When refactoring Gerrit's code to move all callers to use
PermissionBackend for all permission checks, we introduced indexedChange
as a way to contruct a PermissionBackend from a change that we recovered
from the index (i.e. has no ChangeNotes).

This commit refactors the logic in PermissionBackend and as an end
result, we obsolete #indexedChange. If a change was contructed from the
index, callers have ChangeData and can just pass this into
PermissionBackend. Callers who got the entity from the primary storage
can pass ChangeNotes instead.

This is an effort to make the DETAILED_LABELS ListChangesOption not
require lazyload as well as a general refactoring of the code.

Change-Id: I3dfd8f91dbaf54bb472b6c922d798365fe539674
This commit is contained in:
Patrick Hiesel
2020-03-06 16:38:30 +01:00
parent e96815ac36
commit 707c75541a
15 changed files with 109 additions and 149 deletions

View File

@@ -674,7 +674,9 @@ public class ChangeData {
public ReviewerSet reviewers() {
if (reviewers == null) {
if (!lazyLoad) {
return ReviewerSet.empty();
// We are not allowed to load values from NoteDb. Reviewers were not populated with values
// from the index. However, we need these values for permission checks.
throw new IllegalStateException("reviewers not populated");
}
reviewers = approvalsUtil.getReviewers(notes(), approvals().values());
}
@@ -685,10 +687,6 @@ public class ChangeData {
this.reviewers = reviewers;
}
public ReviewerSet getReviewers() {
return reviewers;
}
public ReviewerByEmailSet reviewersByEmail() {
if (reviewersByEmail == null) {
if (!lazyLoad) {

View File

@@ -67,7 +67,6 @@ public class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData>
return false;
}
ChangeNotes notes = notesFactory.createFromIndexedChange(change);
Optional<ProjectState> projectState = projectCache.get(cd.project());
if (!projectState.isPresent()) {
logger.atFine().log("Filter out change %s of non-existing project %s", cd, cd.project());
@@ -83,7 +82,7 @@ public class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData>
? permissionBackend.absentUser(user.getAccountId())
: permissionBackend.user(anonymousUserProvider.get());
try {
withUser.indexedChange(cd, notes).check(ChangePermission.READ);
withUser.change(cd).check(ChangePermission.READ);
} catch (PermissionBackendException e) {
Throwable cause = e.getCause();
if (cause instanceof RepositoryNotFoundException) {