diff sat_pubsub/pgsql_storage.py @ 322:54d90c73b8b5

mam: various improvments: - put common namespaces ton const - VAL_RSM_MAX_DEFAULT can be None if default limit is not wanted - ItemDate now has a 'date' attribute - MAMService is MonkeyPatched the same way as PubSubService to handle PEP - fixed error mapping in mam module - PEP is handled - properly manage date in a payload independent way - when PEP is used, send privileged messages
author Goffi <goffi@goffi.org>
date Tue, 05 Jan 2016 23:13:13 +0100
parents a51947371625
children 8496af26be45
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Tue Jan 05 22:16:37 2016 +0100
+++ b/sat_pubsub/pgsql_storage.py	Tue Jan 05 23:13:13 2016 +0100
@@ -749,7 +749,7 @@
         args = []
 
         # SELECT
-        query = ["SELECT data,items.access_model,item_id"]
+        query = ["SELECT data,items.access_model,item_id,date"]
 
         query_order = self._appendSourcesAndFilters(query, args, authorized_groups, unrestricted, ext_data)
 
@@ -801,15 +801,16 @@
                 item = generic.stripNamespace(parseXml(data[0]))
                 access_model = data[1]
                 item_id = data[2]
+                date = data[3]
                 access_list = {}
                 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model
                     cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,))
                     access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()]
 
-                ret.append(container.ItemData(item, access_model, access_list))
+                ret.append(container.ItemData(item, access_model, access_list, date=date))
             return ret
 
-        items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), None, None) for r in result]
+        items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), r[1], r[2], date=r[3]) for r in result]
         return items_data
 
     def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers):
@@ -828,7 +829,7 @@
         ret = []
         if unrestricted: #we get everything without checking permissions
             for itemIdentifier in itemIdentifiers:
-                cursor.execute("""SELECT data,items.access_model,item_id FROM nodes
+                cursor.execute("""SELECT data,items.access_model,item_id,date FROM nodes
                                   INNER JOIN items USING (node_id)
                                   WHERE node_id=%s AND item=%s""",
                                (self.nodeDbId,
@@ -840,18 +841,19 @@
                 item = generic.stripNamespace(parseXml(result[0]))
                 access_model = result[1]
                 item_id = result[2]
+                date= result[3]
                 access_list = {}
                 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model
                     cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,))
                     access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()]
 
-                ret.append(container.ItemData(item, access_model, access_list))
+                ret.append(container.ItemData(item, access_model, access_list, date=date))
         else: #we check permission before returning items
             for itemIdentifier in itemIdentifiers:
                 args = [self.nodeDbId, itemIdentifier]
                 if authorized_groups:
                     args.append(authorized_groups)
-                cursor.execute("""SELECT data FROM nodes
+                cursor.execute("""SELECT data, date FROM nodes
                            INNER  JOIN items USING (node_id)
                            LEFT JOIN item_groups_authorized USING (item_id)
                            WHERE node_id=%s AND item=%s AND
@@ -861,7 +863,7 @@
 
                 result = cursor.fetchone()
                 if result:
-                    ret.append(container.ItemData(generic.stripNamespace(parseXml(result[0])), None, None))
+                    ret.append(container.ItemData(generic.stripNamespace(parseXml(result[0])), date=result[1]))
 
         return ret