comparison sat_pubsub/backend.py @ 251:0a7d43b3dad6

owner is now notified of items published
author Goffi <goffi@goffi.org>
date Tue, 23 Oct 2012 00:09:38 +0200
parents eb14b8d30cba
children 25a1dc7181cc
comparison
equal deleted inserted replaced
250:eb14b8d30cba 251:0a7d43b3dad6
73 from twisted.words.protocols.jabber.jid import JID, InvalidFormat 73 from twisted.words.protocols.jabber.jid import JID, InvalidFormat
74 from twisted.words.xish import utility 74 from twisted.words.xish import utility
75 75
76 from wokkel import disco, data_form 76 from wokkel import disco, data_form
77 from wokkel.iwokkel import IPubSubResource 77 from wokkel.iwokkel import IPubSubResource
78 from wokkel.pubsub import PubSubResource, PubSubError 78 from wokkel.pubsub import PubSubResource, PubSubError, Subscription
79 79
80 from sat_pubsub import error, iidavoll, const 80 from sat_pubsub import error, iidavoll, const
81 from sat_pubsub.iidavoll import IBackendService, ILeafNode 81 from sat_pubsub.iidavoll import IBackendService, ILeafNode
82 82
83 83
709 node = data['node'] 709 node = data['node']
710 710
711 def _notifyAllowed(result): 711 def _notifyAllowed(result):
712 """Check access of subscriber for each item, 712 """Check access of subscriber for each item,
713 and notify only allowed ones""" 713 and notify only allowed ones"""
714 notifications, roster = result 714 notifications, (owner_jid,roster) = result
715 715
716 #we filter items not allowed for the subscribers 716 #we filter items not allowed for the subscribers
717 notifications_filtered = [] 717 notifications_filtered = []
718 718
719 for subscriber, subscriptions, items in notifications: 719 for subscriber, subscriptions, items in notifications:
734 else: #unknown access_model 734 else: #unknown access_model
735 raise NotImplementedError 735 raise NotImplementedError
736 736
737 notifications_filtered.append((subscriber, subscriptions, allowed_items)) 737 notifications_filtered.append((subscriber, subscriptions, allowed_items))
738 738
739 #we notify the owner
740 #FIXME: check if this comply with XEP-0060 (option needed ?)
741 #TODO: item's access model have to be sent back to owner
742 #TODO: same thing for getItems
743 notifications_filtered.append((owner_jid,
744 set([Subscription(node.nodeIdentifier,
745 owner_jid,
746 'subscribed')]),
747 [item for access_model, item_config, item in items]))
748
739 return self.pubsubService.notifyPublish( 749 return self.pubsubService.notifyPublish(
740 self.serviceJID, 750 self.serviceJID,
741 node.nodeIdentifier, 751 node.nodeIdentifier,
742 notifications_filtered) 752 notifications_filtered)
743 753
746 d1 = self.backend.getNotifications(node.nodeIdentifier, items) 756 d1 = self.backend.getNotifications(node.nodeIdentifier, items)
747 else: 757 else:
748 subscription = data['subscription'] 758 subscription = data['subscription']
749 d1 = defer.succeed([(subscription.subscriber, [subscription], 759 d1 = defer.succeed([(subscription.subscriber, [subscription],
750 items)]) 760 items)])
751 761
762 def _got_owner(owner_jid):
763 #return a tuple with owner_jid and roster
764 d = self.backend.roster.getRoster(owner_jid)
765 return d.addCallback(lambda roster: (owner_jid,roster))
766
752 d2 = node.getNodeOwner() 767 d2 = node.getNodeOwner()
753 d2.addCallback(self.backend.roster.getRoster) 768 d2.addCallback(_got_owner)
754 769
755 d = defer.gatherResults([d1, d2]) 770 d = defer.gatherResults([d1, d2])
756 d.addCallback(_notifyAllowed) 771 d.addCallback(_notifyAllowed)
757 772
758 773