comparison sat_pubsub/backend.py @ 415:4179ed660a85

backend: fixed publishing with "consistent_publisher" when no item was previously available
author Goffi <goffi@goffi.org>
date Fri, 23 Aug 2019 17:27:26 +0200
parents ccb2a22ea0fc
children 794593086517
comparison
equal deleted inserted replaced
414:ccb2a22ea0fc 415:4179ed660a85
455 if item.getAttribute('id')] 455 if item.getAttribute('id')]
456 456
457 if affiliation == 'owner' or self.isAdmin(requestor): 457 if affiliation == 'owner' or self.isAdmin(requestor):
458 if configuration[const.OPT_CONSISTENT_PUBLISHER]: 458 if configuration[const.OPT_CONSISTENT_PUBLISHER]:
459 pub_map = yield node.getItemsPublishers(itemIdentifiers) 459 pub_map = yield node.getItemsPublishers(itemIdentifiers)
460 publishers = set(pub_map.values()) 460 if pub_map:
461 if len(publishers) != 1: 461 # if we have existing items, we replace publishers with
462 # TODO: handle multiple items publishing (from several 462 # original one to stay consistent
463 # publishers) 463 publishers = set(pub_map.values())
464 raise error.NoPublishing( 464 if len(publishers) != 1:
465 "consistent_publisher is currently only possible when " 465 # TODO: handle multiple items publishing (from several
466 "publishing items from a single publisher. Try to " 466 # publishers)
467 "publish one item at a time") 467 raise error.NoPublishing(
468 # we replace requestor and new payload's publisher by original 468 "consistent_publisher is currently only possible when "
469 # item publisher to keep publisher consistent 469 "publishing items from a single publisher. Try to "
470 requestor = publishers.pop() 470 "publish one item at a time")
471 for item in items: 471 # we replace requestor and new payload's publisher by original
472 item['publisher'] = requestor.full() 472 # item publisher to keep publisher consistent
473 requestor = publishers.pop()
474 for item in items:
475 item['publisher'] = requestor.full()
473 else: 476 else:
474 # we don't want a publisher to overwrite the item 477 # we don't want a publisher to overwrite the item
475 # of an other publisher 478 # of an other publisher
476 yield self._checkOverwrite(node, itemIdentifiers, requestor) 479 yield self._checkOverwrite(node, itemIdentifiers, requestor)
477 480