source:
ralphm-patches/pubsub_manage_affiliations.patch
@
45:51ac2274f989
Last change on this file since 45:51ac2274f989 was 45:51ac2274f989, checked in by Ralph Meijer <ralphm@…>, 12 years ago | |
---|---|
File size: 9.0 KB |
-
wokkel/iwokkel.py
# HG changeset patch # Parent f69b08281becebb5483f3f2dfb0451ad3086a463 diff -r f69b08281bec wokkel/iwokkel.py
a b 767 767 deleted. 768 768 @rtype: L{defer.Deferred} 769 769 """ 770 771 772 def affiliationsGet(request): 773 """ 774 Called when a affiliations retrieval request (owner) has been received. 775 776 @param request: The publish-subscribe request. 777 @type request: L{wokkel.pubsub.PubSubRequest} 778 @return: A deferred that fires with a C{dict} of affiliations with the 779 entity as key (L{JID}) and the affiliation state as value 780 (C{unicode}). The affiliation can be C{u'owner'}, C{u'publisher'}, 781 or C{u'outcast'}. 782 @rtype: L{defer.Deferred} 783 """ -
wokkel/pubsub.py
diff -r f69b08281bec wokkel/pubsub.py
a b 220 220 @ivar subscriptions: Subscriptions to be modified, as a set of 221 221 L{Subscription}. 222 222 @type subscriptions: C{set} 223 @ivar affiliations: Affiliations to be modified, as a dictionary of entity 224 (L{JID} to affiliation (C{unicode}). 225 @type affiliations: C{dict} 223 226 """ 224 227 225 228 verb = None … … 234 237 subscriber = None 235 238 subscriptionIdentifier = None 236 239 subscriptions = None 240 affiliations = None 237 241 238 242 # Map request iq type and subelement name to request verb 239 243 _requestVerbMap = { … … 279 283 'purge': ['node'], 280 284 'delete': ['node'], 281 285 'affiliationsGet': ['nodeOrEmpty'], 282 'affiliationsSet': [ ],286 'affiliationsSet': ['nodeOrEmpty', 'affiliations'], 283 287 'subscriptionsGet': ['nodeOrEmpty'], 284 288 'subscriptionsSet': [], 285 289 } … … 526 530 self._render_options(optionsElement) 527 531 528 532 533 def _parse_affiliations(self, verbElement): 534 self.affiliations = {} 535 for element in verbElement.elements(): 536 if (element.uri == NS_PUBSUB_OWNER and 537 element.name == 'affiliation'): 538 try: 539 entity = jid.internJID(element['jid']) 540 except KeyError: 541 raise BadRequest(text='Missing jid attribute') 542 try: 543 affiliation = element['affiliation'] 544 except KeyError: 545 raise BadRequest(text='Missing affiliation attribute') 546 self.affiliations[entity] = affiliation 547 548 529 549 def parseElement(self, element): 530 550 """ 531 551 Parse the publish-subscribe verb and parameters out of a request. … … 1303 1323 1304 1324 return message 1305 1325 1326 1327 def _toResponse_affiliationsGet(self, result, resource, request): 1328 response = domish.Element((NS_PUBSUB_OWNER, 'pubsub')) 1329 affiliations = response.addElement('affiliations') 1330 1331 if request.nodeIdentifier: 1332 affiliations['node'] = request.nodeIdentifier 1333 1334 for entity, affiliation in result.iteritems(): 1335 item = affiliations.addElement('affiliation') 1336 item['jid'] = entity.full() 1337 item['affiliation'] = affiliation 1338 1339 return response 1340 1341 1306 1342 # public methods 1307 1343 1308 1344 def notifyPublish(self, service, nodeIdentifier, notifications): -
wokkel/test/test_pubsub.py
diff -r f69b08281bec wokkel/test/test_pubsub.py
a b 3192 3192 3193 3193 def test_on_affiliationsGet(self): 3194 3194 """ 3195 Getting subscription options is not supported. 3195 Getting node affiliations should have. 3196 """ 3197 3198 xml = """ 3199 <iq type='get' to='pubsub.example.org' 3200 from='user@example.org'> 3201 <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> 3202 <affiliations node='test'/> 3203 </pubsub> 3204 </iq> 3205 """ 3206 3207 def affiliationsGet(request): 3208 self.assertEquals('test', request.nodeIdentifier) 3209 return defer.succeed({JID('user@example.org'): 'owner'}) 3210 3211 def cb(element): 3212 self.assertEquals(u'pubsub', element.name) 3213 self.assertEquals(NS_PUBSUB_OWNER, element.uri) 3214 self.assertEquals(NS_PUBSUB_OWNER, element.affiliations.uri) 3215 self.assertEquals(u'test', element.affiliations[u'node']) 3216 children = list(element.affiliations.elements()) 3217 self.assertEquals(1, len(children)) 3218 affiliation = children[0] 3219 self.assertEquals(u'affiliation', affiliation.name) 3220 self.assertEquals(NS_PUBSUB_OWNER, affiliation.uri) 3221 self.assertEquals(u'user@example.org', affiliation[u'jid']) 3222 self.assertEquals(u'owner', affiliation[u'affiliation']) 3223 3224 self.resource.affiliationsGet = affiliationsGet 3225 verify.verifyObject(iwokkel.IPubSubResource, self.resource) 3226 d = self.handleRequest(xml) 3227 d.addCallback(cb) 3228 return d 3229 3230 3231 def test_on_affiliationsGetEmptyNode(self): 3232 """ 3233 Getting node affiliations without node should assume empty node. 3196 3234 """ 3197 3235 3198 3236 xml = """ … … 3204 3242 </iq> 3205 3243 """ 3206 3244 3207 def cb(result): 3208 self.assertEquals('feature-not-implemented', result.condition) 3209 self.assertEquals('unsupported', result.appCondition.name) 3210 self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) 3211 self.assertEquals('modify-affiliations', 3212 result.appCondition['feature']) 3213 3245 def affiliationsGet(request): 3246 self.assertIdentical('', request.nodeIdentifier) 3247 return defer.succeed({}) 3248 3249 def cb(element): 3250 self.assertFalse(element.affiliations.hasAttribute(u'node')) 3251 3252 self.resource.affiliationsGet = affiliationsGet 3253 verify.verifyObject(iwokkel.IPubSubResource, self.resource) 3214 3254 d = self.handleRequest(xml) 3215 self.assertFailure(d, error.StanzaError)3216 3255 d.addCallback(cb) 3217 3256 return d 3218 3257 3219 3258 3220 3259 def test_on_affiliationsSet(self): 3221 3260 """ 3222 Setting subscription options is not supported.3261 Setting node affiliations has the affiliations to be modified. 3223 3262 """ 3224 3263 3225 3264 xml = """ 3226 3265 <iq type='set' to='pubsub.example.org' 3227 3266 from='user@example.org'> 3228 3267 <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> 3229 <affiliations/> 3268 <affiliations node='test'> 3269 <affiliation jid='other@example.org' affiliation='publisher'/> 3270 </affiliations> 3230 3271 </pubsub> 3231 3272 </iq> 3232 3273 """ 3233 3274 3234 def cb(result): 3235 self.assertEquals('feature-not-implemented', result.condition) 3236 self.assertEquals('unsupported', result.appCondition.name) 3237 self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) 3238 self.assertEquals('modify-affiliations', 3239 result.appCondition['feature']) 3240 3241 d = self.handleRequest(xml) 3242 self.assertFailure(d, error.StanzaError) 3243 d.addCallback(cb) 3244 return d 3275 def affiliationsSet(request): 3276 self.assertEquals(u'test', request.nodeIdentifier) 3277 otherJID = JID(u'other@example.org') 3278 self.assertIn(otherJID, request.affiliations) 3279 self.assertEquals(u'publisher', request.affiliations[otherJID]) 3280 3281 self.resource.affiliationsSet = affiliationsSet 3282 return self.handleRequest(xml) 3245 3283 3246 3284 3247 3285 … … 3914 3952 self.assertFailure(d, error.StanzaError) 3915 3953 d.addCallback(cb) 3916 3954 return d 3955 3956 3957 def test_affiliationsGet(self): 3958 """ 3959 Non-overridden owner affiliations get yields unsupported error. 3960 """ 3961 3962 def cb(result): 3963 self.assertEquals('feature-not-implemented', result.condition) 3964 self.assertEquals('unsupported', result.appCondition.name) 3965 self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) 3966 self.assertEquals('modify-affiliations', 3967 result.appCondition['feature']) 3968 3969 d = self.resource.affiliationsGet(pubsub.PubSubRequest()) 3970 self.assertFailure(d, error.StanzaError) 3971 d.addCallback(cb) 3972 return d 3973 3974 3975 def test_affiliationsSet(self): 3976 """ 3977 Non-overridden owner affiliations set yields unsupported error. 3978 """ 3979 3980 def cb(result): 3981 self.assertEquals('feature-not-implemented', result.condition) 3982 self.assertEquals('unsupported', result.appCondition.name) 3983 self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) 3984 self.assertEquals('modify-affiliations', 3985 result.appCondition['feature']) 3986 3987 d = self.resource.affiliationsGet(pubsub.PubSubRequest()) 3988 self.assertFailure(d, error.StanzaError) 3989 d.addCallback(cb) 3990 return d
Note: See TracBrowser
for help on using the repository browser.