diff 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
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Fri Dec 06 00:37:08 2013 +0100
+++ b/sat_pubsub/backend.py	Fri Feb 21 16:10:11 2014 +0100
@@ -593,9 +593,29 @@
     def retractItem(self, nodeIdentifier, itemIdentifiers, requestor):
         d = self.storage.getNode(nodeIdentifier)
         d.addCallback(_getAffiliation, requestor)
-        d.addCallback(self._doRetract, itemIdentifiers)
+        if const.FLAG_RETRACT_ALLOW_PUBLISHER:
+            d.addCallback(self._doRetractAllowPublisher, itemIdentifiers, requestor)
+        else:
+            d.addCallback(self._doRetract, itemIdentifiers)
         return d
 
+    def _doRetractAllowPublisher(self, result, itemIdentifiers, requestor):
+        """This method has been added to allow the publisher
+        of an item to retract it, even if he has no affiliation
+        to that item. For instance, this allows you to delete
+        an item you posted in a node of "open" publish model.
+        """
+        node, affiliation = result
+        if affiliation in ['owner', 'publisher']:
+            return self._doRetract(result, itemIdentifiers)
+        d = node.filterItemsWithPublisher(itemIdentifiers, requestor)
+        def filterCb(filteredItems):
+            if not filteredItems:
+                return self._doRetract(result, itemIdentifiers)
+            # XXX: fake an affiliation that does NOT exist
+            return self._doRetract((node, 'publisher'), filteredItems)
+        d.addCallback(filterCb)
+        return d
 
     def _doRetract(self, result, itemIdentifiers):
         node, affiliation = result