diff sat_pubsub/pgsql_storage.py @ 243:42048e37699e

added experimental roster access_model (use remote_roster)
author Goffi <goffi@goffi.org>
date Sun, 27 May 2012 15:55:25 +0200
parents 70c8bb90d75f
children 3ecc94407e36
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Sun May 27 15:36:06 2012 +0200
+++ b/sat_pubsub/pgsql_storage.py	Sun May 27 15:55:25 2012 +0200
@@ -56,7 +56,7 @@
 
 from zope.interface import implements
 
-from twisted.enterprise import adbapi
+from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
 
 from wokkel.generic import parseXml, stripNamespace
@@ -185,6 +185,15 @@
         if cursor.rowcount != 1:
             raise error.NodeNotFound()
 
+    def getNodeGroups(self, nodeIdentifier):
+        return self.dbpool.runInteraction(self._getNodeGroups, nodeIdentifier)
+
+    def _getNodeGroups(self, cursor, nodeIdentifier):
+        cursor.execute("SELECT groupname FROM node_groups_authorized NATURAL JOIN nodes WHERE node=%s",
+                       (nodeIdentifier,))
+        rows = cursor.fetchall()
+
+        return [row[0] for row in rows]
 
     def getAffiliations(self, entity):
         d = self.dbpool.runQuery("""SELECT node, affiliation FROM entities
@@ -228,6 +237,7 @@
     def __init__(self, nodeIdentifier, config):
         self.nodeIdentifier = nodeIdentifier
         self._config = config
+        self.owner = None;
 
 
     def _checkNodeExists(self, cursor):
@@ -240,6 +250,13 @@
     def getType(self):
         return self.nodeType
 
+    def getNodeOwner(self):
+        if self.owner:
+            return defer.succeed(self.owner)
+        d = self.dbpool.runQuery("""SELECT jid FROM nodes NATURAL JOIN affiliations NATURAL JOIN entities WHERE node=%s""", (self.nodeIdentifier,))
+        d.addCallback(lambda result: jid.JID(result[0][0]))
+        return d
+
 
     def getConfiguration(self):
         return self._config