def getNodeText(self, jid, node):
     app = Zope2.app()
     text = ''
     try:
         portal = app.unrestrictedTraverse(self.portal_id, None)
         if portal is None:
             raise DSCException(
                 'Portal with id %s not found' % self.portal_id)
         setSite(portal)
         acl_users = getToolByName(portal, 'acl_users')
         user_id = unescapeNode(JID(jid).user)
         user = acl_users.getUserById(user_id)
         if user is None:
             raise DSCException(
                 'Invalid user %s' % user_id)
         newSecurityManager(None, user)
         ct = getToolByName(portal, 'portal_catalog')
         uid, html_id = node.split('#')
         item = ct.unrestrictedSearchResults(UID=uid)
         if not item:
             raise DSCException(
                 'Content with UID %s not found' % uid)
         item = ICollaborativelyEditable(item[0].getObject())
         text = item.getNodeTextFromHtmlID(html_id)
     finally:
         noSecurityManager()
         setSite(None)
     return text
Пример #2
0
        def _send():
            mt = getToolByName(portal, 'portal_membership', None)
            message = Element((
                None,
                "message",
            ))
            message["id"] = getRandomId()
            message["from"] = self.xmlstream.factory.authenticator.jid.full()
            message["to"] = to.userhost()
            x = message.addElement((NS_ROSTER_X, 'x'))
            for jid in items:
                if to == jid:
                    continue

                member_id = users.unescapeNode(jid.user)
                if mt is not None and mt.getMemberInfo(member_id):
                    info = mt.getMemberInfo(member_id)
                    fullname = info.get('fullname', member_id).decode('utf-8')
                else:
                    log.warn('Could not get user fullname: %s' % member_id)
                    fullname = ''

                item = x.addElement('item')
                item["action"] = 'add'
                item["jid"] = jid.userhost()
                item["name"] = fullname
                if group:
                    item.addElement('group', content=group)
            self.xmlstream.send(message)
Пример #3
0
        def _send():
            mt = getToolByName(portal, "portal_membership", None)
            message = Element((None, "message"))
            message["id"] = getRandomId()
            message["from"] = self.xmlstream.factory.authenticator.jid.full()
            message["to"] = to.userhost()
            x = message.addElement((NS_ROSTER_X, "x"))
            for jid in items:
                if to == jid:
                    continue

                member_id = users.unescapeNode(jid.user)
                if mt is not None and mt.getMemberInfo(member_id):
                    info = mt.getMemberInfo(member_id)
                    fullname = info.get("fullname", member_id).decode("utf-8")
                else:
                    log.warn("Could not get user fullname: %s" % member_id)
                    fullname = ""

                item = x.addElement("item")
                item["action"] = "add"
                item["jid"] = jid.userhost()
                item["name"] = fullname
                if group:
                    item.addElement("group", content=group)
            self.xmlstream.send(message)
 def getNodeText(self, jid, node):
     app = Zope2.app()
     text = ''
     try:
         portal = app.unrestrictedTraverse(self.portal_id, None)
         if portal is None:
             raise DSCException('Portal with id %s not found' %
                                self.portal_id)
         setSite(portal)
         acl_users = getToolByName(portal, 'acl_users')
         user_id = unescapeNode(JID(jid).user)
         user = acl_users.getUserById(user_id)
         if user is None:
             raise DSCException('Invalid user %s' % user_id)
         newSecurityManager(None, user)
         ct = getToolByName(portal, 'portal_catalog')
         uid, html_id = node.split('#')
         item = ct.unrestrictedSearchResults(UID=uid)
         if not item:
             raise DSCException('Content with UID %s not found' % uid)
         item = ICollaborativelyEditable(item[0].getObject())
         text = item.getNodeTextFromHtmlID(html_id)
     finally:
         noSecurityManager()
         setSite(None)
     return text
Пример #5
0
 def __init__(self, jid, host, password, port, authcallback):
     self.authcallback = authcallback
     self.vcard = VCardHandler()
     self.presence = PresenceClientProtocol()
     # XXX: This is a hack. See https://github.com/ralphm/wokkel/issues/5
     # Not yet sure what the best way of dealing with this is.
     jid = JID(u"@".join((doubleEscapeNode(unescapeNode(jid.user)), jid.host)))
     super(UserClient, self).__init__(
         jid, password, extra_handlers=[self.vcard, self.presence], host=host, port=port
     )
Пример #6
0
 def __init__(self, jid, host, password, port, authcallback):
     self.authcallback = authcallback
     self.vcard = VCardHandler()
     self.presence = PresenceClientProtocol()
     # XXX: This is a hack. See https://github.com/ralphm/wokkel/issues/5
     # Not yet sure what the best way of dealing with this is.
     jid = JID(u'@'.join(
         (doubleEscapeNode(unescapeNode(jid.user)), jid.host)))
     super(UserClient, self).__init__(
         jid, password,
         extra_handlers=[self.vcard, self.presence],
         host=host,
         port=port)
    def setNodeText(self, jid, node, text):
        transaction.begin()
        app = Zope2.app()
        try:
            try:
                portal = app.unrestrictedTraverse(self.portal_id, None)
                if portal is None:
                    raise DSCException(
                        'Portal with id %s not found' % self.portal_id)
                setSite(portal)
                
                settings = getUtility(IRegistry)
                autosave = settings.get('collective.xmpp.autoSaveCollaboration', False)
                if not autosave:
                    transaction.abort()
                    return

                acl_users = getToolByName(portal, 'acl_users')
                user_id = unescapeNode(JID(jid).user)
                user = acl_users.getUserById(user_id)
                if user is None:
                    raise DSCException(
                        'Invalid user %s' % user_id)
                newSecurityManager(None, user)
                ct = getToolByName(portal, 'portal_catalog')
                uid, html_id = node.split('#')
                item = ct.unrestrictedSearchResults(UID=uid)
                if not item:
                    raise DSCException(
                        'Content with UID %s not found' % uid)
                item = ICollaborativelyEditable(item[0].getObject())
                item.setNodeTextFromHtmlID(html_id, text)
                transaction.commit()
            except:
                transaction.abort()
                raise
        finally:
            noSecurityManager()
            setSite(None)
            app._p_jar.close()
        return text
Пример #8
0
    def __call__(self, user_id):
        pm = getToolByName(self.context, 'portal_membership')
        if pm.isAnonymousUser():
            raise Unauthorized

        user_id = unescapeNode(user_id)
        info = pm.getMemberInfo(user_id)
        if info is None:
            return None
        fullname = info.get('fullname') or user_id
        portrait_url = pm.getPersonalPortrait(user_id).absolute_url()

        portal_url = getToolByName(self.context, 'portal_url')
        user_profile_url = '%s/author/%s' % (portal_url(), user_id)

        response = self.request.response
        response.setHeader('content-type', 'application/json')
        response.setBody(json.dumps({'fullname': fullname,
                                     'portrait_url': portrait_url,
                                     'user_profile_url': user_profile_url }))
        return response
    def setNodeText(self, jid, node, text):
        transaction.begin()
        app = Zope2.app()
        try:
            try:
                portal = app.unrestrictedTraverse(self.portal_id, None)
                if portal is None:
                    raise DSCException('Portal with id %s not found' %
                                       self.portal_id)
                setSite(portal)

                settings = getUtility(IRegistry)
                autosave = settings.get(
                    'collective.xmpp.autoSaveCollaboration', False)
                if not autosave:
                    transaction.abort()
                    return

                acl_users = getToolByName(portal, 'acl_users')
                user_id = unescapeNode(JID(jid).user)
                user = acl_users.getUserById(user_id)
                if user is None:
                    raise DSCException('Invalid user %s' % user_id)
                newSecurityManager(None, user)
                ct = getToolByName(portal, 'portal_catalog')
                uid, html_id = node.split('#')
                item = ct.unrestrictedSearchResults(UID=uid)
                if not item:
                    raise DSCException('Content with UID %s not found' % uid)
                item = ICollaborativelyEditable(item[0].getObject())
                item.setNodeTextFromHtmlID(html_id, text)
                transaction.commit()
            except:
                transaction.abort()
                raise
        finally:
            noSecurityManager()
            setSite(None)
            app._p_jar.close()
        return text
Пример #10
0
 def remove(self, user_id):
     user_id = unescapeNode(user_id)
     if user_id in self._passwords:
         del self._passwords[user_id]