comparison sat_pubsub/backend.py @ 302:b8b25efae0bc

fixed item_data issues after introduction of ItemData namedtuple
author Goffi <goffi@goffi.org>
date Wed, 25 Nov 2015 22:48:59 +0100
parents 05c875a13a62
children bf4098a6cbb7
comparison
equal deleted inserted replaced
301:05c875a13a62 302:b8b25efae0bc
593 593
594 def _rosterEb(self, failure): 594 def _rosterEb(self, failure):
595 log.msg("Error while getting roster: {}".format(failure.value)) 595 log.msg("Error while getting roster: {}".format(failure.value))
596 return {} 596 return {}
597 597
598 def _tuple2ItemData(self, items_data):
599 # FIXME: workaround for the use of ItemData which doesn't exist in storage
600 # must be done in a cleaner way
601 return [ItemData(item, access_model, access_list, []) for item, access_model, access_list in items_data]
602
598 def _doGetItems(self, result, requestor, maxItems, itemIdentifiers, 603 def _doGetItems(self, result, requestor, maxItems, itemIdentifiers,
599 ext_data): 604 ext_data):
600 node, affiliation = result 605 node, affiliation = result
601 606
602 def append_item_config(items_data): 607 def append_item_config(items_data):
603 ret = [] 608 ret = []
604 for item, access_model, access_list in items_data: 609 for item_data in items_data:
610 item, access_model, access_list = item_data.item, item_data.access_model, item_data.config
605 if access_model == const.VAL_AMODEL_OPEN: 611 if access_model == const.VAL_AMODEL_OPEN:
606 pass 612 pass
607 elif access_model == const.VAL_AMODEL_ROSTER: 613 elif access_model == const.VAL_AMODEL_ROSTER:
608 form = data_form.Form('submit', formNamespace=const.NS_ITEM_CONFIG) 614 form = data_form.Form('submit', formNamespace=const.NS_ITEM_CONFIG)
609 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_ROSTER) 615 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_ROSTER)
629 authorized_groups = tuple(roster_item.groups) if roster_item else tuple() 635 authorized_groups = tuple(roster_item.groups) if roster_item else tuple()
630 unrestricted = affiliation == 'owner' 636 unrestricted = affiliation == 'owner'
631 637
632 if itemIdentifiers: 638 if itemIdentifiers:
633 d = node.getItemsById(authorized_groups, unrestricted, itemIdentifiers) 639 d = node.getItemsById(authorized_groups, unrestricted, itemIdentifiers)
640 d.addCallback(self._tuple2ItemData)
634 else: 641 else:
635 d = node.getItems(authorized_groups, unrestricted, maxItems, 642 d = node.getItems(authorized_groups, unrestricted, maxItems, ext_data)
636 ext_data)
637 if unrestricted: 643 if unrestricted:
644 d.addCallback(self._tuple2ItemData)
638 d.addCallback(append_item_config) 645 d.addCallback(append_item_config)
639 646
640 for extension in ext_data: 647 for extension in ext_data:
641 if ext_data[extension] is not None: 648 if ext_data[extension] is not None:
642 if hasattr(self, '_items_%s' % extension): 649 if hasattr(self, '_items_%s' % extension):
763 d = node.removeItems(itemIdentifiers) 770 d = node.removeItems(itemIdentifiers)
764 d.addCallback(lambda removed: [item_data for item_data in items_data if item_data.item["id"] in removed]) 771 d.addCallback(lambda removed: [item_data for item_data in items_data if item_data.item["id"] in removed])
765 return d 772 return d
766 773
767 d = node.getItemsById(None, True, itemIdentifiers) 774 d = node.getItemsById(None, True, itemIdentifiers)
775 d.addCallback(self._tuple2ItemData)
768 d.addCallback(removeItems) 776 d.addCallback(removeItems)
769 777
770 if notify: 778 if notify:
771 d.addCallback(self._doNotifyRetraction, node, pep, recipient) 779 d.addCallback(self._doNotifyRetraction, node, pep, recipient)
772 return d 780 return d
1010 1018
1011 notifications_filtered.append((owner_jid, 1019 notifications_filtered.append((owner_jid,
1012 set([Subscription(node.nodeIdentifier, 1020 set([Subscription(node.nodeIdentifier,
1013 owner_jid, 1021 owner_jid,
1014 'subscribed')]), 1022 'subscribed')]),
1015 [item for item, _, _ in items_data])) 1023 [item_data.item for item_data in items_data]))
1016 1024
1017 if pep: 1025 if pep:
1018 return self.backend.privilege.notifyRetract( 1026 return self.backend.privilege.notifyRetract(
1019 recipient, 1027 recipient,
1020 node.nodeIdentifier, 1028 node.nodeIdentifier,