comparison 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
comparison
equal deleted inserted replaced
242:a6170637690d 243:42048e37699e
54 54
55 import copy 55 import copy
56 56
57 from zope.interface import implements 57 from zope.interface import implements
58 58
59 from twisted.enterprise import adbapi 59 from twisted.internet import defer
60 from twisted.words.protocols.jabber import jid 60 from twisted.words.protocols.jabber import jid
61 61
62 from wokkel.generic import parseXml, stripNamespace 62 from wokkel.generic import parseXml, stripNamespace
63 from wokkel.pubsub import Subscription 63 from wokkel.pubsub import Subscription
64 64
183 (nodeIdentifier,)) 183 (nodeIdentifier,))
184 184
185 if cursor.rowcount != 1: 185 if cursor.rowcount != 1:
186 raise error.NodeNotFound() 186 raise error.NodeNotFound()
187 187
188 def getNodeGroups(self, nodeIdentifier):
189 return self.dbpool.runInteraction(self._getNodeGroups, nodeIdentifier)
190
191 def _getNodeGroups(self, cursor, nodeIdentifier):
192 cursor.execute("SELECT groupname FROM node_groups_authorized NATURAL JOIN nodes WHERE node=%s",
193 (nodeIdentifier,))
194 rows = cursor.fetchall()
195
196 return [row[0] for row in rows]
188 197
189 def getAffiliations(self, entity): 198 def getAffiliations(self, entity):
190 d = self.dbpool.runQuery("""SELECT node, affiliation FROM entities 199 d = self.dbpool.runQuery("""SELECT node, affiliation FROM entities
191 NATURAL JOIN affiliations 200 NATURAL JOIN affiliations
192 NATURAL JOIN nodes 201 NATURAL JOIN nodes
226 implements(iidavoll.INode) 235 implements(iidavoll.INode)
227 236
228 def __init__(self, nodeIdentifier, config): 237 def __init__(self, nodeIdentifier, config):
229 self.nodeIdentifier = nodeIdentifier 238 self.nodeIdentifier = nodeIdentifier
230 self._config = config 239 self._config = config
240 self.owner = None;
231 241
232 242
233 def _checkNodeExists(self, cursor): 243 def _checkNodeExists(self, cursor):
234 cursor.execute("""SELECT node_id FROM nodes WHERE node=%s""", 244 cursor.execute("""SELECT node_id FROM nodes WHERE node=%s""",
235 (self.nodeIdentifier,)) 245 (self.nodeIdentifier,))
237 raise error.NodeNotFound() 247 raise error.NodeNotFound()
238 248
239 249
240 def getType(self): 250 def getType(self):
241 return self.nodeType 251 return self.nodeType
252
253 def getNodeOwner(self):
254 if self.owner:
255 return defer.succeed(self.owner)
256 d = self.dbpool.runQuery("""SELECT jid FROM nodes NATURAL JOIN affiliations NATURAL JOIN entities WHERE node=%s""", (self.nodeIdentifier,))
257 d.addCallback(lambda result: jid.JID(result[0][0]))
258 return d
242 259
243 260
244 def getConfiguration(self): 261 def getConfiguration(self):
245 return self._config 262 return self._config
246 263