Skip to content

Commit 8cb33bd

Browse files
fetch profile docs
1 parent a32d078 commit 8cb33bd

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

package-lock.json

Lines changed: 7 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/acl-check.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Access control logic
22

33
const $rdf = require('rdflib')
4-
4+
const Fetcher = $rdf.Fetcher
55
const ACL = $rdf.Namespace('http://www.w3.org/ns/auth/acl#')
66
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/')
77
const VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#')
@@ -44,19 +44,30 @@ function accessDenied (kb, doc, directory, aclDoc, agent, modesRequired, origin,
4444
return ok
4545
}
4646

47-
async function getTrustedModesForOrigin (kb, aclDoc, doc, origin) {
47+
async function getTrustedModesForOrigin (kb, aclDoc, doc, origin, fetch) {
4848
const docAuths = kb.each(null, ACL('accessTo'), doc, aclDoc)
4949
const ownerAuths = docAuths.filter(auth => kb.holds(auth, ACL('mode'), ACL('Control'), aclDoc))
5050
const owners = ownerAuths.reduce((acc, auth) => acc.concat(kb.each(auth, ACL('agent'))), []) // owners
51-
const result = await Promise.all(owners.map(owner => query(`
52-
SELECT ?mode WHERE {
53-
${owner} ${ACL('trustedApp')} ?trustedOrigin.
54-
?trustedOrigin ${ACL('origin')} ${origin};
55-
${ACL('mode')} ?mode .
56-
}`, kb)))
51+
let result
52+
try {
53+
result = await Promise.all(owners.map(owner => {
54+
return fetch(owner).then(() => {
55+
const q = `
56+
SELECT ?mode WHERE {
57+
${owner} ${ACL('trustedApp')} ?trustedOrigin.
58+
?trustedOrigin ${ACL('origin')} ${origin};
59+
${ACL('mode')} ?mode .
60+
}`
61+
return query(q, kb)
62+
}).catch(e => {
63+
log('could not fetch owner doc', owner, e.message)
64+
})
65+
}))
66+
} catch (e) {
67+
log('error checking owner profiles', e.message)
68+
}
5769
let trustedModes = []
5870
result.map(ownerResults => ownerResults.map(entry => {
59-
console.log('entry', entry['?mode'])
6071
trustedModes.push(entry['?mode'])
6172
}))
6273
return Promise.resolve(trustedModes)

0 commit comments

Comments
 (0)