Beispiel #1
0
 def registerAll(self):
     status = IStatusMessage(self.request)
     member_ids = users.getAllMemberIds()
     try:
         setup.registerXMPPUsers(self.context, member_ids)
     except AdminClientNotConnected:
         status.add(
             _(u"We are not yet connected to the XMPP "
               u"server. Either your settings are incorrect, or "
               u"you're trying to register users immediately after the "
               u"ZServer has been restarted. If your settings are correct, "
               u"then try again, it should work now. "), "warn")
         return
     status.add(
         _(u"All users are being registered in the background. "
           "This might take a few minutes and your site might become "
           "unresponsive."), "info")
 def registerAll(self):
     status = IStatusMessage(self.request)
     member_ids = users.getAllMemberIds()
     try:
         setup.registerXMPPUsers(self.context, member_ids)
     except AdminClientNotConnected:
         status.add(
             _(u"We are not yet connected to the XMPP "
               u"server. Either your settings are incorrect, or "
               u"you're trying to register users immediately after the "
               u"ZServer has been restarted. If your settings are correct, "
               u"then try again, it should work now. "), "warn")
         return
     status.add(_(
         u"All users are being registered in the background. "
         "This might take a few minutes and your site might become "
         "unresponsive."), "info")
Beispiel #3
0
    def updateVCards(self, member_ids=[]):
        """ """
        portal = self.context
        registry = getUtility(IRegistry)
        settings = registry.forInterface(IXMPPSettings, check=False)
        status = IStatusMessage(self.request)
        client = queryUtility(IAdminClient)
        portal_url = getToolByName(portal, 'portal_url')()
        member_dicts = []
        pass_storage = getUtility(IXMPPPasswordStorage)
        if client is None:
            status.add(UTILITY_NOT_FOUND_MESSAGE, "error")
            return

        # XXX: This is a hack. We get vcard data for all users in the site,
        # without yet knowing whether they are actually registered in the
        # XMPP server. We do this here because getPersonalPortrait doesn't
        # work in callbacks (due to Request not being set up properly).
        xmpp_users = getUtility(IXMPPUsers)
        mtool = getToolByName(portal, 'portal_membership')
        member_ids = member_ids or users.getAllMemberIds()
        log.info('Total members are: %d' % len(member_ids))
        i = 0
        for member_id in member_ids:
            member = mtool.getMemberById(member_id)
            fullname = member.getProperty('fullname').decode('utf-8')
            user_jid = xmpp_users.getUserJID(member_id)
            portrait = mtool.getPersonalPortrait(member_id)
            if isinstance(portrait, FSImage):
                raw_image = portrait._data
            else:
                raw_image = portrait.data
            udict = {
                'fullname': fullname,
                'nickname': member_id,
                'email': member.getProperty('email'),
                'userid': user_jid.userhost(),
                'jabberid': user_jid.userhost(),
                'url': '%s/author/%s' % (portal_url, member_id),
                'image_type': portrait.content_type,
                'raw_image': raw_image,
                'jid_obj': user_jid,
                'pass': pass_storage.get(member_id)
            }
            member_dicts.append(udict)
            i += 1
            log.info('Fetched details for member %d, %s' % (i, fullname))

        @newzodbconnection(portal=portal)
        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if 'node' in items[0]:
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = settings.xmpp_domain
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                member_jids = [item['jid'] for item in items]
                if settings.admin_jid in member_jids:
                    member_jids.remove(settings.admin_jid)
                registered_member_dicts = \
                    [d for d in member_dicts if d['jabberid'] in member_jids]

                @newzodbconnection(portal=portal)
                def updateVCard():
                    mdict = registered_member_dicts.pop()
                    setup.setVCard(mdict, mdict['jid_obj'], mdict['pass'],
                                   updateVCard)

                if len(registered_member_dicts):
                    zr = getUtility(IZopeReactor)
                    zr.reactor.callInThread(updateVCard)
            return

        d = client.admin.getRegisteredUsers()
        d.addCallbacks(resultReceived)
        status.add(
            _(u"Each XMPP-registered user is having their vCard "
              u"updated. This might take some minutes to complete."), "info")
        return d
    def updateVCards(self):
        """
        """
        portal = self.context
        registry = getUtility(IRegistry)
        settings = registry.forInterface(IXMPPSettings, check=False)
        status = IStatusMessage(self.request)
        client = queryUtility(IAdminClient)
        portal_url = getToolByName(portal, 'portal_url')()
        member_dicts = []
        pass_storage = getUtility(IXMPPPasswordStorage)
        if client is None:
            status.add(UTILITY_NOT_FOUND_MESSAGE, "error")
            return

        # XXX: This is a hack. We get vcard data for all users in the site,
        # without yet knowing whether they are actually registered in the
        # XMPP server. We do this here because getPersonalPortrait doesn't
        # work in callbacks (due to Request not being set up properly).
        xmpp_users = getUtility(IXMPPUsers)
        mtool = getToolByName(portal, 'portal_membership')
        member_ids = users.getAllMemberIds()
        for member_id in member_ids:
            member = mtool.getMemberById(member_id)
            fullname = member.getProperty('fullname').decode('utf-8')
            user_jid = xmpp_users.getUserJID(member_id)
            portrait = mtool.getPersonalPortrait(member_id)
            if isinstance(portrait, FSImage):
                raw_image = portrait._data
            else:
                raw_image = portrait.data
            udict = {
                'fullname': fullname,
                'nickname': member_id,
                'email': member.getProperty('email'),
                'userid': user_jid.userhost(),
                'jabberid': user_jid.userhost(),
                'url': '%s/author/%s' % (portal_url, member_id),
                'image_type': portrait.content_type,
                'raw_image': raw_image,
                'jid_obj': user_jid,
                'pass': pass_storage.get(member_id)
            }
            member_dicts.append(udict)

        @newzodbconnection(portal=portal)
        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if 'node' in items[0]:
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = settings.xmpp_domain
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                member_jids = [item['jid'] for item in items]
                if settings.admin_jid in member_jids:
                    member_jids.remove(settings.admin_jid)
                registered_member_dicts = \
                    [d for d in member_dicts if d['jabberid'] in member_jids]

                @newzodbconnection(portal=portal)
                def updateVCard():
                    mdict = registered_member_dicts.pop()
                    setup.setVCard(
                        mdict,
                        mdict['jid_obj'],
                        mdict['pass'],
                        updateVCard)

                if len(registered_member_dicts):
                    zr = getUtility(IZopeReactor)
                    zr.reactor.callInThread(updateVCard)
            return

        d = client.admin.getRegisteredUsers()
        d.addCallbacks(resultReceived)
        status.add(_(u"Each XMPP-registered user is having their vCard "
                     u"updated. This might take some minutes to complete."),
                   "info")
        return d