@@ -19,6 +19,38 @@ var asn1 = forge.asn1
1919var pki = forge.pki
2020var parse = require('./utils').parse
2121
22+ var workspaces = [
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+ ]
53+
2254function defaultBuildURI (account, host, port) {
2355 var hostAndPort = (host || 'localhost') + (port || '')
2456 return 'https://' + hostAndPort + '/'
@@ -35,6 +67,7 @@ function IdentityProvider (options) {
3567 this.suffixURI = options.suffixURI || '#me'
3668 this.buildURI = options.buildURI || defaultBuildURI
3769 this.suffixAcl = options.suffixAcl
70+ this.workspaces = options.workspaces || workspaces
3871}
3972
4073// Generate the future webid from the options and the IdentityProvider Settings
@@ -67,6 +100,7 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
67100 options.agent = options.card + self.suffixURI
68101 debug('Creating space ' + options.url)
69102 options.suffixAcl = self.suffixAcl
103+ options.workspaces = options.workspaces || self.workspaces
70104
71105 var card = createCard(options, cert)
72106 var cardAcl = createCardAcl(options)
@@ -103,6 +137,57 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
103137 })
104138}
105139
140+ function createPreferences (options) {
141+ var graph = $rdf.graph()
142+ var pref = options.url + 'Preferences/prefs.ttl'
143+
144+ graph.add(
145+ sym(pref),
146+ sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
147+ sym('http://www.w3.org/ns/pim/space#ConfigurationFile'))
148+
149+ graph.add(
150+ sym(pref),
151+ sym('http://purl.org/dc/terms/title'),
152+ lit('Preferences file'))
153+
154+ graph.add(
155+ sym(options.card),
156+ sym('http://www.w3.org/ns/pim/space#preferencesFile'),
157+ sym(pref))
158+
159+ graph.add(
160+ sym(options.card),
161+ sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
162+ sym('http://xmlns.com/foaf/0.1/Person'))
163+
164+ options.workspaces.forEach(function() {
165+ // TODO
166+ })
167+
168+ return graph
169+ }
170+
171+ function createWorkSpace (options, workspace) {
172+ var resource = options.url + workspace.name + '/'
173+ var acl = resource + options.suffixAcl
174+
175+ var aclGraph = createAcl(
176+ acl,
177+ resource,
178+ options.agent,
179+ options.email)
180+
181+ if (workspace.type === 'PublicWorkspace') {
182+ addReadAll(aclGraph, acl)
183+ }
184+
185+ if (workspace.type === 'Inbox') {
186+ addAppendAll(aclGraph, acl)
187+ }
188+
189+ }
190+
106191// Generates a WebID card and add the key if the cert is passed
107192function createCard (options, cert) {
108193 var graph = $rdf.graph()
@@ -174,46 +259,29 @@ function addKey (graph, agent, cert) {
174259 lit(exponent, 'http://www.w3.org/2001/XMLSchema#int')) // TODO add Datatype "http://www.w3.org/2001/XMLSchema#int"
175260}
176261
177- // Create an ACL for the WebID card
178- function createCardAcl (options) {
179- var graph = $rdf.graph()
180- var url = options.card
181- var acl = url + options.suffixAcl
182- var agent = options.agent
183- var owner = acl + '#owner'
184- var readAll = acl + '#readall'
262+ function addAppendAll (graph, acl) {
263+ var readAll = acl + '#appendall'
185264
186265 graph.add(
187- sym(owner ),
266+ sym(readAll ),
188267 sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
189268 sym('http://www.w3.org/ns/auth/acl#Authorization'))
190269 graph.add(
191- sym(owner ),
270+ sym(readAll ),
192271 sym('http://www.w3.org/ns/auth/acl#accessTo'),
193272 sym(url))
194-
195- // This is soon to be deprecated
196- graph.add(
197- sym(owner),
198- sym('http://www.w3.org/ns/auth/acl#accessTo'),
199- sym(acl))
200-
201- graph.add(
202- sym(owner),
203- sym('http://www.w3.org/ns/auth/acl#agent'),
204- sym(agent))
205273 graph.add(
206- sym(owner),
207- sym('http://www.w3.org/ns/auth/acl#mode'),
208- sym('http://www.w3.org/ns/auth/acl#Read'))
209- graph.add(
210- sym(owner),
211- sym('http://www.w3.org/ns/auth/acl#mode'),
212- sym('http://www.w3.org/ns/auth/acl#Write'))
274+ sym(readAll),
275+ sym('http://www.w3.org/ns/auth/acl#agentClass'),
276+ sym('http://xmlns.com/foaf/0.1/Agent'))
213277 graph.add(
214- sym(owner ),
278+ sym(readAll ),
215279 sym('http://www.w3.org/ns/auth/acl#mode'),
216- sym('http://www.w3.org/ns/auth/acl#Control'))
280+ sym('http://www.w3.org/ns/auth/acl#Append'))
281+ }
282+
283+ function addReadAll (graph, acl) {
284+ var readAll = acl + '#readall'
217285
218286 graph.add(
219287 sym(readAll),
@@ -231,44 +299,49 @@ function createCardAcl (options) {
231299 sym(readAll),
232300 sym('http://www.w3.org/ns/auth/acl#mode'),
233301 sym('http://www.w3.org/ns/auth/acl#Read'))
302+ }
303+
304+ // Create an ACL for the WebID card
305+ function createCardAcl (options) {
306+ var graph = $rdf.graph()
307+
308+ // Create Card ACL
309+ var graph = createAcl(
310+ options.card + options.suffixAcl,
311+ options.card,
312+ options.agent,
313+ options.email)
314+
315+ // Add ReadAll term
316+ addReadAll(graph, options.card + options.suffixAcl)
234317
235318 return graph
236319}
237320
238- // Create ACL for the space reserved for the new user
239- function createRootAcl (options) {
240- var owner = options.url + options.suffixAcl + '#owner'
241- var agent = options.agent
242-
321+ function createAcl (acl, uri, agent, email) {
243322 var graph = $rdf.graph()
323+ var owner = acl + '#owner'
324+
244325 graph.add(
245326 sym(owner),
246327 sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
247328 sym('http://www.w3.org/ns/auth/acl#Authorization'))
248329 graph.add(
249330 sym(owner),
250331 sym('http://www.w3.org/ns/auth/acl#accessTo'),
251- sym(options.url ))
332+ sym(uri ))
252333 graph.add(
253334 sym(owner),
254335 sym('http://www.w3.org/ns/auth/acl#accessTo'),
255- sym(options.url ))
336+ sym(uri ))
256337 graph.add(
257338 sym(owner),
258339 sym('http://www.w3.org/ns/auth/acl#agent'),
259340 sym(agent))
260-
261- if (options.email && options.email.length > 0) {
262- graph.add(
263- sym(owner),
264- sym('http://www.w3.org/ns/auth/acl#agent'),
265- sym('mailto:' + options.email))
266- }
267-
268341 graph.add(
269342 sym(owner),
270343 sym('http://www.w3.org/ns/auth/acl#defaultForNew'),
271- sym(options.url ))
344+ sym(uri ))
272345 graph.add(
273346 sym(owner),
274347 sym('http://www.w3.org/ns/auth/acl#mode'),
@@ -282,6 +355,24 @@ function createRootAcl (options) {
282355 sym('http://www.w3.org/ns/auth/acl#mode'),
283356 sym('http://www.w3.org/ns/auth/acl#Control'))
284357
358+ if (email && email.length > 0) {
359+ graph.add(
360+ sym(owner),
361+ sym('http://www.w3.org/ns/auth/acl#agent'),
362+ sym('mailto:' + email))
363+ }
364+
365+ return graph
366+ }
367+
368+ // Create ACL for the space reserved for the new user
369+ function createRootAcl (options) {
370+ var graph = createAcl(
371+ options.url + options.suffixAcl,
372+ options.url,
373+ options.agent,
374+ options.email)
375+
285376 return graph
286377}
287378
0 commit comments