Skip to content

Commit 4b2ac7a

Browse files
committed
Move all options to constructor.
1 parent 9a6bdf3 commit 4b2ac7a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/acl-checker.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const DEFAULT_ACL_SUFFIX = '.acl'
1111
class ACLChecker {
1212
constructor (resource, options = {}) {
1313
this.resource = resource
14+
this.host = options.host
15+
this.origin = options.origin
1416
this.debug = options.debug || console.log.bind(console)
1517
this.fetch = options.fetch
1618
this.strictOrigin = options.strictOrigin
1719
this.suffix = options.suffix || DEFAULT_ACL_SUFFIX
1820
}
1921

20-
can (user, mode, options = {}) {
22+
can (user, mode) {
2123
const debug = this.debug
2224
this.debug(`Can ${user || 'an agent'} ${mode} ${this.resource}?`)
2325
// If this is an ACL, Control mode must be present for any operations
@@ -28,7 +30,7 @@ class ACLChecker {
2830
// Check the permissions within the nearest ACL
2931
return this.getNearestACL(this.resource)
3032
.then(nearestAcl => {
31-
const acls = this.getPermissionSet(nearestAcl, options)
33+
const acls = this.getPermissionSet(nearestAcl)
3234
return this.checkAccess(acls, user, mode, this.resource)
3335
})
3436
.then(() => { debug('ACL policy found') })
@@ -111,7 +113,7 @@ class ACLChecker {
111113
}
112114

113115
// Gets the permission set for the given resource
114-
getPermissionSet ({ acl, graph, isContainer }, options = {}) {
116+
getPermissionSet ({ acl, graph, isContainer }) {
115117
const debug = this.debug
116118
if (!graph || graph.length === 0) {
117119
debug('ACL ' + acl + ' is empty')
@@ -120,8 +122,8 @@ class ACLChecker {
120122
const aclOptions = {
121123
aclSuffix: this.suffix,
122124
graph: graph,
123-
host: options.host,
124-
origin: options.origin,
125+
host: this.host,
126+
origin: this.origin,
125127
rdf: rdf,
126128
strictOrigin: this.strictOrigin,
127129
isAcl: uri => this.isAcl(uri),

lib/handlers/allow.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ function allow (mode) {
2424
if (!reqPath.endsWith('/') && !err && stat.isDirectory()) {
2525
reqPath += '/'
2626
}
27-
var options = {
28-
origin: req.get('origin'),
29-
host: req.protocol + '://' + req.get('host')
30-
}
3127

3228
var baseUri = utils.uriBase(req)
3329
var acl = new ACL(baseUri + reqPath, {
30+
origin: req.get('origin'),
31+
host: req.protocol + '://' + req.get('host'),
3432
debug: debug,
3533
fetch: fetchDocument(req.hostname, ldp, baseUri),
3634
suffix: ldp.suffixAcl,
3735
strictOrigin: ldp.strictOrigin
3836
})
3937
req.acl = acl
4038

41-
acl.can(req.session.userId, mode, options).then(next, next)
39+
acl.can(req.session.userId, mode).then(next, next)
4240
})
4341
}
4442
}

0 commit comments

Comments
 (0)