Mercurial > libervia-pubsub
changeset 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 | 7b821432d012 |
children | 86e767dc6abb |
files | sat_pubsub/backend.py sat_pubsub/const.py sat_pubsub/iidavoll.py sat_pubsub/memory_storage.py sat_pubsub/pgsql_storage.py |
diffstat | 5 files changed, 57 insertions(+), 1 deletions(-) [+] |
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
--- 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
--- 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<twisted.words.protocols.jabber.jid.JID>} + @return: deferred that fires with a C{list} of item identifiers. + """ class IGatewayStorage(Interface):
--- 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'
--- 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'