Skip to content

Commit

Permalink
Merge pull request #176 from wikimedia/phab/T76165
Browse files Browse the repository at this point in the history
Minor fixes from #172
  • Loading branch information
gwicke committed Feb 13, 2015
2 parents 4d87db7 + d9c847e commit 62e08a2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mods/page_revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ PRS.prototype.getTableSchema = function () {
* @throws rbUtil.httpError if access to the revision should be denied
*/
PRS.prototype._checkRevReturn = function(res) {
var item = res && res.body && Array.isArray(res.body.items) && res.body.items[0];
var item = res.body.items.length && res.body.items[0];
// if there are any restrictions imposed on this
// revision, forbid its retrieval, cf.
// https://phabricator.wikimedia.org/T76165#1030962
if (item && Array.isArray(item.restrictions) && item.restrictions.length > 0) {
// there are some restrictions, deny access to the revision
return Promise.reject(new rbUtil.HTTPError({
throw new rbUtil.HTTPError({
status: 403,
body: {
type: 'access_denied#revision',
title: 'Access to resource denied',
description: 'Access is restricted for revision ' + item.rev,
restrictions: item.restrictions
}
}));
});
}
return Promise.resolve(res);
}
Expand Down Expand Up @@ -253,8 +253,9 @@ PRS.prototype.getTitleRevision = function(restbase, req) {
throw new Error("Invalid revision: " + rp.revision);
}
return revisionRequest
.then(self._checkRevReturn)
.then(function(res) {
// check if the revision has any restrictions
self._checkRevReturn(res);
if (!res.headers) {
res.headers = {};
}
Expand Down

0 comments on commit 62e08a2

Please sign in to comment.