Mercurial > libervia-pubsub
comparison sat_pubsub/backend.py @ 355:c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Sep 2017 08:02:05 +0200 |
parents | 18b983fe9e1b |
children | 1167e48e5f52 |
comparison
equal
deleted
inserted
replaced
354:18b983fe9e1b | 355:c72fcbdcdab7 |
---|---|
458 if subscriberEntity != requestor.userhostJID(): | 458 if subscriberEntity != requestor.userhostJID(): |
459 return defer.fail(error.Forbidden()) | 459 return defer.fail(error.Forbidden()) |
460 | 460 |
461 d = self.storage.getNode(nodeIdentifier, pep, recipient) | 461 d = self.storage.getNode(nodeIdentifier, pep, recipient) |
462 d.addCallback(_getAffiliation, subscriberEntity) | 462 d.addCallback(_getAffiliation, subscriberEntity) |
463 d.addCallback(self._doSubscribe, subscriber) | 463 d.addCallback(self._doSubscribe, subscriber, pep, recipient) |
464 return d | 464 return d |
465 | 465 |
466 def _doSubscribe(self, result, subscriber): | 466 def _doSubscribe(self, result, subscriber, pep, recipient): |
467 # TODO: implement other access models | |
468 node, affiliation = result | 467 node, affiliation = result |
469 | 468 |
470 if affiliation == 'outcast': | 469 if affiliation == 'outcast': |
471 raise error.Forbidden() | 470 raise error.Forbidden() |
472 | 471 |
488 return False | 487 return False |
489 | 488 |
490 def cb(sendLast): | 489 def cb(sendLast): |
491 d = node.getSubscription(subscriber) | 490 d = node.getSubscription(subscriber) |
492 if sendLast: | 491 if sendLast: |
493 d.addCallback(self._sendLastPublished, node) | 492 d.addCallback(self._sendLastPublished, node, pep, recipient) |
494 return d | 493 return d |
495 | 494 |
496 d = node.addSubscription(subscriber, 'subscribed', {}) | 495 d.addCallback(lambda _: node.addSubscription(subscriber, 'subscribed', {})) |
497 d.addCallbacks(lambda _: True, trapExists) | 496 d.addCallbacks(lambda _: True, trapExists) |
498 d.addCallback(cb) | 497 d.addCallback(cb) |
499 | 498 |
500 return d | 499 return d |
501 | 500 |
502 def _sendLastPublished(self, subscription, node): | 501 def _sendLastPublished(self, subscription, node, pep, recipient): |
503 | 502 |
504 def notifyItem(items): | 503 def notifyItem(items_data): |
505 if items: | 504 if items_data: |
506 reactor.callLater(0, self.dispatch, | 505 reactor.callLater(0, self.dispatch, |
507 {'items': items, | 506 {'items_data': items_data, |
508 'node': node, | 507 'node': node, |
508 'pep': pep, | |
509 'recipient': recipient, | |
509 'subscription': subscription, | 510 'subscription': subscription, |
510 }, | 511 }, |
511 '//event/pubsub/notify') | 512 '//event/pubsub/notify') |
512 | 513 |
513 config = node.getConfiguration() | 514 config = node.getConfiguration() |
514 sendLastPublished = config.get('pubsub#send_last_published_item', | 515 sendLastPublished = config.get('pubsub#send_last_published_item', |
515 'never') | 516 'never') |
516 if sendLastPublished == 'on_sub' and node.nodeType == 'leaf': | 517 if sendLastPublished == 'on_sub' and node.nodeType == 'leaf': |
517 entity = subscription.subscriber.userhostJID() | 518 entity = subscription.subscriber.userhostJID() |
518 d = self.getItems(node.nodeIdentifier, entity, 1) | 519 d = self.getItemsData(node.nodeIdentifier, entity, recipient, maxItems=1, ext_data={'pep': pep}) |
519 d.addCallback(notifyItem) | 520 d.addCallback(notifyItem) |
520 d.addErrback(log.err) | 521 d.addErrback(log.err) |
521 | 522 |
522 return subscription | 523 return subscription |
523 | 524 |
527 | 528 |
528 d = self.storage.getNode(nodeIdentifier, pep, recipient) | 529 d = self.storage.getNode(nodeIdentifier, pep, recipient) |
529 d.addCallback(lambda node: node.removeSubscription(subscriber)) | 530 d.addCallback(lambda node: node.removeSubscription(subscriber)) |
530 return d | 531 return d |
531 | 532 |
532 def getSubscriptions(self, entity): | 533 def getSubscriptions(self, requestor, pep, recipient): |
533 return self.storage.getSubscriptions(entity) | 534 return self.storage.getSubscriptions(requestor, pep, recipient) |
534 | 535 |
535 def supportsAutoCreate(self): | 536 def supportsAutoCreate(self): |
536 return True | 537 return True |
537 | 538 |
538 def supportsCreatorCheck(self): | 539 def supportsCreatorCheck(self): |