Avoid 500s when a topic includes changes that are not visible

/action and /submitted_together requests are throwing OrmException
when they are not able to examine non-visible changes in the topic:

 com.google.gwtorm.server.OrmException: Failed to get submit type for 12345: Patch set 12345,6 not found
        at com.google.gerrit.server.git.MergeSuperSet.logErrorAndThrow(MergeSuperSet.java:218)
        at com.google.gerrit.server.git.MergeSuperSet.completeChangeSetWithoutTopic(MergeSuperSet.java:122)
        at com.google.gerrit.server.git.MergeSuperSet.completeChangeSetIncludingTopics(MergeSuperSet.java:180)
        at com.google.gerrit.server.git.MergeSuperSet.completeChangeSet(MergeSuperSet.java:101)
        at com.google.gerrit.server.change.SubmittedTogether.getForOpenChange(SubmittedTogether.java:105)
        at com.google.gerrit.server.change.SubmittedTogether.apply(SubmittedTogether.java:78)
        at com.google.gerrit.server.change.SubmittedTogether.apply(SubmittedTogether.java:46)
        at com.google.gerrit.httpd.restapi.RestApiServlet.service(RestApiServlet.java:332)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

The result is a lightbox with a 500 when the user views a change in
the same topic as a draft change the user cannot see.

As a first step toward fixing that, use response code 403 instead.
This allows automated callers to get a better sense of what is going
on (it is a permissions error, not an internal server error) without
being confused by an unexpected response (e.g., an abbreviated list of
changes).

Change-Id: I560508c8d941fa6be140363f5bb103c3da4fac05
This commit is contained in:
Jonathan Nieder
2016-06-15 16:10:52 -07:00
parent 27d460cfa9
commit 669c6cf68b
8 changed files with 129 additions and 12 deletions

View File

@@ -101,8 +101,12 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
}
private List<ChangeData> getForOpenChange(Change c, CurrentUser user)
throws OrmException, IOException {
throws OrmException, IOException, AuthException {
ChangeSet cs = mergeSuperSet.completeChangeSet(dbProvider.get(), c, user);
if (cs.furtherHiddenChanges()) {
throw new AuthException(
"change would be submitted with a change that you cannot see");
}
return cs.changes().asList();
}