# HG changeset patch # User Ralph Meijer # Date 1121374308 0 # Node ID f393bccec4bc00cfa45c6be45fc29fdeaabcc927 # Parent 5b0b3f013ccc77ee223a2271430266c2c64c0618 Add get_affiliations to Node class in storage facilities in preparation of support for 'Modifying Entity Affiliations' in the JEP-0060 specification. diff -r 5b0b3f013ccc -r f393bccec4bc idavoll/memory_storage.py --- 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) diff -r 5b0b3f013ccc -r f393bccec4bc idavoll/pgsql_storage.py --- 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,)) - diff -r 5b0b3f013ccc -r f393bccec4bc idavoll/storage.py --- 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. """ diff -r 5b0b3f013ccc -r f393bccec4bc idavoll/test/test_storage.py --- 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):