Skip to content

Commit 9684cca

Browse files
committed
isOwner
1 parent bbb8d78 commit 9684cca

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

lib/handlers/allow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ function allow (mode) {
7272
}
7373
}
7474

75-
// check user is owner. Find owner from /.meta
76-
if (resourceUrl.endsWith('.acl') && userId === await ldp.getOwner(req.hostname)) return next()
75+
// check user is owner. Check isOwner from /.meta
76+
if (resourceUrl.endsWith('.acl') && await ldp.isOwner(userId, req.hostname)) return next()
7777

7878
const error = req.authError || await req.acl.getError(userId, mode)
7979
debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)

lib/handlers/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async function checkPermission (request, patchObject, resourceExists) {
164164
if (!allAllowed) {
165165
// check owner with Control
166166
const ldp = request.app.locals.ldp
167-
if (request.path.endsWith('.acl') && userId === await ldp.getOwner(request.hostname)) return Promise.resolve(patchObject)
167+
if (request.path.endsWith('.acl') && await ldp.isOwner(userId, request.hostname)) return Promise.resolve(patchObject)
168168

169169
const errors = await Promise.all(modes.map(mode => acl.getError(userId, mode)))
170170
const error = errors.filter(error => !!error)

lib/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function addPermissions (req, res, next) {
128128
getPermissionsFor(acl, null, req),
129129
getPermissionsFor(acl, session.userId, req)
130130
])
131-
if (resource.endsWith('.acl') && userPerms === '' && session.userId === await ldp.getOwner(req.hostname)) userPerms = 'control'
131+
if (resource.endsWith('.acl') && userPerms === '' && await ldp.isOwner(session.userId, req.hostname)) userPerms = 'control'
132132
debug.ACL(`Permissions on ${resource} for ${session.userId || '(none)'}: ${userPerms}`)
133133
debug.ACL(`Permissions on ${resource} for public: ${publicPerms}`)
134134
res.set('WAC-Allow', `user="${userPerms}",public="${publicPerms}"`)

lib/ldp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,16 @@ class LDP {
454454
// this is a hack to replace solid:owner, using solid:account in /.meta to avoid NSS migration
455455
// this /.meta has no functionality in actual NSS
456456
// comment https://github.com/solid/node-solid-server/pull/1604#discussion_r652903546
457-
async getOwner (hostname) {
457+
async isOwner (webId, hostname) {
458458
// const ldp = req.app.locals.ldp
459459
const rootUrl = this.resourceMapper.resolveUrl(hostname)
460460
let graph
461461
try {
462462
// TODO check for permission ?? Owner is a MUST
463463
graph = await this.getGraph(rootUrl + '/.meta')
464464
const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#')
465-
const owner = await graph.any(null, SOLID('account'), $rdf.sym(rootUrl + '/'))
466-
return owner.uri
465+
const owner = await graph.statementsMatching($rdf.sym(webId), SOLID('account'), $rdf.sym(rootUrl + '/'))
466+
return owner.length
467467
} catch (error) {
468468
throw new Error(`Failed to get owner from ${rootUrl}/.meta, got ` + error)
469469
}

test/integration/ldp-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ describe('LDP', function () {
8989
})
9090
})
9191

92-
describe('getOwner', () => {
93-
it('should return acl:owner', () => {
94-
const owner1 = 'https://tim.localhost:7777/profile/card#me'
95-
return ldp.getOwner('/resources/')
96-
.then(owner => {
97-
assert.equal(owner, owner1)
92+
describe('isOwner', () => {
93+
it('should return acl:owner true', () => {
94+
const owner = 'https://tim.localhost:7777/profile/card#me'
95+
return ldp.isOwner(owner, '/resources/')
96+
.then(isOwner => {
97+
assert.equal(isOwner, true)
9898
})
9999
})
100100
})

0 commit comments

Comments
 (0)