comparison sat_pubsub/backend.py @ 263:9dfd3890e646

added the constant FLAG_RETRACT_ALLOW_PUBLISHER to allow a publisher to retract an item he has published in a node of "open" publish model.
author souliane <souliane@mailoo.org>
date Fri, 21 Feb 2014 16:10:11 +0100
parents 65d4fed44edf
children 8a71486c3e95
comparison
equal deleted inserted replaced
262:7b821432d012 263:9dfd3890e646
591 return d 591 return d
592 592
593 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor): 593 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor):
594 d = self.storage.getNode(nodeIdentifier) 594 d = self.storage.getNode(nodeIdentifier)
595 d.addCallback(_getAffiliation, requestor) 595 d.addCallback(_getAffiliation, requestor)
596 d.addCallback(self._doRetract, itemIdentifiers) 596 if const.FLAG_RETRACT_ALLOW_PUBLISHER:
597 return d 597 d.addCallback(self._doRetractAllowPublisher, itemIdentifiers, requestor)
598 598 else:
599 d.addCallback(self._doRetract, itemIdentifiers)
600 return d
601
602 def _doRetractAllowPublisher(self, result, itemIdentifiers, requestor):
603 """This method has been added to allow the publisher
604 of an item to retract it, even if he has no affiliation
605 to that item. For instance, this allows you to delete
606 an item you posted in a node of "open" publish model.
607 """
608 node, affiliation = result
609 if affiliation in ['owner', 'publisher']:
610 return self._doRetract(result, itemIdentifiers)
611 d = node.filterItemsWithPublisher(itemIdentifiers, requestor)
612 def filterCb(filteredItems):
613 if not filteredItems:
614 return self._doRetract(result, itemIdentifiers)
615 # XXX: fake an affiliation that does NOT exist
616 return self._doRetract((node, 'publisher'), filteredItems)
617 d.addCallback(filterCb)
618 return d
599 619
600 def _doRetract(self, result, itemIdentifiers): 620 def _doRetract(self, result, itemIdentifiers):
601 node, affiliation = result 621 node, affiliation = result
602 persistItems = node.getConfiguration()["pubsub#persist_items"] 622 persistItems = node.getConfiguration()["pubsub#persist_items"]
603 623