changeset 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 2b50e4664d74
children d2bdff8a4b45
files db/pubsub.sql sat_pubsub/backend.py sat_pubsub/pgsql_storage.py sat_pubsub/test/test_storage.py
diffstat 4 files changed, 33 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/db/pubsub.sql	Sun May 20 00:52:13 2012 +0200
+++ b/db/pubsub.sql	Tue May 22 21:21:57 2012 +0200
@@ -8,6 +8,8 @@
     node text NOT NULL UNIQUE,
     node_type text NOT NULL DEFAULT 'leaf'
         CHECK (node_type IN ('leaf', 'collection')),
+    access_model text NOT NULL DEFAULT 'open'
+        CHECK (access_model IN ('open', 'roster')),
     persist_items boolean,
     deliver_payloads boolean NOT NULL DEFAULT TRUE,
     send_last_published_item text NOT NULL DEFAULT 'on_sub'
--- a/sat_pubsub/backend.py	Sun May 20 00:52:13 2012 +0200
+++ b/sat_pubsub/backend.py	Tue May 22 21:21:57 2012 +0200
@@ -70,7 +70,7 @@
 from twisted.python import components, log
 from twisted.internet import defer, reactor
 from twisted.words.protocols.jabber.error import StanzaError
-from twisted.words.protocols.jabber.jid import JID
+from twisted.words.protocols.jabber.jid import JID, InvalidFormat
 from twisted.words.xish import utility
 
 from wokkel import disco
@@ -603,6 +603,7 @@
 
         self.backend.registerNotifier(self._notify)
         self.backend.registerPreDelete(self._preDelete)
+        
         if self.backend.supportsCreatorCheck():
             self.features.append("creator-jid-check")  #SàT custom feature: Check that a node (which correspond to
                                                        #                    a jid in this server) is created by the right jid
@@ -663,7 +664,6 @@
 
         raise exc
 
-
     def getInfo(self, requestor, service, nodeIdentifier):
         info = {}
 
@@ -701,6 +701,7 @@
 
     def _publish_errb(self, failure, request):
         if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate():
+            print "Auto-creating node %s" % (request.nodeIdentifier,)
             d = self.backend.createNode(request.nodeIdentifier,
                                         request.sender)
             d.addCallback(lambda ignore,
@@ -710,8 +711,7 @@
                           request)
             return d
 
-        raise failure
-
+        return failure
 
     def publish(self, request):
         d = self.backend.publish(request.nodeIdentifier,
--- 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)
--- a/sat_pubsub/test/test_storage.py	Sun May 20 00:52:13 2012 +0200
+++ b/sat_pubsub/test/test_storage.py	Tue May 22 21:21:57 2012 +0200
@@ -165,6 +165,7 @@
                 "pubsub#deliver_payloads": True,
                 "pubsub#send_last_published_item": 'on_sub',
                 "pubsub#node_type": 'leaf',
+                "pubsub#access_model": 'open',
                 }
 
         def unsetPersistItems(_):