comparison idavoll/backend.py @ 95:3ad74552bbc7

Merge from RELENG_0: Implemented node configuration.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 23 Nov 2004 16:18:52 +0000
parents 878a5b7697f2
children b9c449f4c167
comparison
equal deleted inserted replaced
94:bbebadd71d35 95:3ad74552bbc7
203 d.addCallback(self._do_publish, node_id, items, requestor) 203 d.addCallback(self._do_publish, node_id, items, requestor)
204 return d 204 return d
205 205
206 def _do_publish(self, result, node_id, items, requestor): 206 def _do_publish(self, result, node_id, items, requestor):
207 configuration = result[0][1] 207 configuration = result[0][1]
208 persist_items = configuration["persist_items"] 208 persist_items = configuration["pubsub#persist_items"]
209 deliver_payloads = configuration["deliver_payloads"] 209 deliver_payloads = configuration["pubsub#deliver_payloads"]
210 affiliation = result[1][1] 210 affiliation = result[1][1]
211 211
212 if affiliation not in ['owner', 'publisher']: 212 if affiliation not in ['owner', 'publisher']:
213 raise NotAuthorized 213 raise NotAuthorized
214 214
305 305
306 class NodeCreationService(service.Service): 306 class NodeCreationService(service.Service):
307 307
308 __implements__ = INodeCreationService, 308 __implements__ = INodeCreationService,
309 309
310 options = {"pubsub#persist_items":
311 {"type": "boolean",
312 "label": "Persist items to storage"},
313 "pubsub#deliver_payloads":
314 { "type": "boolean",
315 "label": "Deliver payloads with event notifications"}
316 }
317
310 def supports_instant_nodes(self): 318 def supports_instant_nodes(self):
311 return True 319 return True
312 320
313 def create_node(self, node_id, requestor): 321 def create_node(self, node_id, requestor):
314 if not node_id: 322 if not node_id:
316 requestor.full()).hexdigest() 324 requestor.full()).hexdigest()
317 325
318 d = self.parent.storage.create_node(node_id, requestor) 326 d = self.parent.storage.create_node(node_id, requestor)
319 d.addCallback(lambda _: node_id) 327 d.addCallback(lambda _: node_id)
320 return d 328 return d
329
330 def get_node_configuration(self, node_id):
331 if node_id:
332 d = self.parent.storage.get_node_configuration(node_id)
333 else:
334 d = defer.succeed({"pubsub#persist_items": True,
335 "pubsub#deliver_payloads": True})
336
337 d.addCallback(self._make_config)
338 return d
339
340 def _make_config(self, config):
341 options = []
342 for key, value in config.iteritems():
343 option = {"var": key}
344 option.update(self.options[key])
345 if option["type"] == "boolean":
346 option["value"] = str(int(bool(value)))
347 else:
348 option["value"] = str(value)
349 options.append(option)
350
351 return options
352
353 def set_node_configuration(self, node_id, options, requestor):
354 for key in options.iterkeys():
355 if not self.options.has_key(key):
356 raise InvalidConfigurationOption
357
358 d = self.parent.storage.get_affiliation(node_id, requestor)
359 d.addCallback(self._do_set_node_configuration, node_id, options)
360 return d
361
362 def _do_set_node_configuration(self, affiliation, node_id, options):
363 if affiliation != 'owner':
364 raise NotAuthorized
365
366 return self.parent.storage.set_node_configuration(node_id, options)
321 367
322 class AffiliationsService(service.Service): 368 class AffiliationsService(service.Service):
323 369
324 __implements__ = IAffiliationsService, 370 __implements__ = IAffiliationsService,
325 371