comparison sat_pubsub/backend.py @ 438:b5e1e8d93dd4

backend, pgsql: new `overwrite_policy` node setting: /!\ pgsql schema needs to be updated /!\ this settings can be set currently to 2 values: - `original_publisher` (default), when only original publisher of an item can overwrite it (except node owner/admin) - `any_publisher` when any entity with publishing right can overwrite any item.
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 21:20:32 +0100
parents 454f61a32427
children 074037832daf
comparison
equal deleted inserted replaced
437:454f61a32427 438:b5e1e8d93dd4
177 const.VAL_PMODEL_OPEN: "Everybody can publish", 177 const.VAL_PMODEL_OPEN: "Everybody can publish",
178 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish", 178 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish",
179 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node", 179 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node",
180 } 180 }
181 }, 181 },
182 const.OPT_OVERWRITE_POLICY:
183 {"type": "list-single",
184 "label": "Who can overwrite an item",
185 "options": {
186 const.VAL_OWPOL_ORIGINAL: "Only original publisher of the item",
187 const.VAL_OWPOL_ANY_PUB: "Any publisher",
188 }
189 },
182 const.OPT_SERIAL_IDS: 190 const.OPT_SERIAL_IDS:
183 {"type": "boolean", 191 {"type": "boolean",
184 "label": "Use serial ids"}, 192 "label": "Use serial ids"},
185 const.OPT_CONSISTENT_PUBLISHER: 193 const.OPT_CONSISTENT_PUBLISHER:
186 {"type": "boolean", 194 {"type": "boolean",
405 to_remove.add(item_field) 413 to_remove.add(item_field)
406 414
407 for field in to_remove: 415 for field in to_remove:
408 item_form.removeField(field) 416 item_form.removeField(field)
409 item_elt.addChild(item_form.toElement()) 417 item_elt.addChild(item_form.toElement())
410
411 def _checkOverwrite(self, node, itemIdentifiers, publisher):
412 """Check that publisher can overwrite items
413
414 current publisher must correspond to each item publisher
415 """
416 def doCheck(item_pub_map):
417 for item_publisher in item_pub_map.values():
418 if item_publisher.userhost() != publisher.userhost():
419 raise error.ItemForbidden()
420
421 d = node.getItemsPublishers(itemIdentifiers)
422 d.addCallback(doCheck)
423 return d
424 418
425 def _getFDPSubmittedNode( 419 def _getFDPSubmittedNode(
426 self, 420 self,
427 nodeIdentifier: str, 421 nodeIdentifier: str,
428 pep: bool, 422 pep: bool,
525 # we replace requestor and new payload's publisher by original 519 # we replace requestor and new payload's publisher by original
526 # item publisher to keep publisher consistent 520 # item publisher to keep publisher consistent
527 requestor = publishers.pop() 521 requestor = publishers.pop()
528 for item in items: 522 for item in items:
529 item['publisher'] = requestor.full() 523 item['publisher'] = requestor.full()
530 else: 524 elif configuration[const.OPT_OVERWRITE_POLICY] == const.VAL_OWPOL_ORIGINAL:
531 # we don't want a publisher to overwrite the item 525 # we don't want a publisher to overwrite the item
532 # of an other publisher 526 # of an other publisher
533 await self._checkOverwrite(node, itemIdentifiers, requestor) 527 item_pub_map = await node.getItemsPublishers(itemIdentifiers)
528 for item_publisher in item_pub_map.values():
529 if item_publisher.userhost() != requestor.userhost():
530 raise error.ItemForbidden(
531 "Item can only be overwritten by original publisher"
532 )
534 533
535 if node.nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX): 534 if node.nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX):
536 schema_item = items_data[-1].item 535 schema_item = items_data[-1].item
537 try: 536 try:
538 schema = next(schema_item.elements(data_form.NS_X_DATA, 'x')) 537 schema = next(schema_item.elements(data_form.NS_X_DATA, 'x'))