diff idavoll/backend.py @ 95:3ad74552bbc7

Merge from RELENG_0: Implemented node configuration.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 23 Nov 2004 16:18:52 +0000
parents 878a5b7697f2
children b9c449f4c167
line wrap: on
line diff
--- a/idavoll/backend.py	Wed Nov 17 21:08:29 2004 +0000
+++ b/idavoll/backend.py	Tue Nov 23 16:18:52 2004 +0000
@@ -205,8 +205,8 @@
 
     def _do_publish(self, result, node_id, items, requestor):
         configuration = result[0][1]
-        persist_items = configuration["persist_items"]
-        deliver_payloads = configuration["deliver_payloads"]
+        persist_items = configuration["pubsub#persist_items"]
+        deliver_payloads = configuration["pubsub#deliver_payloads"]
         affiliation = result[1][1]
 
         if affiliation not in ['owner', 'publisher']:
@@ -307,6 +307,14 @@
 
     __implements__ = INodeCreationService,
 
+    options = {"pubsub#persist_items":
+                  {"type": "boolean",
+                   "label": "Persist items to storage"},
+               "pubsub#deliver_payloads":
+                  { "type": "boolean",
+                   "label": "Deliver payloads with event notifications"}
+              }
+
     def supports_instant_nodes(self):
         return True
 
@@ -319,6 +327,44 @@
         d.addCallback(lambda _: node_id)
         return d
 
+    def get_node_configuration(self, node_id):
+        if node_id:
+            d = self.parent.storage.get_node_configuration(node_id)
+        else:
+            d = defer.succeed({"pubsub#persist_items": True,
+                               "pubsub#deliver_payloads": True})
+
+        d.addCallback(self._make_config)
+        return d
+
+    def _make_config(self, config):
+        options = []
+        for key, value in config.iteritems():
+            option = {"var": key}
+            option.update(self.options[key])
+            if option["type"] == "boolean":
+                option["value"] = str(int(bool(value)))
+            else:
+                option["value"] = str(value)
+            options.append(option)
+
+        return options
+
+    def set_node_configuration(self, node_id, options, requestor):
+        for key in options.iterkeys():
+            if not self.options.has_key(key):
+                raise InvalidConfigurationOption
+
+        d = self.parent.storage.get_affiliation(node_id, requestor)
+        d.addCallback(self._do_set_node_configuration, node_id, options)
+        return d
+
+    def _do_set_node_configuration(self, affiliation, node_id, options):
+        if affiliation != 'owner':
+            raise NotAuthorized
+
+        return self.parent.storage.set_node_configuration(node_id, options)
+
 class AffiliationsService(service.Service):
 
     __implements__ = IAffiliationsService,