Changeset 46:5ec77d2dcdb4 in ralphm-patches
- Timestamp:
- Feb 12, 2011, 7:16:51 PM (11 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pubsub_manage_affiliations.patch
r45 r46 1 1 # HG changeset patch 2 2 # Parent f69b08281becebb5483f3f2dfb0451ad3086a463 3 Add support for managing affiliations of Publish-Subscribe nodes. 3 4 4 5 diff -r f69b08281bec wokkel/iwokkel.py 5 6 --- a/wokkel/iwokkel.py Sat Feb 12 00:08:30 2011 +0100 6 +++ b/wokkel/iwokkel.py Sat Feb 12 09:41:40 2011 +01007 @@ -767,3 +767, 17@@7 +++ b/wokkel/iwokkel.py Sat Feb 12 19:16:00 2011 +0100 8 @@ -767,3 +767,36 @@ 8 9 deleted. 9 10 @rtype: L{defer.Deferred} … … 22 23 + or C{u'outcast'}. 23 24 + @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. 24 44 + """ 25 45 diff -r f69b08281bec wokkel/pubsub.py 26 46 --- a/wokkel/pubsub.py Sat Feb 12 00:08:30 2011 +0100 27 +++ b/wokkel/pubsub.py Sat Feb 12 09:41:40 2011 +010047 +++ b/wokkel/pubsub.py Sat Feb 12 19:16:00 2011 +0100 28 48 @@ -220,6 +220,9 @@ 29 49 @ivar subscriptions: Subscriptions to be modified, as a set of … … 53 73 'subscriptionsSet': [], 54 74 } 55 @@ -526,6 +530,2 2@@75 @@ -526,6 +530,27 @@ 56 76 self._render_options(optionsElement) 57 77 … … 63 83 + element.name == 'affiliation'): 64 84 + try: 65 + entity = jid.internJID(element['jid']) 85 + entity = jid.internJID(element['jid']).userhostJID() 66 86 + except KeyError: 67 87 + raise BadRequest(text='Missing jid attribute') 88 + 89 + if entity in self.affiliations: 90 + raise BadRequest(text='Multiple affiliations for an entity') 91 + 68 92 + try: 69 93 + affiliation = element['affiliation'] 70 94 + except KeyError: 71 95 + raise BadRequest(text='Missing affiliation attribute') 96 + 72 97 + self.affiliations[entity] = affiliation 73 98 + … … 76 101 """ 77 102 Parse the publish-subscribe verb and parameters out of a request. 78 @@ -1303,6 +132 3,22 @@103 @@ -1303,6 +1328,22 @@ 79 104 80 105 return message … … 101 126 diff -r f69b08281bec wokkel/test/test_pubsub.py 102 127 --- 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 +0100128 +++ b/wokkel/test/test_pubsub.py Sat Feb 12 19:16:00 2011 +0100 104 129 @@ -3192,7 +3192,45 @@ 105 130 … … 149 174 150 175 xml = """ 151 @@ -3204, 44 +3242,44@@176 @@ -3204,39 +3242,90 @@ 152 177 </iq> 153 178 """ … … 193 218 """ 194 219 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): 196 273 - self.assertEquals('feature-not-implemented', result.condition) 197 274 - self.assertEquals('unsupported', result.appCondition.name) … … 199 276 - self.assertEquals('modify-affiliations', 200 277 - 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 @@ 218 283 self.assertFailure(d, error.StanzaError) 219 284 d.addCallback(cb)
Note: See TracChangeset
for help on using the changeset viewer.