ChangeUtil: Fix findChanges for anonymous users
In I7710befa I didn't realize the user provider was a Provider<IdentifiedUser>, which caused a ProvisionException when anonymous users tried to use the REST API to look up changes by something other than a number. This wasn't noticed sooner because it didn't affect the web UI, which exclusively uses change numbers. Change to Provider<CurrentUser> and use asIdentifiedUser only at the sites where an IdentifiedUser is needed. This will throw a different unchecked exception type on failure (UnsupportedOperationException instead of ProvisionException), but callers aren't depending on that. Add a test, during which I also discovered a bug in the implementation of AbstractDaemonTest#setApiUserAnonymous. That wasn't already causing failures because the only user was using it to avoid some side effects that "may" have happened. Change-Id: Idbad114d6f5a61167d6fda32ee0093558491cf8e
This commit is contained in:
@@ -177,7 +177,7 @@ public class ChangeUtil {
|
||||
return subject;
|
||||
}
|
||||
|
||||
private final Provider<IdentifiedUser> user;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<InternalChangeQuery> queryProvider;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
@@ -192,7 +192,7 @@ public class ChangeUtil {
|
||||
private final StarredChangesUtil starredChangesUtil;
|
||||
|
||||
@Inject
|
||||
ChangeUtil(Provider<IdentifiedUser> user,
|
||||
ChangeUtil(Provider<CurrentUser> user,
|
||||
Provider<ReviewDb> db,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
@@ -238,7 +238,7 @@ public class ChangeUtil {
|
||||
RevCommit commitToRevert =
|
||||
revWalk.parseCommit(ObjectId.fromString(patch.getRevision().get()));
|
||||
|
||||
PersonIdent authorIdent = user.get()
|
||||
PersonIdent authorIdent = user.get().asIdentifiedUser()
|
||||
.newCommitterIdent(myIdent.getWhen(), myIdent.getTimeZone());
|
||||
|
||||
if (commitToRevert.getParentCount() == 0) {
|
||||
|
||||
Reference in New Issue
Block a user