Esempio n. 1
0
def publish(
        request,
        module_name,
        _get_module_info=get_module_info,  # only for testing
):
    (
        bobo_before,
        bobo_after,
        object,
        realm,
        debug_mode,
        err_hook,
        validated_hook,
        transactions_manager,
    ) = _get_module_info(module_name)

    notify(PubStart(request))
    request.processInputs()
    response = request.response

    if bobo_after is not None:
        response.after_list += (bobo_after, )

    if debug_mode:
        response.debug_mode = debug_mode

    if realm and not request.get('REMOTE_USER', None):
        response.realm = realm

    if bobo_before is not None:
        bobo_before()

    # Get the path list.
    # According to RFC1738 a trailing space in the path is valid.
    path = request.get('PATH_INFO')

    request['PARENTS'] = [object]
    object = request.traverse(path, validated_hook=validated_hook)
    notify(PubAfterTraversal(request))

    if transactions_manager:
        transactions_manager.recordMetaData(object, request)

    result = mapply(
        object,
        request.args,
        request,
        call_object,
        1,
        missing_name,
        dont_publish_class,
        request,
        bind=1,
    )

    if result is not response:
        response.setBody(result)

    notify(PubBeforeCommit(request))
    return response
Esempio n. 2
0
 def test_publish_content(self):
     context = FauxContent('foo')
     notify(ObjectCreatedEvent(context))
     request = FauxRequest(context)
     notify(PubAfterTraversal(request))
     applyTransformOnSuccess(FauxPubEvent(request))
     self.assertEqual('#{}#'.format(IUUID(context)),
                      request.response.getHeader('X-Ids-Involved'))
Esempio n. 3
0
 def test_not_found_when_acquiring_site(self):
     from Products.CMFPlone.factory import addPloneSite
     app = self.layer['app']
     addPloneSite(
         app,
         'other_plone',
         title='other plone',
         setup_content=False,
         default_language='en',
     )
     request = self.layer['request']
     base_url = request['SERVER_URL']
     request.traverse('/plone/other_plone')
     redirect(PubAfterTraversal(request))
     # raise only if MIGHT_REDIRECT
     request.set('MIGHT_REDIRECT', True)
     with self.assertRaises(NotFound) as cm:
         redirect(PubAfterTraversal(request))
Esempio n. 4
0
 def test_do_nothing_when_redirect_to_referrer(self):
     self.portal.invokeFactory('Folder', 'news')
     self.assertTrue('news' in self.portal.objectIds())
     self.portal.invokeFactory('Link', 'link')
     self.assertTrue('link' in self.portal.objectIds())
     request = self.layer['request']
     base_url = request['SERVER_URL']
     request.set('MIGHT_REDIRECT', True)
     request.set('HTTP_REFERER', 'http://nohost/plone/link')
     request.traverse('/plone/news/link')
     redirect(PubAfterTraversal(request))
Esempio n. 5
0
 def test_do_nothing_when_redirect_to_itself(self):
     self.portal.invokeFactory('Folder', 'news')
     self.assertTrue('news' in self.portal.objectIds())
     self.portal['news'].invokeFactory('Document', 'page')
     self.assertTrue('page' in self.portal['news'].objectIds())
     # simulate breakage of 'news' folder
     self.portal['news'].getOrdering().notifyRemoved('page')
     self.assertTrue('page' not in self.portal['news'].objectIds())
     request = self.layer['request']
     base_url = request['SERVER_URL']
     request.set('MIGHT_REDIRECT', True)
     request.traverse('/plone/news/page')
     redirect(PubAfterTraversal(request))
Esempio n. 6
0
 def assertRedirectWhenTraverse(self, traverse_to, redirect_to, **kw):
     request = self.layer['request']
     base_url = request['SERVER_URL']
     request.set('MIGHT_REDIRECT', True)
     for key, value in kw.items():
         request.set(key, value)
     with self.assertRaises(Redirect) as cm:
         request.traverse(traverse_to)
         # simulate ZPublisher.Publish
         redirect(PubAfterTraversal(request))
     self.assertTrue('expires' in request.response.headers)
     self.assertTrue('cache-control' in request.response.headers)
     self.assertTrue(
         request.response.headers['cache-control'].startswith('max-age=0'))
     self.assertEquals(cm.exception.message, base_url + redirect_to)
Esempio n. 7
0
 def testAfterTraversal(self):
     e = PubAfterTraversal(_Request())
     verifyObject(IPubAfterTraversal, e)