Ignore:
Timestamp:
Feb 12, 2011, 10:58:46 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add support for managing affiliations of Publish-Subscribe nodes, server-side.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r92 r93  
    221221                         L{Subscription}.
    222222    @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}
    223226    """
    224227
     
    235238    subscriptionIdentifier = None
    236239    subscriptions = None
     240    affiliations = None
    237241
    238242    # Map request iq type and subelement name to request verb
     
    280284        'delete': ['node'],
    281285        'affiliationsGet': ['nodeOrEmpty'],
    282         'affiliationsSet': [],
     286        'affiliationsSet': ['nodeOrEmpty', 'affiliations'],
    283287        'subscriptionsGet': ['nodeOrEmpty'],
    284288        'subscriptionsSet': [],
     
    525529            optionsElement = verbElement.parent.addElement('options')
    526530            self._render_options(optionsElement)
     531
     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']).userhostJID()
     540                except KeyError:
     541                    raise BadRequest(text='Missing jid attribute')
     542
     543                if entity in self.affiliations:
     544                    raise BadRequest(text='Multiple affiliations for an entity')
     545
     546                try:
     547                    affiliation = element['affiliation']
     548                except KeyError:
     549                    raise BadRequest(text='Missing affiliation attribute')
     550
     551                self.affiliations[entity] = affiliation
    527552
    528553
     
    13041329        return message
    13051330
     1331
     1332    def _toResponse_affiliationsGet(self, result, resource, request):
     1333        response = domish.Element((NS_PUBSUB_OWNER, 'pubsub'))
     1334        affiliations = response.addElement('affiliations')
     1335
     1336        if request.nodeIdentifier:
     1337            affiliations['node'] = request.nodeIdentifier
     1338
     1339        for entity, affiliation in result.iteritems():
     1340            item = affiliations.addElement('affiliation')
     1341            item['jid'] = entity.full()
     1342            item['affiliation'] = affiliation
     1343
     1344        return response
     1345
     1346
    13061347    # public methods
    13071348
Note: See TracChangeset for help on using the changeset viewer.