Mercurial > libervia-pubsub
changeset 145:f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
support for 'Modifying Entity Affiliations' in the JEP-0060 specification.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 14 Jul 2005 20:51:48 +0000 |
parents | 5b0b3f013ccc |
children | b4490bdc77e5 |
files | idavoll/memory_storage.py idavoll/pgsql_storage.py idavoll/storage.py idavoll/test/test_storage.py |
diffstat | 4 files changed, 44 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/memory_storage.py Tue Jul 12 14:53:23 2005 +0000 +++ b/idavoll/memory_storage.py Thu Jul 14 20:51:48 2005 +0000 @@ -136,6 +136,12 @@ return defer.succeed(subscription.state == 'subscribed') + def get_affiliations(self): + affiliations = [(jid.JID(entity), affiliation) for entity, affiliation + in self._affiliations.iteritems()] + + return defer.succeed(affiliations) + class LeafNode(Node): implements(storage.ILeafNode)
--- a/idavoll/pgsql_storage.py Tue Jul 12 14:53:23 2005 +0000 +++ b/idavoll/pgsql_storage.py Thu Jul 14 20:51:48 2005 +0000 @@ -280,6 +280,23 @@ return cursor.fetchone() is not None + def get_affiliations(self): + return self._dbpool.runInteraction(self._get_affiliations) + + def _get_affiliations(self, cursor): + self._check_node_exists(cursor) + + cursor.execute("""SELECT jid, affiliation FROM nodes + JOIN affiliations ON + (nodes.id = affiliations.node_id) + JOIN entities ON + (affiliations.entity_id = entities.id) + WHERE node=%s""", + self.id) + result = cursor.fetchall() + + return [(jid.JID(r[0]), r[1]) for r in result] + class LeafNode(Node): implements(storage.ILeafNode) @@ -378,4 +395,3 @@ cursor.execute("""DELETE FROM items WHERE node_id=(SELECT id FROM nodes WHERE node=%s)""", (self.id,)) -
--- a/idavoll/storage.py Tue Jul 12 14:53:23 2005 +0000 +++ b/idavoll/storage.py Thu Jul 14 20:51:48 2005 +0000 @@ -180,6 +180,14 @@ @return: deferred that returns a L{bool}. """ + def get_affiliations(self): + """ Get affiliations of entities with this node. + + @return: deferred that returns a L{list} of tuples (jid, affiliation), + where jid is a L(jid.JID) and affiliation is one of C{'owner'}, + C{'publisher'}, C{'outcast'}. + """ + class ILeafNode(Interface): """ Interface to the class of objects that represent leaf nodes. """
--- a/idavoll/test/test_storage.py Tue Jul 12 14:53:23 2005 +0000 +++ b/idavoll/test/test_storage.py Thu Jul 14 20:51:48 2005 +0000 @@ -315,6 +315,19 @@ d.addCallback(cb3) return d + def testGetNodeAffilatiations(self): + def cb1(node): + return node.get_affiliations() + + def cb2(affiliations): + affiliations = dict(((a[0].full(), a[1]) for a in affiliations)) + assertEquals(affiliations[OWNER.full()], 'owner') + + d = self.s.get_node('pre-existing') + d.addCallback(cb1) + d.addCallback(cb2) + return d + class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): def setUpClass(self):