@@ -123,7 +123,6 @@ ACL.prototype.findACL = function(mode, address, userId, callback) {
123123 async . whilst (
124124 // Check if we have gone through all the `/` in relativePath
125125 function ( ) {
126- console . log ( i ) ;
127126 return i ++ < depth . length ;
128127 } ,
129128 function ( done ) {
@@ -177,16 +176,16 @@ ACL.prototype.findACL = function(mode, address, userId, callback) {
177176 // result is false when no policy is found
178177 if ( ! result ) {
179178 debug ( "No ACL policies present - access allowed" ) ;
180- return callback ( null , true ) ;
179+ return callback ( null ) ;
181180 }
182181
183182 // result is true if ACL statement is found
184183 if ( result === true ) {
185184 debug ( "ACL allowed" ) ;
186- return callback ( null , true ) ;
185+ return callback ( null ) ;
187186 }
188187
189- // result is an object (since obj !== true)
188+ // result is an object (since result !== true)
190189 // the object is of the type {status: 40[0-9], message: String}
191190 return callback ( result ) ;
192191 }
@@ -198,7 +197,6 @@ ACL.prototype.findACL = function(mode, address, userId, callback) {
198197 * @param {Object } err Error occurred when reading the acl file
199198 * @param {Number } err.status Status code of the error (HTTP way)
200199 * @param {String } err.message Reason of the error
201- * @param {Boolean } result Found valid ACL statement
202200 */
203201
204202ACL . prototype . allowMode = function ( mode , userId , aclGraph , accessType , pathUri , callback ) {
@@ -209,20 +207,16 @@ ACL.prototype.allowMode = function (mode, userId, aclGraph, accessType, pathUri,
209207 debug ( "Found " + accessType + " policy for <" + mode + ">" ) ;
210208
211209 var accessTypeStatements = aclGraph . each ( modeElem , ns . acl ( accessType ) , aclGraph . sym ( pathUri ) ) ;
212-
213- console . log ( "-- accessTypeStatements" , accessTypeStatements . length )
214210 async . some ( accessTypeStatements , function ( accessTypeElem , next ) {
215211 var origins = aclGraph . each ( modeElem , ns . acl ( "origin" ) , undefined ) ;
216-
217- console . log ( "-- ACL origins, " , acl . origin , origins )
218- console . log ( "-- ACL origins lengths " , acl . origin . length , origins . length )
219212 if ( acl . origin . length > 0 && origins . length > 0 ) {
220213 debug ( "Origin set to: " + rdfVocab . brack ( acl . origin ) ) ;
221214 async . some ( origins , function ( originsElem , done ) {
222215 if ( rdfVocab . brack ( acl . origin ) === originsElem . toString ( ) ) {
223216 debug ( "Found policy for origin: " + originsElem . toString ( ) ) ;
224- acl . allowOrigin ( mode , userId , aclGraph , modeElem , done ) ;
217+ return acl . allowOrigin ( mode , userId , aclGraph , modeElem , done ) ;
225218 }
219+ return done ( false ) ;
226220 } , next ) ;
227221 } else {
228222 debug ( "No origin found, moving on." ) ;
@@ -274,8 +268,8 @@ ACL.prototype.allow = function(mode, address, callback) {
274268 if ( err ) {
275269 return callback ( err ) ;
276270 }
277- acl . findACL ( mode , address , userId , function ( err , res ) {
278- return callback ( err , res ) ;
271+ acl . findACL ( mode , address , userId , function ( err ) {
272+ return callback ( err ) ;
279273 } ) ;
280274 } ) ;
281275} ;
@@ -285,7 +279,6 @@ ACL.prototype.allow = function(mode, address, callback) {
285279 * @param {Object } err Error occurred when reading the acl file
286280 * @param {Number } err.status Status code of the error (HTTP way)
287281 * @param {String } err.message Reason of the error
288- * @param {Boolean } result Found valid ACL statement
289282 */
290283
291284ACL . prototype . allowOrigin = function ( mode , userId , aclGraph , subject , callback ) {
@@ -383,11 +376,13 @@ ACL.prototype.fetchDocument = function(uri, callback) {
383376 var documentPath = file . uriToFilename ( newPath , ldp . root ) ;
384377 var documentUri = url . parse ( documentPath ) ;
385378 documentPath = documentUri . pathname ;
386- acl . allow ( 'Read' , newPath , function ( err , readAllowed ) {
387- if ( readAllowed ) {
388- return fs . readFile ( documentPath , { encoding : 'utf8' } , cb ) ;
379+ acl . allow ( 'Read' , newPath , function ( err ) {
380+ if ( err ) {
381+ // return an empty body to be parsed
382+ return cb ( null , '' ) ;
389383 }
390- // TODO here should be an error
384+
385+ return fs . readFile ( documentPath , { encoding : 'utf8' } , cb ) ;
391386 } ) ;
392387 } ,
393388 function ( body , cb ) {
@@ -480,21 +475,24 @@ function allowIfACLEnabled(mode, req, res, next) {
480475 if ( ! ldp . webid ) {
481476 return next ( ) ;
482477 }
483- return allow ( mode , req , next ) ;
478+ return allow ( mode , req , res , next ) ;
484479}
485480
486- function allow ( mode , req , callback ) {
481+ function allow ( mode , req , res , next ) {
487482 var ldp = req . app . locals . ldp ;
488483
489484 // Handle glob requests
490485 var filepath = file . uriToFilename ( req . path , ldp . root ) ;
491486 if ( req . method === 'GET' && glob . hasMagic ( filepath ) ) {
492- return callback ( null , true ) ;
487+ return next ( ) ;
493488 }
494489
495490 // Check ACL
491+ var reqPath = res && res . locals && res . locals . path ? res . locals . path : req . path ;
496492 var acl = reqToACL ( req ) ;
497- acl . allow ( mode , req . path , callback ) ;
493+ acl . allow ( mode , reqPath , function ( err ) {
494+ next ( err ) ;
495+ } ) ;
498496}
499497
500498exports . allow = allow ;
@@ -517,18 +515,13 @@ exports.allowAppendThenWriteHandler = function(req, res, next) {
517515 return next ( ) ;
518516 }
519517
520- allow ( "Append" , req , function ( err , allowed ) {
521- if ( ! err && allowed === true ) {
518+ allow ( "Append" , req , res , function ( err ) {
519+ if ( ! err ) {
522520 return next ( ) ;
523521 }
524522 // Append failed, maybe user can write
525- allow ( "Write" , req , function ( err , allowed ) {
526- if ( ! err && allowed === true ) {
527- return next ( ) ;
528- }
529- return res
530- . status ( err . status )
531- . send ( err . message || '' ) ;
523+ allow ( "Write" , req , res , function ( err ) {
524+ next ( err ) ;
532525 } ) ;
533526 } ) ;
534527
0 commit comments