def cb(new_node): # need some way of identifying these nodes if APIMixin gets restarted # e.g. use pubsub node tree and have an API folder? self.clients[jid] = new_node ds = [] ds.append(psaff.makeSubscriptions( self.jid, new_node, set([ps.Subscription( nodeIdentifier=None, subscriber=jid, state='subscribed' )]), self.psclient.xmlstream )) ds.append(psaff.makeAffiliations( self.jid, new_node, dict({jid.full(): 'publisher'}), self.psclient.xmlstream )) def inner(data): return new_node def eb(err): return self.api_unregister(jid) l = defer.DeferredList(ds) l.addCallbacks(inner, eb) return l
def manageAffiliations(sender, name, pubs, admins, xs, includeAdmin=False): # set up affiliations, least significant first so that more significant with same key # overwrite ones that are less significant specials = set([sender.full(), collab.ADMIN_JID]) affiliations = {} def setAffiliation(j, aff): affiliations[j] = aff old_affs = yield psaff.getAffiliations( sender=sender, node=name, xs=xs ) log.msg('old affiliations %s' % old_affs) [setAffiliation(j.full(), u'none') for j, aff in old_affs.iteritems() if j.full() not in specials] if len(affiliations) > 0: yield psaff.makeAffiliations( sender=sender, node=name, affiliations=affiliations, xs=xs) affiliations = {} [setAffiliation(p, u'publisher') for p in pubs if p not in specials] [setAffiliation(a, u'owner') for a in admins if a not in specials] if includeAdmin: affiliations[collab.ADMIN_JID] = u'owner' if len(affiliations) > 0: yield psaff.makeAffiliations( sender=sender, node=name, affiliations=affiliations, xs=xs)