|
1 | 1 | // Access control logic
|
2 | 2 |
|
3 | 3 | const $rdf = require('rdflib')
|
4 |
| - |
| 4 | +const Fetcher = $rdf.Fetcher |
5 | 5 | const ACL = $rdf.Namespace('http://www.w3.org/ns/auth/acl#')
|
6 | 6 | const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/')
|
7 | 7 | const VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#')
|
@@ -44,19 +44,30 @@ function accessDenied (kb, doc, directory, aclDoc, agent, modesRequired, origin,
|
44 | 44 | return ok
|
45 | 45 | }
|
46 | 46 |
|
47 |
| -async function getTrustedModesForOrigin (kb, aclDoc, doc, origin) { |
| 47 | +async function getTrustedModesForOrigin (kb, aclDoc, doc, origin, fetch) { |
48 | 48 | const docAuths = kb.each(null, ACL('accessTo'), doc, aclDoc)
|
49 | 49 | const ownerAuths = docAuths.filter(auth => kb.holds(auth, ACL('mode'), ACL('Control'), aclDoc))
|
50 | 50 | 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 | + } |
57 | 69 | let trustedModes = []
|
58 | 70 | result.map(ownerResults => ownerResults.map(entry => {
|
59 |
| - console.log('entry', entry['?mode']) |
60 | 71 | trustedModes.push(entry['?mode'])
|
61 | 72 | }))
|
62 | 73 | return Promise.resolve(trustedModes)
|
|
0 commit comments