comparison sat_pubsub/pgsql_storage.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 8cf1be9572f8
children f33406fcab5c
comparison
equal deleted inserted replaced
345:83122f15b993 346:3bbab2173ebc
782 782
783 return deleted 783 return deleted
784 784
785 def getItems(self, authorized_groups, unrestricted, maxItems=None, ext_data=None): 785 def getItems(self, authorized_groups, unrestricted, maxItems=None, ext_data=None):
786 """ Get all authorised items 786 """ Get all authorised items
787
787 @param authorized_groups: we want to get items that these groups can access 788 @param authorized_groups: we want to get items that these groups can access
788 @param unrestricted: if true, don't check permissions (i.e.: get all items) 789 @param unrestricted: if true, don't check permissions (i.e.: get all items)
789 @param maxItems: nb of items we want to get 790 @param maxItems: nb of items we want to get
790 @param ext_data: options for extra features like RSM and MAM 791 @param ext_data: options for extra features like RSM and MAM
791 792
793 if unrestricted is False, access_model and config will be None 794 if unrestricted is False, access_model and config will be None
794 """ 795 """
795 if ext_data is None: 796 if ext_data is None:
796 ext_data = {} 797 ext_data = {}
797 return self.dbpool.runInteraction(self._getItems, authorized_groups, unrestricted, maxItems, ext_data) 798 return self.dbpool.runInteraction(self._getItems, authorized_groups, unrestricted, maxItems, ext_data)
799
800 def getItemsIds(self, authorized_groups, unrestricted, maxItems=None, ext_data=None):
801 """ Get all authorised items ids
802
803 @param authorized_groups: we want to get items that these groups can access
804 @param unrestricted: if true, don't check permissions (i.e.: get all items)
805 @param maxItems: nb of items we want to get
806 @param ext_data: options for extra features like RSM and MAM
807
808 @return list(unicode): list of ids
809 """
810 if ext_data is None:
811 ext_data = {}
812 return self.dbpool.runInteraction(self._getItems, authorized_groups, unrestricted, maxItems, ext_data, ids_only=True)
798 813
799 def _appendSourcesAndFilters(self, query, args, authorized_groups, unrestricted, ext_data): 814 def _appendSourcesAndFilters(self, query, args, authorized_groups, unrestricted, ext_data):
800 """append sources and filters to sql query requesting items and return ORDER BY 815 """append sources and filters to sql query requesting items and return ORDER BY
801 816
802 arguments query, args, authorized_groups, unrestricted and ext_data are the same as for 817 arguments query, args, authorized_groups, unrestricted and ext_data are the same as for
845 860
846 query.extend(query_filters) 861 query.extend(query_filters)
847 862
848 return "ORDER BY item_id DESC" 863 return "ORDER BY item_id DESC"
849 864
850 def _getItems(self, cursor, authorized_groups, unrestricted, maxItems, ext_data): 865 def _getItems(self, cursor, authorized_groups, unrestricted, maxItems, ext_data, ids_only):
851 self._checkNodeExists(cursor) 866 self._checkNodeExists(cursor)
852 867
853 if maxItems == 0: 868 if maxItems == 0:
854 return [] 869 return []
855 870
856 args = [] 871 args = []
857 872
858 # SELECT 873 # SELECT
859 query = ["SELECT data,items.access_model,item_id,date"] 874 if ids_only:
875 query = ["SELECT item"]
876 else:
877 query = ["SELECT data,items.access_model,item_id,date"]
860 878
861 query_order = self._appendSourcesAndFilters(query, args, authorized_groups, unrestricted, ext_data) 879 query_order = self._appendSourcesAndFilters(query, args, authorized_groups, unrestricted, ext_data)
862 880
863 if 'rsm' in ext_data: 881 if 'rsm' in ext_data:
864 rsm = ext_data['rsm'] 882 rsm = ext_data['rsm']
899 args.append(maxItems) 917 args.append(maxItems)
900 918
901 cursor.execute(' '.join(query), args) 919 cursor.execute(' '.join(query), args)
902 920
903 result = cursor.fetchall() 921 result = cursor.fetchall()
904 if unrestricted: 922 if unrestricted and not ids_only:
905 # with unrestricted query, we need to fill the access_list for a roster access items 923 # with unrestricted query, we need to fill the access_list for a roster access items
906 ret = [] 924 ret = []
907 for data in result: 925 for data in result:
908 item = generic.stripNamespace(parseXml(data[0])) 926 item = generic.stripNamespace(parseXml(data[0]))
909 access_model = data[1] 927 access_model = data[1]
916 934
917 ret.append(container.ItemData(item, access_model, access_list, date=date)) 935 ret.append(container.ItemData(item, access_model, access_list, date=date))
918 # TODO: whitelist item access model 936 # TODO: whitelist item access model
919 return ret 937 return ret
920 938
921 items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), r[1], r[2], date=r[3]) for r in result] 939 if ids_only:
940 return [r[0] for r in result]
941 else:
942 items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), r[1], r[2], date=r[3]) for r in result]
922 return items_data 943 return items_data
923 944
924 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers): 945 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers):
925 """Get items which are in the given list 946 """Get items which are in the given list
926 947