diff sat_pubsub/backend.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 ff8aff4c9b79
children 20b82fb8de02
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Sun Aug 20 22:55:28 2017 +0200
+++ b/sat_pubsub/backend.py	Thu Aug 24 01:17:28 2017 +0200
@@ -662,6 +662,15 @@
         return d
 
 
+    def getItemsIds(self, nodeIdentifier, authorized_groups, unrestricted, maxItems=None, ext_data=None, pep=False, recipient=None):
+        d = self.storage.getNode(nodeIdentifier, pep, recipient)
+        d.addCallback(lambda node: node.getItemsIds(authorized_groups,
+                                                    unrestricted,
+                                                    maxItems,
+                                                    ext_data))
+        return d
+
+
     def getItems(self, nodeIdentifier, requestor, recipient, maxItems=None,
                        itemIdentifiers=None, ext_data=None):
         d = self.getItemsData(nodeIdentifier, requestor, recipient, maxItems, itemIdentifiers, ext_data)
@@ -1276,12 +1285,26 @@
         d.addErrback(self._mapErrors)
         return d
 
+    def getNodes(self, requestor, service, nodeIdentifier):
+        try:
+            pep = service.pep
+        except AttributeError:
+            pep = False
 
-    def getNodes(self, requestor, service, nodeIdentifier, pep=None):
-        return defer.succeed([]) # FIXME: disabled for now, need to manage PEP
         if service.resource:
             return defer.succeed([])
-        d = self.backend.getNodes(pep)
+
+        if nodeIdentifier:
+            d = self.backend.getItemsIds(nodeIdentifier,
+                                         [],
+                                         requestor.userhostJID() == service,
+                                         None,
+                                         None,
+                                         pep,
+                                         service)
+
+        else:
+            d = self.backend.getNodes(pep)
         return d.addErrback(self._mapErrors)