# HG changeset patch # User souliane # Date 1392995411 -3600 # Node ID 9dfd3890e6467da8538689dce5d30d6c7caf1612 # Parent 7b821432d0122590ca20315ac2b30e1e3885afa5 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. diff -r 7b821432d012 -r 9dfd3890e646 sat_pubsub/backend.py --- 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 diff -r 7b821432d012 -r 9dfd3890e646 sat_pubsub/const.py --- a/sat_pubsub/const.py Fri Dec 06 00:37:08 2013 +0100 +++ b/sat_pubsub/const.py Fri Feb 21 16:10:11 2014 +0100 @@ -66,3 +66,5 @@ VAL_PMODEL_SUBSCRIBERS = 'subscribers' VAL_PMODEL_OPEN = 'open' VAL_PMODEL_DEFAULT = VAL_PMODEL_PUBLISHERS + +FLAG_RETRACT_ALLOW_PUBLISHER = True # XXX: see the method BackendService._doRetractAllowPublisher diff -r 7b821432d012 -r 9dfd3890e646 sat_pubsub/iidavoll.py --- a/sat_pubsub/iidavoll.py Fri Dec 06 00:37:08 2013 +0100 +++ b/sat_pubsub/iidavoll.py Fri Feb 21 16:10:11 2014 +0100 @@ -573,6 +573,15 @@ """ + def filterItemsWithPublisher(itemIdentifiers, requestor): + """ + Filter the given items by checking the items publisher against the requestor. + + @param itemIdentifiers: C{list} of item ids. + @param requestor: JID of the requestor. + @type requestor: L{JID} + @return: deferred that fires with a C{list} of item identifiers. + """ class IGatewayStorage(Interface): diff -r 7b821432d012 -r 9dfd3890e646 sat_pubsub/memory_storage.py --- a/sat_pubsub/memory_storage.py Fri Dec 06 00:37:08 2013 +0100 +++ b/sat_pubsub/memory_storage.py Fri Feb 21 16:10:11 2014 +0100 @@ -318,6 +318,17 @@ return defer.succeed(None) + def filterItemsWithPublisher(self, itemIdentifiers, requestor): + filteredItems = [] + for itemIdentifier in itemIdentifiers: + try: + if self._items[itemIdentifier].publisher.userhost() == requestor.userhost(): + filteredItems.append(self.items[itemIdentifier]) + except KeyError, AttributeError: + pass + return defer.succeed(filteredItems) + + class CollectionNode(Node): nodeType = 'collection' diff -r 7b821432d012 -r 9dfd3890e646 sat_pubsub/pgsql_storage.py --- a/sat_pubsub/pgsql_storage.py Fri Dec 06 00:37:08 2013 +0100 +++ b/sat_pubsub/pgsql_storage.py Fri Feb 21 16:10:11 2014 +0100 @@ -720,6 +720,20 @@ (self.nodeIdentifier,)) + def filterItemsWithPublisher(self, itemIdentifiers, requestor): + return self.dbpool.runInteraction(self._filterItemsWithPublisher, itemIdentifiers, requestor) + + def _filterItemsWithPublisher(self, cursor, itemIdentifiers, requestor): + self._checkNodeExists(cursor) + ret = [] + for itemIdentifier in itemIdentifiers: + args = ["%s/%%" % requestor.userhost(), itemIdentifier] + cursor.execute("""SELECT item FROM items WHERE publisher LIKE %s AND item=%s""", args) + result = cursor.fetchone() + if result: + ret.append(result[0]) + return ret + class CollectionNode(Node): nodeType = 'collection'