Skip to content

Commit fa23c82

Browse files
committed
Change accessType into isContainer.
1 parent b169010 commit fa23c82

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

lib/acl-checker.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class ACLChecker {
2626

2727
// Check the permissions within the nearest ACL
2828
return this.getNearestACL(resource)
29-
.then(({ acl, graph, accessType }) =>
29+
.then(({ acl, graph, isContainer }) =>
3030
this.checkAccess(
3131
graph, // The ACL graph
3232
user, // The webId of the user
3333
mode, // Read/Write/Append
3434
resource, // The resource we want to access
35-
accessType, // accessTo or defaultForNew
35+
isContainer,
3636
acl, // The current Acl file!
3737
options
3838
)
@@ -52,18 +52,18 @@ class ACLChecker {
5252

5353
// Gets the ACL that applies to the resource
5454
getNearestACL (uri) {
55-
let accessType = 'accessTo'
55+
let isContainer = false
5656
let nearestACL = Promise.reject()
5757
for (const acl of this.getPossibleACLs(uri, this.suffix)) {
5858
nearestACL = nearestACL.catch(() => new Promise((resolve, reject) => {
5959
this.debug(`Check if ACL exists: ${acl}`)
6060
this.fetch(acl, (err, graph) => {
6161
if (err || !graph || !graph.length) {
6262
if (err) this.debug(`Error reading ${acl}: ${err}`)
63-
accessType = 'defaultForNew'
63+
isContainer = true
6464
reject(err)
6565
} else {
66-
resolve({ acl, graph, accessType })
66+
resolve({ acl, graph, isContainer })
6767
}
6868
})
6969
}))
@@ -104,14 +104,13 @@ class ACLChecker {
104104
* @param user {String} WebID URI of the user accessing the resource
105105
* @param mode {String} Access mode, e.g. 'Read', 'Write', etc.
106106
* @param resource {String} URI of the resource being accessed
107-
* @param accessType {String} One of `accessTo`, or `default`
107+
* @param isContainer {boolean}
108108
* @param acl {String} URI of this current .acl resource
109109
* @param options {Object} Options hashmap
110110
* @param [options.origin] Request's `Origin:` header
111111
* @param [options.host] Request's host URI (with protocol)
112112
*/
113-
checkAccess (graph, user, mode, resource, accessType, acl, options = {}) {
114-
const isContainer = accessType.startsWith('default')
113+
checkAccess (graph, user, mode, resource, isContainer, acl, options = {}) {
115114
const acls = this.getPermissionSet(graph, resource, isContainer, acl, options)
116115

117116
return acls.checkAccess(resource, user, mode)

test/unit/acl-checker-test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,29 @@ describe('ACLChecker unit test', () => {
2727
'solid-permissions': { PermissionSet: PermissionSetAlwaysGrant }
2828
})
2929
let graph = {}
30-
let accessType = ''
3130
let user, mode, resource, aclUrl
3231
let acl = new ACLChecker({ debug })
33-
return expect(acl.checkAccess(graph, user, mode, resource, accessType, aclUrl))
32+
return expect(acl.checkAccess(graph, user, mode, resource, true, aclUrl))
3433
.to.eventually.be.true
3534
})
3635
it('should callback with error on grant failure', () => {
3736
let ACLChecker = proxyquire('../../lib/acl-checker', {
3837
'solid-permissions': { PermissionSet: PermissionSetNeverGrant }
3938
})
4039
let graph = {}
41-
let accessType = ''
4240
let user, mode, resource, aclUrl
4341
let acl = new ACLChecker({ debug })
44-
return expect(acl.checkAccess(graph, user, mode, resource, accessType, aclUrl))
42+
return expect(acl.checkAccess(graph, user, mode, resource, true, aclUrl))
4543
.to.be.rejectedWith('ACL file found but no matching policy found')
4644
})
4745
it('should callback with error on grant error', () => {
4846
let ACLChecker = proxyquire('../../lib/acl-checker', {
4947
'solid-permissions': { PermissionSet: PermissionSetAlwaysError }
5048
})
5149
let graph = {}
52-
let accessType = ''
5350
let user, mode, resource, aclUrl
5451
let acl = new ACLChecker({ debug })
55-
return expect(acl.checkAccess(graph, user, mode, resource, accessType, aclUrl))
52+
return expect(acl.checkAccess(graph, user, mode, resource, true, aclUrl))
5653
.to.be.rejectedWith('Error thrown during checkAccess()')
5754
})
5855
})

0 commit comments

Comments
 (0)