changeset 244:3ecc94407e36

item access_model (not finished)
author Goffi <goffi@goffi.org>
date Wed, 30 May 2012 01:04:15 +0200 (2012-05-29)
parents 42048e37699e
children e11e99246be5
files db/pubsub.sql sat_pubsub/pgsql_storage.py
diffstat 2 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/db/pubsub.sql	Sun May 27 15:55:25 2012 +0200
+++ b/db/pubsub.sql	Wed May 30 01:04:15 2012 +0200
@@ -53,6 +53,16 @@
     item text NOT NULL,
     publisher text NOT NULL,
     data text,
+    access_model text NOT NULL DEFAULT 'default'
+        CHECK (access_model IN ('default','open', 'roster')),
     date timestamp with time zone NOT NULL DEFAULT now(),
     UNIQUE (node_id, item)
 );
+
+CREATE TABLE item_groups_authorized (
+    item_groups_authorized_id serial PRIMARY KEY,
+    item_id integer NOT NULL references items ON DELETE CASCADE,
+    groupname text NOT NULL,
+    UNIQUE (item_id,groupname)
+);
+
--- a/sat_pubsub/pgsql_storage.py	Sun May 27 15:55:25 2012 +0200
+++ b/sat_pubsub/pgsql_storage.py	Wed May 30 01:04:15 2012 +0200
@@ -61,9 +61,14 @@
 
 from wokkel.generic import parseXml, stripNamespace
 from wokkel.pubsub import Subscription
+from wokkel import data_form
 
 from sat_pubsub import error, iidavoll
 
+NS_ITEM_CONFIG = "http://jabber.org/protocol/pubsub#item-config"
+OPT_ACCESS_MODEL = 'pubsub#access_model'
+VAL_DEFAULT = 'default'
+
 class Storage:
 
     implements(iidavoll.IStorage)
@@ -510,7 +515,23 @@
 
 
     def _storeItem(self, cursor, item, publisher):
+        item_config = None
+        access_model = VAL_DEFAULT
+        for i in range(len(item.children)):
+            elt = item.children[i]
+            if not (elt.uri,elt.name)==(data_form.NS_X_DATA,'x'):
+                continue
+            form = data_form.Form.fromElement(elt)
+            if (form.formNamespace == NS_ITEM_CONFIG):
+                item_config = form
+                del item.children[i] #we need to remove the config from item
+                break
+
+        if item_config:
+            access_model = item_config.get("pubsub#access_model", VAL_DEFAULT)
+         
         data = item.toXml()
+        
         cursor.execute("""UPDATE items SET date=now(), publisher=%s, data=%s
                           FROM nodes
                           WHERE nodes.node_id = items.node_id AND
@@ -522,12 +543,13 @@
         if cursor.rowcount == 1:
             return
 
-        cursor.execute("""INSERT INTO items (node_id, item, publisher, data)
-                          SELECT node_id, %s, %s, %s FROM nodes
+        cursor.execute("""INSERT INTO items (node_id, item, publisher, data, access_model)
+                          SELECT node_id, %s, %s, %s, %s FROM nodes
                                                      WHERE node=%s""",
                        (item["id"],
                         publisher.full(),
                         data,
+                        access_model,
                         self.nodeIdentifier))