diff 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
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Mon Feb 08 19:01:29 2021 +0100
+++ b/sat_pubsub/backend.py	Sat Feb 27 21:20:32 2021 +0100
@@ -179,6 +179,14 @@
                      const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node",
                      }
                 },
+            const.OPT_OVERWRITE_POLICY:
+                {"type": "list-single",
+                 "label": "Who can overwrite an item",
+                 "options": {
+                     const.VAL_OWPOL_ORIGINAL: "Only original publisher of the item",
+                     const.VAL_OWPOL_ANY_PUB: "Any publisher",
+                     }
+                },
             const.OPT_SERIAL_IDS:
                 {"type": "boolean",
                  "label": "Use serial ids"},
@@ -408,20 +416,6 @@
             item_form.removeField(field)
         item_elt.addChild(item_form.toElement())
 
-    def _checkOverwrite(self, node, itemIdentifiers, publisher):
-        """Check that publisher can overwrite items
-
-        current publisher must correspond to each item publisher
-        """
-        def doCheck(item_pub_map):
-            for item_publisher in item_pub_map.values():
-                if item_publisher.userhost() != publisher.userhost():
-                    raise error.ItemForbidden()
-
-        d = node.getItemsPublishers(itemIdentifiers)
-        d.addCallback(doCheck)
-        return d
-
     def _getFDPSubmittedNode(
         self,
         nodeIdentifier: str,
@@ -527,10 +521,15 @@
                             requestor = publishers.pop()
                             for item in items:
                                 item['publisher'] = requestor.full()
-                else:
+                elif configuration[const.OPT_OVERWRITE_POLICY] == const.VAL_OWPOL_ORIGINAL:
                     # we don't want a publisher to overwrite the item
                     # of an other publisher
-                    await self._checkOverwrite(node, itemIdentifiers, requestor)
+                    item_pub_map = await node.getItemsPublishers(itemIdentifiers)
+                    for item_publisher in item_pub_map.values():
+                        if item_publisher.userhost() != requestor.userhost():
+                            raise error.ItemForbidden(
+                                "Item can only be overwritten by original publisher"
+                            )
 
             if node.nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX):
                 schema_item = items_data[-1].item