Skip to content

Commit b19214d

Browse files
committed
making progress based on @deiu's comments
1 parent c317ec2 commit b19214d

1 file changed

Lines changed: 55 additions & 59 deletions

File tree

lib/identity-provider.js

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,7 @@ var pki = forge.pki
1919
var parse = require('./utils').parse
2020
var stringToStream = require('./utils').stringToStream
2121

22-
var defaultContainers = [
23-
{
24-
name: 'Public',
25-
label: 'Public workspace',
26-
type: 'PublicWorkspace'
27-
}, {
28-
name: 'Private',
29-
label: 'Private workspace',
30-
type: 'PrivateWorkspace'
31-
}, {
32-
name: 'Work',
33-
label: 'Work workspace'
34-
}, {
35-
name: 'Shared',
36-
label: 'Shared workspace',
37-
type: 'SharedWorkspace'
38-
}, {
39-
name: 'Preferences',
40-
label: 'Preferences workspace'
41-
}, {
42-
name: 'Applications',
43-
label: 'Applications workspace',
44-
type: 'PreferencesWorkspace'
45-
}, {
46-
name: 'Inbox',
47-
label: 'Inbox'
48-
}, {
49-
name: 'Timeline',
50-
label: 'Timeline'
51-
}
52-
]
22+
var defaultContainers = []
5323

5424
function defaultBuildURI (account, host, port) {
5525
var hostAndPort = (host || 'localhost') + (port || '')
@@ -104,9 +74,25 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
10474
options.suffixAcl = self.suffixAcl
10575
options.defaultContainers = options.defaultContainers || self.defaultContainers
10676

107-
var card = createCard(options, cert)
108-
var cardAcl = createCardAcl(options)
109-
var rootAcl = createRootAcl(options)
77+
options.preferences = options.url + options.settings + '/prefs.ttl'
78+
options.inboxAcl = options.url + options.inbox + '/' + self.suffixAcl
79+
80+
var graphs = [
81+
self.putGraph(options.card, createCard(options, cert)),
82+
self.putGraph(options.card + self.suffixAcl, createCardAcl(options)),
83+
self.putGraph(options.url + self.suffixAcl, createRootAcl(options))
84+
]
85+
86+
if (options.preferences) {
87+
graphs.push(self.putGraph(options.preferences, createPreferences(options)))
88+
}
89+
if (options.inbox) {
90+
graphs.push(self.putGraph(options.inbox + self.suffixAcl, createInboxAcl(options)))
91+
}
92+
93+
if (options.defaultContainers && options.defaultContainers.length > 0) {
94+
throw new Error('default containers is not supported yet')
95+
}
11096

11197
// TODO create defaultContainers
11298
// remove port from host
@@ -123,55 +109,58 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
123109

124110
debug(subdomain + ' is free')
125111

126-
parallel([
127-
self.putGraph(options.card, card),
128-
self.putGraph(options.card + self.suffixAcl, cardAcl),
129-
self.putGraph(options.url + self.suffixAcl, rootAcl)
130-
], function (err) {
112+
// Creating user card, card acl and root acl
113+
parallel(graphs, function (err) {
131114
if (err) {
132115
err.status = 500
133116
debug('Error creating account ' + options.agent + ': ' + err.message)
134117
}
135118

136119
debug('Created files for ' + options.agent)
120+
// TODO delete all the files we just created
137121
callback(err)
138122
})
139123
})
140124
}
141125

126+
function createInboxAcl (options) {
127+
var resource = options.url + '/' + options.inbox + '/'
128+
var acl = resource + options.suffixAcl
129+
130+
var aclGraph = createAcl(
131+
acl,
132+
resource,
133+
options.agent,
134+
options.email)
135+
136+
addAppendAll(aclGraph, acl)
137+
138+
return aclGraph
139+
}
140+
142141
function createPreferences (options) {
143142
var graph = $rdf.graph()
144-
var pref = options.url + 'Preferences/prefs.ttl'
145143

146144
graph.add(
147-
sym(pref),
145+
sym(options.preferences),
148146
sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
149147
sym('http://www.w3.org/ns/pim/space#ConfigurationFile'))
150148

151149
graph.add(
152-
sym(pref),
150+
sym(options.preferences),
153151
sym('http://purl.org/dc/terms/title'),
154152
lit('Preferences file'))
155153

156-
graph.add(
157-
sym(options.card),
158-
sym('http://www.w3.org/ns/pim/space#preferencesFile'),
159-
sym(pref))
160-
161154
graph.add(
162155
sym(options.card),
163156
sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
164157
sym('http://xmlns.com/foaf/0.1/Person'))
165158

166-
options.defaultContainers.forEach(function() {
167-
// TODO
168-
})
169-
170159
return graph
171160
}
172161

173-
function createWorkSpace (options, workspace) {
174-
var resource = options.url + workspace.name + '/'
162+
function createContainer (options, defaultContainer) {
163+
var resource = options.url + defaultContainer.name + '/'
175164
var acl = resource + options.suffixAcl
176165

177166
var aclGraph = createAcl(
@@ -180,14 +169,13 @@ function createWorkSpace (options, workspace) {
180169
options.agent,
181170
options.email)
182171

183-
if (workspace.type === 'PublicWorkspace') {
172+
if (defaultContainer.access === 'readAll') {
184173
addReadAll(aclGraph, acl)
185174
}
186175

187-
if (workspace.type === 'Inbox') {
176+
if (defaultContainer.access === 'appendAll') {
188177
addAppendAll(aclGraph, acl)
189178
}
190-
191179
}
192180

193181
// Generates a WebID card and add the key if the cert is passed
@@ -221,7 +209,17 @@ function createCard (options, cert) {
221209
sym('http://www.w3.org/ns/pim/space#storage'),
222210
sym(options.url))
223211

224-
// TODO add workspace with inbox, timeline, preferencesFile..
212+
graph.add(
213+
sym(options.agent),
214+
sym('http://www.w3.org/ns/pim/space#preferencesFile'),
215+
sym(options.preferences)) // TODO
216+
217+
graph.add(
218+
sym(options.agent),
219+
sym('http://www.w3.org/ns/solid/terms#inbox'),
220+
sym(options.inbox)) // TODO
221+
222+
// TODO add defaultContainer with inbox, timeline, preferencesFile..
225223
// See: https://github.com/linkeddata/gold/blob/master/webid.go
226224

227225
if (cert) {
@@ -313,8 +311,6 @@ function addReadAll (graph, acl) {
313311

314312
// Create an ACL for the WebID card
315313
function createCardAcl (options) {
316-
var graph = $rdf.graph()
317-
318314
// Create Card ACL
319315
var graph = createAcl(
320316
options.card + options.suffixAcl,

0 commit comments

Comments
 (0)