Mercurial > libervia-pubsub
comparison 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 |
comparison
equal
deleted
inserted
replaced
321:c7fe09894952 | 322:54d90c73b8b5 |
---|---|
747 return [] | 747 return [] |
748 | 748 |
749 args = [] | 749 args = [] |
750 | 750 |
751 # SELECT | 751 # SELECT |
752 query = ["SELECT data,items.access_model,item_id"] | 752 query = ["SELECT data,items.access_model,item_id,date"] |
753 | 753 |
754 query_order = self._appendSourcesAndFilters(query, args, authorized_groups, unrestricted, ext_data) | 754 query_order = self._appendSourcesAndFilters(query, args, authorized_groups, unrestricted, ext_data) |
755 | 755 |
756 if 'rsm' in ext_data: | 756 if 'rsm' in ext_data: |
757 rsm = ext_data['rsm'] | 757 rsm = ext_data['rsm'] |
799 ret = [] | 799 ret = [] |
800 for data in result: | 800 for data in result: |
801 item = generic.stripNamespace(parseXml(data[0])) | 801 item = generic.stripNamespace(parseXml(data[0])) |
802 access_model = data[1] | 802 access_model = data[1] |
803 item_id = data[2] | 803 item_id = data[2] |
804 date = data[3] | |
804 access_list = {} | 805 access_list = {} |
805 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model | 806 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model |
806 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,)) | 807 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,)) |
807 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()] | 808 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()] |
808 | 809 |
809 ret.append(container.ItemData(item, access_model, access_list)) | 810 ret.append(container.ItemData(item, access_model, access_list, date=date)) |
810 return ret | 811 return ret |
811 | 812 |
812 items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), None, None) for r in result] | 813 items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), r[1], r[2], date=r[3]) for r in result] |
813 return items_data | 814 return items_data |
814 | 815 |
815 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers): | 816 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers): |
816 """ Get items which are in the given list | 817 """ Get items which are in the given list |
817 @param authorized_groups: we want to get items that these groups can access | 818 @param authorized_groups: we want to get items that these groups can access |
826 def _getItemsById(self, cursor, authorized_groups, unrestricted, itemIdentifiers): | 827 def _getItemsById(self, cursor, authorized_groups, unrestricted, itemIdentifiers): |
827 self._checkNodeExists(cursor) | 828 self._checkNodeExists(cursor) |
828 ret = [] | 829 ret = [] |
829 if unrestricted: #we get everything without checking permissions | 830 if unrestricted: #we get everything without checking permissions |
830 for itemIdentifier in itemIdentifiers: | 831 for itemIdentifier in itemIdentifiers: |
831 cursor.execute("""SELECT data,items.access_model,item_id FROM nodes | 832 cursor.execute("""SELECT data,items.access_model,item_id,date FROM nodes |
832 INNER JOIN items USING (node_id) | 833 INNER JOIN items USING (node_id) |
833 WHERE node_id=%s AND item=%s""", | 834 WHERE node_id=%s AND item=%s""", |
834 (self.nodeDbId, | 835 (self.nodeDbId, |
835 itemIdentifier)) | 836 itemIdentifier)) |
836 result = cursor.fetchone() | 837 result = cursor.fetchone() |
838 raise error.ItemNotFound() | 839 raise error.ItemNotFound() |
839 | 840 |
840 item = generic.stripNamespace(parseXml(result[0])) | 841 item = generic.stripNamespace(parseXml(result[0])) |
841 access_model = result[1] | 842 access_model = result[1] |
842 item_id = result[2] | 843 item_id = result[2] |
844 date= result[3] | |
843 access_list = {} | 845 access_list = {} |
844 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model | 846 if access_model == const.VAL_AMODEL_ROSTER: #TODO: jid access_model |
845 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,)) | 847 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,)) |
846 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()] | 848 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()] |
847 | 849 |
848 ret.append(container.ItemData(item, access_model, access_list)) | 850 ret.append(container.ItemData(item, access_model, access_list, date=date)) |
849 else: #we check permission before returning items | 851 else: #we check permission before returning items |
850 for itemIdentifier in itemIdentifiers: | 852 for itemIdentifier in itemIdentifiers: |
851 args = [self.nodeDbId, itemIdentifier] | 853 args = [self.nodeDbId, itemIdentifier] |
852 if authorized_groups: | 854 if authorized_groups: |
853 args.append(authorized_groups) | 855 args.append(authorized_groups) |
854 cursor.execute("""SELECT data FROM nodes | 856 cursor.execute("""SELECT data, date FROM nodes |
855 INNER JOIN items USING (node_id) | 857 INNER JOIN items USING (node_id) |
856 LEFT JOIN item_groups_authorized USING (item_id) | 858 LEFT JOIN item_groups_authorized USING (item_id) |
857 WHERE node_id=%s AND item=%s AND | 859 WHERE node_id=%s AND item=%s AND |
858 (items.access_model='open' """ + | 860 (items.access_model='open' """ + |
859 ("or (items.access_model='roster' and groupname in %s)" if authorized_groups else '') + ")", | 861 ("or (items.access_model='roster' and groupname in %s)" if authorized_groups else '') + ")", |
860 args) | 862 args) |
861 | 863 |
862 result = cursor.fetchone() | 864 result = cursor.fetchone() |
863 if result: | 865 if result: |
864 ret.append(container.ItemData(generic.stripNamespace(parseXml(result[0])), None, None)) | 866 ret.append(container.ItemData(generic.stripNamespace(parseXml(result[0])), date=result[1])) |
865 | 867 |
866 return ret | 868 return ret |
867 | 869 |
868 def getItemsCount(self, authorized_groups, unrestricted, ext_data=None): | 870 def getItemsCount(self, authorized_groups, unrestricted, ext_data=None): |
869 """Count expected number of items in a getItems query | 871 """Count expected number of items in a getItems query |