@@ -55,7 +55,11 @@ class ACLChecker {
5555 return this . aclCached [ cacheKey ]
5656 }
5757 // console.log('TEST', this.acl)
58- const resource = rdf . sym ( this . resource )
58+ let resource = rdf . sym ( this . resource )
59+ if ( this . resource . endsWith ( '/' + this . suffix ) ) {
60+ // Then, the ACL file is for a directory
61+ resource = rdf . sym ( ACLChecker . getDirectory ( this . resource ) )
62+ }
5963 // const directory = acl.isContainer ? this.resource : null
6064 const directory = acl . isContainer ? rdf . sym ( ACLChecker . getDirectory ( acl . acl ) ) : null
6165 // console.log(ACLChecker.getDirectory(acl.acl))
@@ -109,45 +113,21 @@ class ACLChecker {
109113 // let directory = null
110114 // Create a cascade of reject handlers (one for each possible ACL)
111115 const possibleACLs = this . getPossibleACLs ( )
112- const acls = [ ...possibleACLs ]
113- let returnAcl = null
114- while ( possibleACLs . length > 0 && ! returnAcl ) {
115- const acl = possibleACLs . shift ( )
116- try {
117- const graph = await this . fetch ( acl )
118- const relative = resource . replace ( acl . replace ( / [ ^ / ] + $ / , '' ) , './' )
119- debug ( `Using ACL ${ acl } for ${ relative } ` )
120- returnAcl = { acl, graph, isContainer }
121- } catch ( err ) {
122- if ( err && ( err . code === 'ENOENT' || err . status === 404 ) ) {
123- isContainer = true
124- continue
125- } else if ( err ) {
126- console . error ( 'ERROR IN getNearestACL' , err . code , err )
127- debug ( err )
128- throw err
129- }
130- }
131- }
132- if ( ! returnAcl ) {
133- throw new HTTPError ( 403 , `No ACL found for ${ resource } , searched in \n- ${ acls . join ( '\n- ' ) } ` )
134- }
135- return returnAcl
136- // const nearestACL = possibleACLs.reduce((prevACL, acl) => {
137- // return prevACL.catch(() => new Promise((resolve, reject) => {
138- // this.fetch(acl, (err, graph) => {
139- // if (err && err.code !== 'ENOENT') {
140- // isContainer = true
141- // reject(err)
142- // } else {
143- // const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
144- // debug(`Using ACL ${acl} for ${relative}`)
145- // resolve({ acl, graph, isContainer })
146- // }
147- // })
148- // }))
149- // }, Promise.reject())
150- // return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
116+ const nearestACL = possibleACLs . reduce ( ( prevACL , acl ) => {
117+ return prevACL . catch ( ( ) => new Promise ( ( resolve , reject ) => {
118+ this . fetch ( acl , ( err , graph ) => {
119+ if ( err && err . code !== 'ENOENT' ) {
120+ isContainer = true
121+ reject ( err )
122+ } else {
123+ const relative = resource . replace ( acl . replace ( / [ ^ / ] + $ / , '' ) , './' )
124+ debug ( `Using ACL ${ acl } for ${ relative } ` )
125+ resolve ( { acl, graph, isContainer } )
126+ }
127+ } )
128+ } ) )
129+ } , Promise . reject ( ) )
130+ return nearestACL . catch ( e => { throw new Error ( `No ACL resource found, searched in \n- ${ possibleACLs . join ( '\n- ' ) } ` ) } )
151131 }
152132
153133// Gets all possible ACL paths that apply to the resource
0 commit comments