comparison sat_pubsub/pgsql_storage.py @ 356:95c83899b5e9

pgsql: fixed bad data filling in getItemsData: item_id was wrongly used to fill ItemData container. Attribute names instead of index are now used to avoid this in the future.
author Goffi <goffi@goffi.org>
date Fri, 08 Sep 2017 08:02:05 +0200
parents efbdca10f0fb
children 1167e48e5f52
comparison
equal deleted inserted replaced
355:c72fcbdcdab7 356:95c83899b5e9
962 962
963 result = cursor.fetchall() 963 result = cursor.fetchall()
964 if unrestricted and not ids_only: 964 if unrestricted and not ids_only:
965 # with unrestricted query, we need to fill the access_list for a roster access items 965 # with unrestricted query, we need to fill the access_list for a roster access items
966 ret = [] 966 ret = []
967 for data in result: 967 for item_data in result:
968 item = generic.stripNamespace(parseXml(data[0])) 968 item = generic.stripNamespace(parseXml(item_data.data))
969 access_model = data[1] 969 access_model = item_data.access_model
970 item_id = data[2] 970 item_id = item_data.item_id
971 date = data[3] 971 date = item_data.date
972 access_list = {} 972 access_list = {}
973 if access_model == const.VAL_AMODEL_PUBLISHER_ROSTER: 973 if access_model == const.VAL_AMODEL_PUBLISHER_ROSTER:
974 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,)) 974 cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,))
975 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()] 975 access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r.groupname for r in cursor.fetchall()]
976 976
977 ret.append(container.ItemData(item, access_model, access_list, date=date)) 977 ret.append(container.ItemData(item, access_model, access_list, date=date))
978 # TODO: whitelist item access model 978 # TODO: whitelist item access model
979 return ret 979 return ret
980 980
981 if ids_only: 981 if ids_only:
982 return [r[0] for r in result] 982 return [r.item for r in result]
983 else: 983 else:
984 items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), r[1], r[2], date=r[3]) for r in result] 984 items_data = [container.ItemData(generic.stripNamespace(parseXml(r.data)), r.access_model, date=r.date) for r in result]
985 return items_data 985 return items_data
986 986
987 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers): 987 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers):
988 """Get items which are in the given list 988 """Get items which are in the given list
989 989