comparison idavoll/backend.py @ 59:0fa161c00ed9

Use jid.JIDs everywhere in the backend. Fix subscription list retrieval in pgsql_backend, thereby actually making notifications work.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 Nov 2004 17:07:47 +0000
parents e602ddda2d6e
children ad08e021b4d5
comparison
equal deleted inserted replaced
58:3e2e0040e3e0 59:0fa161c00ed9
78 Depending on the node's configuration and possible business rules, the 78 Depending on the node's configuration and possible business rules, the
79 C{subscriber} is added to the list of subscriptions of the node with id 79 C{subscriber} is added to the list of subscriptions of the node with id
80 C{node_id}. The C{subscriber} might be different from the C{requestor}, 80 C{node_id}. The C{subscriber} might be different from the C{requestor},
81 and if the C{requestor} is not allowed to subscribe this entity an 81 and if the C{requestor} is not allowed to subscribe this entity an
82 exception should be raised. 82 exception should be raised.
83 83
84 @return: a deferred that returns the subscription state 84 @return: a deferred that returns the subscription state
85 """ 85 """
86 86
87 def unsubscribe(self, node_id, subscriber, requestor): 87 def unsubscribe(self, node_id, subscriber, requestor):
88 """ Cancel the subscription of an entity to a pubsub node. 88 """ Cancel the subscription of an entity to a pubsub node.
154 154
155 __implements__ = IPublishService, 155 __implements__ = IPublishService,
156 156
157 def publish(self, node_id, items, requestor): 157 def publish(self, node_id, items, requestor):
158 d1 = self.parent.storage.get_node_configuration(node_id) 158 d1 = self.parent.storage.get_node_configuration(node_id)
159 d2 = self.parent.storage.get_affiliation(node_id, requestor.full()) 159 d2 = self.parent.storage.get_affiliation(node_id, requestor)
160 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) 160 d = defer.DeferredList([d1, d2], fireOnOneErrback=1)
161 d.addErrback(lambda x: x.value[0]) 161 d.addErrback(lambda x: x.value[0])
162 d.addCallback(self._do_publish, node_id, items, requestor) 162 d.addCallback(self._do_publish, node_id, items, requestor)
163 return d 163 return d
164 164
183 if item["id"] is None: 183 if item["id"] is None:
184 item["id"] = 'random' # FIXME 184 item["id"] = 'random' # FIXME
185 185
186 if persist_items: 186 if persist_items:
187 d = self.parent.storage.store_items(node_id, items, 187 d = self.parent.storage.store_items(node_id, items,
188 requestor.full()) 188 requestor)
189 else: 189 else:
190 d = defer.succeed(None) 190 d = defer.succeed(None)
191 191
192 d.addCallback(self._do_notify, node_id, items, deliver_payloads) 192 d.addCallback(self._do_notify, node_id, items, deliver_payloads)
193 193
210 210
211 def _magic_filter(self, subscribers, node_id, items): 211 def _magic_filter(self, subscribers, node_id, items):
212 list = {} 212 list = {}
213 for subscriber in subscribers: 213 for subscriber in subscribers:
214 list[subscriber] = items 214 list[subscriber] = items
215
216 return list 215 return list
217 216
218 def register_notifier(self, observerfn, *args, **kwargs): 217 def register_notifier(self, observerfn, *args, **kwargs):
219 self.parent.addObserver('//event/pubsub/notify', observerfn, 218 self.parent.addObserver('//event/pubsub/notify', observerfn,
220 *args, **kwargs) 219 *args, **kwargs)
226 def subscribe(self, node_id, subscriber, requestor): 225 def subscribe(self, node_id, subscriber, requestor):
227 if subscriber.userhostJID() != requestor: 226 if subscriber.userhostJID() != requestor:
228 raise NotAuthorized 227 raise NotAuthorized
229 228
230 d1 = self.parent.storage.get_node_configuration(node_id) 229 d1 = self.parent.storage.get_node_configuration(node_id)
231 d2 = self.parent.storage.get_affiliation(node_id, subscriber.full()) 230 d2 = self.parent.storage.get_affiliation(node_id, subscriber)
232 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) 231 d = defer.DeferredList([d1, d2], fireOnOneErrback=1)
233 d.addErrback(lambda x: x.value[0]) 232 d.addErrback(lambda x: x.value[0])
234 d.addCallback(self._do_subscribe, node_id, subscriber) 233 d.addCallback(self._do_subscribe, node_id, subscriber)
235 return d 234 return d
236 235
239 affiliation = result[1][1] 238 affiliation = result[1][1]
240 239
241 if affiliation == 'outcast': 240 if affiliation == 'outcast':
242 raise NotAuthorized 241 raise NotAuthorized
243 242
244 d = self.parent.storage.add_subscription(node_id, subscriber.full(), 243 d = self.parent.storage.add_subscription(node_id, subscriber,
245 'subscribed') 244 'subscribed')
246 d.addCallback(self._return_subscription, affiliation) 245 d.addCallback(self._return_subscription, affiliation)
247 return d 246 return d
248 247
249 def _return_subscription(self, result, affiliation): 248 def _return_subscription(self, result, affiliation):
250 result['affiliation'] = affiliation 249 result['affiliation'] = affiliation
251 result['jid'] = jid.JID(result['jid'])
252 return result 250 return result
253 251
254 def unsubscribe(self, node_id, subscriber, requestor): 252 def unsubscribe(self, node_id, subscriber, requestor):
255 if subscriber.userhostJID() != requestor: 253 if subscriber.userhostJID() != requestor:
256 raise NotAuthorized 254 raise NotAuthorized
259 d.addCallback(self._do_unsubscribe, node_id, subscriber) 257 d.addCallback(self._do_unsubscribe, node_id, subscriber)
260 return d 258 return d
261 259
262 def _do_unsubscribe(self, result, node_id, subscriber): 260 def _do_unsubscribe(self, result, node_id, subscriber):
263 return self.parent.storage.remove_subscription(node_id, 261 return self.parent.storage.remove_subscription(node_id,
264 subscriber.full()) 262 subscriber)
265 263
266 class NodeCreationService(service.Service): 264 class NodeCreationService(service.Service):
267 265
268 __implements__ = INodeCreationService, 266 __implements__ = INodeCreationService,
269 267
272 270
273 def create_node(self, node_id, requestor): 271 def create_node(self, node_id, requestor):
274 if not node_id: 272 if not node_id:
275 raise NoInstantNodes 273 raise NoInstantNodes
276 274
277 d = self.parent.storage.create_node(node_id, requestor.full()) 275 d = self.parent.storage.create_node(node_id, requestor)
278 d.addCallback(lambda _: node_id) 276 d.addCallback(lambda _: node_id)
279 return d 277 return d