Skip to content

Commit dd9217e

Browse files
authored
Merge pull request #1728 from nodeSolidServer/multipleOwners
isOwner there may be multiple owners
2 parents 7be97cd + 6822a82 commit dd9217e

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

lib/handlers/allow.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ 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()
77-
75+
// check if user is owner. Check isOwner from /.meta
76+
try {
77+
if (resourceUrl.endsWith('.acl') && (await ldp.isOwner(userId, req.hostname))) return next()
78+
} catch (err) {}
7879
const error = req.authError || await req.acl.getError(userId, mode)
7980
debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
8081
next(error)

lib/handlers/patch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async function checkPermission (request, patchObject, resourceExists) {
162162
if (!allAllowed) {
163163
// check owner with Control
164164
const ldp = request.app.locals.ldp
165-
if (request.path.endsWith('.acl') && userId === await ldp.getOwner(request.hostname)) return Promise.resolve(patchObject)
165+
if (request.path.endsWith('.acl') && await ldp.isOwner(userId, request.hostname)) return Promise.resolve(patchObject)
166166

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

lib/header.js

+1-1
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

+3-3
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

+13-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ 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)
98+
})
99+
})
100+
it('should return acl:owner false', () => {
101+
const owner = 'https://tim.localhost:7777/profile/card'
102+
return ldp.isOwner(owner, '/resources/')
103+
.then(isOwner => {
104+
assert.equal(isOwner, false)
98105
})
99106
})
100107
})

0 commit comments

Comments
 (0)