Skip to content

Commit 8e90a7d

Browse files
committed
Improving variable naming in allow handler
1 parent 22de319 commit 8e90a7d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/handlers/allow.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fs = require('fs')
88
const { promisify } = require('util')
99
const HTTPError = require('../http-error')
1010

11-
function allow (mode, testDirectory) {
11+
function allow (mode, checkPermissionsForDirectory) {
1212
return async function allowHandler (req, res, next) {
1313
const ldp = req.app.locals.ldp || {}
1414
if (!ldp.webid) {
@@ -20,31 +20,31 @@ function allow (mode, testDirectory) {
2020

2121
// Determine the actual path of the request
2222
// (This is used as an ugly hack to check the ACL status of other resources.)
23-
let reqPath = res && res.locals && res.locals.path
23+
let resourcePath = res && res.locals && res.locals.path
2424
? res.locals.path
2525
: req.path
2626

27-
// If a relativePath has been provided, check permissions based on that
28-
if (testDirectory) {
29-
reqPath = path.dirname(reqPath)
27+
// Check permissions of the directory instead of the file itself.
28+
if (checkPermissionsForDirectory) {
29+
resourcePath = path.dirname(resourcePath)
3030
}
3131

3232
// Check whether the resource exists
3333
let stat
3434
try {
35-
const ret = await ldp.exists(req.hostname, reqPath)
35+
const ret = await ldp.exists(req.hostname, resourcePath)
3636
stat = ret.stream
3737
} catch (err) {
3838
stat = null
3939
}
4040

4141
// Ensure directories always end in a slash
42-
if (!reqPath.endsWith('/') && stat && stat.isDirectory()) {
43-
reqPath += '/'
42+
if (!resourcePath.endsWith('/') && stat && stat.isDirectory()) {
43+
resourcePath += '/'
4444
}
4545

4646
// Obtain and store the ACL of the requested resource
47-
req.acl = new ACL(rootUrl + reqPath, {
47+
req.acl = new ACL(rootUrl + resourcePath, {
4848
agentOrigin: req.get('origin'),
4949
// host: req.get('host'),
5050
fetch: fetchFromLdp(ldp.resourceMapper),

0 commit comments

Comments
 (0)