diff sat_pubsub/pgsql_storage.py @ 240:70c8bb90d75f

added access_model to config, default to 'open'
author Goffi <goffi@goffi.org>
date Tue, 22 May 2012 21:21:57 +0200
parents 64f780413b82
children 42048e37699e
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Sun May 20 00:52:13 2012 +0200
+++ b/sat_pubsub/pgsql_storage.py	Tue May 22 21:21:57 2012 +0200
@@ -73,10 +73,12 @@
                 "pubsub#persist_items": True,
                 "pubsub#deliver_payloads": True,
                 "pubsub#send_last_published_item": 'on_sub',
+                "pubsub#access_model": 'open',
             },
             'collection': {
                 "pubsub#deliver_payloads": True,
                 "pubsub#send_last_published_item": 'on_sub',
+                "pubsub#access_model": 'open',
             }
     }
 
@@ -87,13 +89,13 @@
     def getNode(self, nodeIdentifier):
         return self.dbpool.runInteraction(self._getNode, nodeIdentifier)
 
-
     def _getNode(self, cursor, nodeIdentifier):
         configuration = {}
         cursor.execute("""SELECT node_type,
                                  persist_items,
                                  deliver_payloads,
-                                 send_last_published_item
+                                 send_last_published_item,
+                                 access_model
                           FROM nodes
                           WHERE node=%s""",
                        (nodeIdentifier,))
@@ -107,7 +109,8 @@
                     'pubsub#persist_items': row[1],
                     'pubsub#deliver_payloads': row[2],
                     'pubsub#send_last_published_item':
-                        row[3]}
+                        row[3],
+                    'pubsub#access_model':row[4]}
             node = LeafNode(nodeIdentifier, configuration)
             node.dbpool = self.dbpool
             return node
@@ -115,7 +118,8 @@
             configuration = {
                     'pubsub#deliver_payloads': row[2],
                     'pubsub#send_last_published_item':
-                        row[3]}
+                        row[3],
+                    'pubsub#access_model':row[4]}
             node = CollectionNode(nodeIdentifier, configuration)
             node.dbpool = self.dbpool
             return node
@@ -141,13 +145,14 @@
         try:
             cursor.execute("""INSERT INTO nodes
                               (node, node_type, persist_items,
-                               deliver_payloads, send_last_published_item)
+                               deliver_payloads, send_last_published_item, access_model)
                               VALUES
-                              (%s, 'leaf', %s, %s, %s)""",
+                              (%s, 'leaf', %s, %s, %s, %s)""",
                            (nodeIdentifier,
                             config['pubsub#persist_items'],
                             config['pubsub#deliver_payloads'],
-                            config['pubsub#send_last_published_item'])
+                            config['pubsub#send_last_published_item'],
+                            config['pubsub#access_model'])
                            )
         except cursor._pool.dbapi.IntegrityError:
             raise error.NodeExists()
@@ -292,6 +297,20 @@
         except TypeError:
             return None
 
+    def getAccessModel(self):
+        return self.dbpool.runInteraction(self._getAccessModel)
+
+    def _getAccessModel(self, cursor, entity):
+        self._checkNodeExists(cursor)
+        cursor.execute("""SELECT access_model FROM nodes
+                          WHERE node=%s""",
+                       (self.nodeIdentifier,))
+
+        try:
+            return cursor.fetchone()[0]
+        except TypeError:
+            return None
+
 
     def getSubscription(self, subscriber):
         return self.dbpool.runInteraction(self._getSubscription, subscriber)