comparison idavoll/backend.py @ 209:7f3ffb7a1a9e

Add support for node deletion with redirect.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 30 Jan 2009 14:35:05 +0000
parents 274a45d2a5ab
children bfc198af5d27
comparison
equal deleted inserted replaced
208:cc4f45ef793e 209:7f3ffb7a1a9e
432 d.addCallback(lambda node: node.getSubscriptions('subscribed')) 432 d.addCallback(lambda node: node.getSubscriptions('subscribed'))
433 d.addCallback(cb) 433 d.addCallback(cb)
434 return d 434 return d
435 435
436 436
437 def deleteNode(self, nodeIdentifier, requestor): 437 def deleteNode(self, nodeIdentifier, requestor, redirectURI=None):
438 d = self.storage.getNode(nodeIdentifier) 438 d = self.storage.getNode(nodeIdentifier)
439 d.addCallback(_getAffiliation, requestor) 439 d.addCallback(_getAffiliation, requestor)
440 d.addCallback(self._doPreDelete) 440 d.addCallback(self._doPreDelete, redirectURI)
441 return d 441 return d
442 442
443 443
444 def _doPreDelete(self, result): 444 def _doPreDelete(self, result, redirectURI):
445 node, affiliation = result 445 node, affiliation = result
446 446
447 if affiliation != 'owner': 447 if affiliation != 'owner':
448 raise error.Forbidden() 448 raise error.Forbidden()
449 449
450 d = defer.DeferredList([cb(node.nodeIdentifier) 450 data = {'nodeIdentifier': node.nodeIdentifier,
451 'redirectURI': redirectURI}
452
453 d = defer.DeferredList([cb(data)
451 for cb in self._callbackList], 454 for cb in self._callbackList],
452 consumeErrors=1) 455 consumeErrors=1)
453 d.addCallback(self._doDelete, node.nodeIdentifier) 456 d.addCallback(self._doDelete, node.nodeIdentifier)
454 457
455 458
559 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID, 562 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID,
560 nodeIdentifier, 563 nodeIdentifier,
561 notifications)) 564 notifications))
562 565
563 566
564 def _preDelete(self, nodeIdentifier): 567 def _preDelete(self, data):
568 nodeIdentifier = data['nodeIdentifier']
569 redirectURI = data.get('redirectURI', None)
565 d = self.backend.getSubscribers(nodeIdentifier) 570 d = self.backend.getSubscribers(nodeIdentifier)
566 d.addCallback(lambda subscribers: self.notifyDelete(self.serviceJID, 571 d.addCallback(lambda subscribers: self.notifyDelete(self.serviceJID,
567 nodeIdentifier, 572 nodeIdentifier,
568 subscribers)) 573 subscribers,
574 redirectURI))
569 return d 575 return d
570 576
571 577
572 def _mapErrors(self, failure): 578 def _mapErrors(self, failure):
573 e = failure.trap(*self._errorMap.keys()) 579 e = failure.trap(*self._errorMap.keys())