diff sat_pubsub/delegation.py @ 346:3bbab2173ebc

implemented disco items: - new getItemsIds method to get only ids of items, without payload or extra data - added delegation (PEP) data for disco items requests. It's a really dirty hack, but there is not clean way to do it beside rewriting the whole thing - authorized node items are returned on disco items when node is specified - if no node is specified, the nodes list is returned
author Goffi <goffi@goffi.org>
date Thu, 24 Aug 2017 01:17:28 +0200
parents 0a93d71f9503
children
line wrap: on
line diff
--- a/sat_pubsub/delegation.py	Sun Aug 20 22:55:28 2017 +0200
+++ b/sat_pubsub/delegation.py	Thu Aug 24 01:17:28 2017 +0200
@@ -266,3 +266,28 @@
 
     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
         return []
+
+
+# we monkeypatch DiscoHandler to add delegation informations
+def _onDiscoItems(self, iq):
+    request = disco._DiscoRequest.fromElement(iq)
+    # it's really ugly to attach pep data to recipient
+    # but we don't have many options
+    request.recipient.pep = iq.delegated
+
+    def toResponse(items):
+        response = disco.DiscoItems()
+        response.nodeIdentifier = request.nodeIdentifier
+
+        for item in items:
+            response.append(item)
+
+        return response.toElement()
+
+    d = self.items(request.sender, request.recipient,
+                   request.nodeIdentifier)
+    d.addCallback(toResponse)
+    return d
+
+
+disco.DiscoHandler._onDiscoItems = _onDiscoItems