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
    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
 def test_setNodeTextFromHtmlID(self):
     ce = ICollaborativelyEditable(self.doc)
     ce.setNodeTextFromHtmlID('text', 'New text')
     self.assertEqual('New text', self.doc.getRawText())
 def test_setNodeTextFromHtmlID(self):
     ce = ICollaborativelyEditable(self.doc)
     ce.setNodeTextFromHtmlID('form-widgets-text',
                              'New text'.decode('utf-8'))
     self.assertEqual('New text', self.doc.text)
Esempio n. 5
0
 def test_setNodeTextFromHtmlID(self):
     ce = ICollaborativelyEditable(self.doc)
     ce.setNodeTextFromHtmlID('form-widgets-text',
                              'New text'.decode('utf-8'))
     self.assertEqual('New text', self.doc.text)
 def test_setNodeTextFromHtmlID(self):
     ce = ICollaborativelyEditable(self.doc)
     ce.setNodeTextFromHtmlID("text", "New text")
     self.assertEqual("New text", self.doc.getRawText())