Changeset 46:5ec77d2dcdb4 in ralphm-patches


Ignore:
Timestamp:
Feb 12, 2011, 7:16:51 PM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Raise exception on duplicate entities, always use bare JIDs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pubsub_manage_affiliations.patch

    r45 r46  
    11# HG changeset patch
    22# Parent f69b08281becebb5483f3f2dfb0451ad3086a463
     3Add support for managing affiliations of Publish-Subscribe nodes.
    34
    45diff -r f69b08281bec wokkel/iwokkel.py
    56--- a/wokkel/iwokkel.py Sat Feb 12 00:08:30 2011 +0100
    6 +++ b/wokkel/iwokkel.py Sat Feb 12 09:41:40 2011 +0100
    7 @@ -767,3 +767,17 @@
     7+++ b/wokkel/iwokkel.py Sat Feb 12 19:16:00 2011 +0100
     8@@ -767,3 +767,36 @@
    89                  deleted.
    910         @rtype: L{defer.Deferred}
     
    2223+            or C{u'outcast'}.
    2324+        @rtype: L{defer.Deferred}
     25+
     26+        @note: Affiliations are always on the bare JID. An implementation of
     27+        this method MUST NOT return JIDs with a resource part.
     28+        """
     29+
     30+
     31+    def affiliationsSet(request):
     32+        """
     33+        Called when a affiliations modify request has been received.
     34+
     35+        @param request: The publish-subscribe request.
     36+        @type request: L{wokkel.pubsub.PubSubRequest}
     37+        @return: A deferred that fires with C{None} when the affiliation
     38+            changes were succesfully processed..
     39+        @rtype: L{defer.Deferred}
     40+
     41+        @note: Affiliations are always on the bare JID. The JIDs in
     42+        L{wokkel.pubsub.PubSubRequest.affiliations} are already stripped of
     43+        any resource.
    2444+        """
    2545diff -r f69b08281bec wokkel/pubsub.py
    2646--- a/wokkel/pubsub.py  Sat Feb 12 00:08:30 2011 +0100
    27 +++ b/wokkel/pubsub.py  Sat Feb 12 09:41:40 2011 +0100
     47+++ b/wokkel/pubsub.py  Sat Feb 12 19:16:00 2011 +0100
    2848@@ -220,6 +220,9 @@
    2949     @ivar subscriptions: Subscriptions to be modified, as a set of
     
    5373         'subscriptionsSet': [],
    5474     }
    55 @@ -526,6 +530,22 @@
     75@@ -526,6 +530,27 @@
    5676             self._render_options(optionsElement)
    5777 
     
    6383+                element.name == 'affiliation'):
    6484+                try:
    65 +                    entity = jid.internJID(element['jid'])
     85+                    entity = jid.internJID(element['jid']).userhostJID()
    6686+                except KeyError:
    6787+                    raise BadRequest(text='Missing jid attribute')
     88+
     89+                if entity in self.affiliations:
     90+                    raise BadRequest(text='Multiple affiliations for an entity')
     91+
    6892+                try:
    6993+                    affiliation = element['affiliation']
    7094+                except KeyError:
    7195+                    raise BadRequest(text='Missing affiliation attribute')
     96+
    7297+                self.affiliations[entity] = affiliation
    7398+
     
    76101         """
    77102         Parse the publish-subscribe verb and parameters out of a request.
    78 @@ -1303,6 +1323,22 @@
     103@@ -1303,6 +1328,22 @@
    79104 
    80105         return message
     
    101126diff -r f69b08281bec wokkel/test/test_pubsub.py
    102127--- a/wokkel/test/test_pubsub.py        Sat Feb 12 00:08:30 2011 +0100
    103 +++ b/wokkel/test/test_pubsub.py        Sat Feb 12 09:41:40 2011 +0100
     128+++ b/wokkel/test/test_pubsub.py        Sat Feb 12 19:16:00 2011 +0100
    104129@@ -3192,7 +3192,45 @@
    105130 
     
    149174 
    150175         xml = """
    151 @@ -3204,44 +3242,44 @@
     176@@ -3204,39 +3242,90 @@
    152177         </iq>
    153178         """
     
    193218         """
    194219 
    195 -        def cb(result):
     220+        def affiliationsSet(request):
     221+            self.assertEquals(u'test', request.nodeIdentifier)
     222+            otherJID = JID(u'other@example.org')
     223+            self.assertIn(otherJID, request.affiliations)
     224+            self.assertEquals(u'publisher', request.affiliations[otherJID])
     225+
     226+        self.resource.affiliationsSet = affiliationsSet
     227+        return self.handleRequest(xml)
     228+
     229+
     230+    def test_on_affiliationsSetBareJID(self):
     231+        """
     232+        Affiliations are always on the bare JID.
     233+        """
     234+
     235+        xml = """
     236+        <iq type='set' to='pubsub.example.org'
     237+                       from='user@example.org'>
     238+          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
     239+            <affiliations node='test'>
     240+              <affiliation jid='other@example.org/Home'
     241+                           affiliation='publisher'/>
     242+            </affiliations>
     243+          </pubsub>
     244+        </iq>
     245+        """
     246+
     247+        def affiliationsSet(request):
     248+            otherJID = JID(u'other@example.org')
     249+            self.assertIn(otherJID, request.affiliations)
     250+
     251+        self.resource.affiliationsSet = affiliationsSet
     252+        return self.handleRequest(xml)
     253+
     254+
     255+    def test_on_affiliationsSetMultipleForSameEntity(self):
     256+        """
     257+        Setting node affiliations can only have one item per entity.
     258+        """
     259+
     260+        xml = """
     261+        <iq type='set' to='pubsub.example.org'
     262+                       from='user@example.org'>
     263+          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
     264+            <affiliations node='test'>
     265+              <affiliation jid='other@example.org' affiliation='publisher'/>
     266+              <affiliation jid='other@example.org' affiliation='owner'/>
     267+            </affiliations>
     268+          </pubsub>
     269+        </iq>
     270+        """
     271+
     272         def cb(result):
    196273-            self.assertEquals('feature-not-implemented', result.condition)
    197274-            self.assertEquals('unsupported', result.appCondition.name)
     
    199276-            self.assertEquals('modify-affiliations',
    200277-                              result.appCondition['feature'])
    201 -
    202 -        d = self.handleRequest(xml)
    203 -        self.assertFailure(d, error.StanzaError)
    204 -        d.addCallback(cb)
    205 -        return d
    206 +        def affiliationsSet(request):
    207 +            self.assertEquals(u'test', request.nodeIdentifier)
    208 +            otherJID = JID(u'other@example.org')
    209 +            self.assertIn(otherJID, request.affiliations)
    210 +            self.assertEquals(u'publisher', request.affiliations[otherJID])
    211 +
    212 +        self.resource.affiliationsSet = affiliationsSet
    213 +        return self.handleRequest(xml)
    214  
    215  
    216  
    217 @@ -3914,3 +3952,39 @@
     278+            self.assertEquals('bad-request', result.condition)
     279 
     280         d = self.handleRequest(xml)
     281         self.assertFailure(d, error.StanzaError)
     282@@ -3914,3 +4003,39 @@
    218283         self.assertFailure(d, error.StanzaError)
    219284         d.addCallback(cb)
Note: See TracChangeset for help on using the changeset viewer.