@@ -5,7 +5,7 @@ const { dirname } = require('path')
55const rdf = require ( 'rdflib' )
66const debug = require ( './debug' ) . ACL
77// const debugCache = require('./debug').cache
8- const debugAccounts = require ( './debug' ) . accounts
8+ // const debugAccounts = require('./debug').accounts
99const HTTPError = require ( './http-error' )
1010const aclCheck = require ( '@solid/acl-check' )
1111const { URL } = require ( 'url' )
@@ -128,14 +128,18 @@ class ACLChecker {
128128
129129 // For delete HTTP method
130130 if ( ( method === 'DELETE' ) ) {
131- // if resource and acl have same parent container,
132- // then accessTo Write from parent is required
131+ // deleting a Container
132+ // without Read, the response code will reveal whether a Container is empty or not
133133 if ( directory && this . resource . endsWith ( '/' ) ) resourceAccessDenied ( [ ACL ( 'Read' ) , ACL ( 'Write' ) ] )
134- else if ( ! directory && aclFile . value . endsWith ( '/.acl' ) ) await accessdeniedFromParent ( [ ACL ( 'Read' ) , ACL ( 'Write' ) ] ) // directory = rdf.sym(dirname(aclFile.value) + '/')
134+ // if resource and acl have same parent container,
135+ // then Read Write from parent is required
136+ else if ( ! directory && aclFile . value . endsWith ( `/${ this . suffix } ` ) ) await accessdeniedFromParent ( [ ACL ( 'Read' ) , ACL ( 'Write' ) ] ) // directory = rdf.sym(dirname(aclFile.value) + '/')
137+
138+ // deleting a Document
135139 else if ( ( directory && directory . value === dirname ( aclFile . value ) + '/' ) ) {
136140 accessDeniedForAccessTo ( [ ACL ( 'Write' ) ] )
137141 } else {
138- await accessdeniedFromParent ( [ ACL ( 'Read' ) , ACL ( ' Write') ] )
142+ await accessdeniedFromParent ( [ ACL ( 'Write' ) ] )
139143 }
140144 }
141145
@@ -175,7 +179,7 @@ class ACLChecker {
175179 let docAcl = null
176180 let docGraph = null
177181 // while (possibleACLs.length > 0 && !returnParentAcl) {
178- while ( possibleACLs . length > 0 && ! returnParentAcl ) { // alain returnParentAcl
182+ while ( possibleACLs . length > 0 && ! returnParentAcl ) {
179183 const acl = possibleACLs . shift ( )
180184 let graph
181185 try {
@@ -195,11 +199,6 @@ class ACLChecker {
195199 if ( ! docAcl ) {
196200 docAcl = acl
197201 docGraph = graph
198- /* if ((possibleACLs.length === 0)) { // || docAcl.endsWith('/.acl')) {
199- parentAcl = acl // alain
200- parentGraph = graph // alain
201- returnParentAcl = true
202- } */
203202 // parentAcl is only needed for DELETE // alain
204203 if ( method !== 'DELETE' ) returnParentAcl = true
205204 } else {
@@ -213,31 +212,27 @@ class ACLChecker {
213212 if ( ! returnAcl ) {
214213 throw new HTTPError ( 500 , `No ACL found for ${ resource } , searched in \n- ${ acls . join ( '\n- ' ) } ` )
215214 }
216- if ( ! parentAcl ) { // alain is it needed
217- returnAcl . parentAcl = returnAcl . docAcl
218- returnAcl . parentGraph = returnAcl . docGraph
219- }
220- const groupNodes = returnAcl . docGraph . statementsMatching ( null , ACL ( 'agentGroup' ) , null )
221- const groupUrls = groupNodes . map ( node => node . object . value . split ( '#' ) [ 0 ] )
215+ // fetch group
216+ let groupNodes = returnAcl . docGraph . statementsMatching ( null , ACL ( 'agentGroup' ) , null )
217+ let groupUrls = groupNodes . map ( node => node . object . value . split ( '#' ) [ 0 ] )
222218 await Promise . all ( groupUrls . map ( async groupUrl => {
223219 try {
224220 const docGraph = await this . fetch ( groupUrl , returnAcl . docGraph )
225221 this . requests [ groupUrl ] = this . requests [ groupUrl ] || docGraph
226- // debugAccounts(this.requests[groupUrl].statementsMatching())
227222 } catch ( e ) { } // failed to fetch groupUrl
228223 } ) )
229- /* groupNodes = returnAcl.parentGraph.statementsMatching(null, ACL('agentGroup'), null)
230- groupUrls = groupNodes.map(node => node.object.value.split('#')[0] )
231- await Promise.all( groupUrls.map(async groupUrl => {
232- try {
233- const docGraph = await this.fetch(groupUrl, returnAcl.parentGraph)
234- this.requests[groupUrl] = this.requests[ groupUrl] || docGraph
235- } catch (e) {} // failed to fetch groupUrl
236- })) */
237- /* returnAcl.parentAcl = returnAcl.docAcl
238- returnAcl.parentGraph = returnAcl.docGraph
239- */
240- debugAccounts ( 'ALAIN returnACl ' + '\ndocAcl ' + returnAcl . docAcl + '\nparentAcl ' + returnAcl . parentAcl )
224+ if ( parentAcl ) {
225+ groupNodes = returnAcl . parentGraph . statementsMatching ( null , ACL ( 'agentGroup' ) , null )
226+ groupUrls = groupNodes . map ( node => node . object . value . split ( '#' ) [ 0 ] )
227+ await Promise . all ( groupUrls . map ( async groupUrl => {
228+ try {
229+ const docGraph = await this . fetch ( groupUrl , returnAcl . parentGraph )
230+ this . requests [ groupUrl ] = this . requests [ groupUrl ] || docGraph
231+ } catch ( e ) { } // failed to fetch groupUrl
232+ } ) )
233+ }
234+
235+ // debugAccounts('ALAIN returnACl ' + '\ndocAcl ' + returnAcl.docAcl + '\nparentAcl ' + returnAcl.parentAcl)
241236 return returnAcl
242237 }
243238
0 commit comments