Commit 9a188fd1 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_officejs: improve WebSection_getDocumentValue behavior + test

to fit original script behavior, from erp5_web skin folder.
Also fixes "KeyError: TraversalRequestNameStack" from
`WebPage.getDocumentValue(reference)` on the "View" skin selection.
parent c9e807eb
......@@ -18,9 +18,8 @@
fix acquisition issues within the _aq_dynamic
lookup from WebSection class.
"""
context.log(context.REQUEST['TraversalRequestNameStack'])
stack = context.REQUEST['TraversalRequestNameStack']
stack = context.REQUEST.get('TraversalRequestNameStack', [])
if type(name) is list:
name = name[0]
url_list = [name]
......@@ -63,13 +62,44 @@ base_sort = (('effective_date', 'descending'), )
# Portal Type and validation state should be handled by predicate
# By default
web_page_list = context.searchResults(
if hasattr(context, "searchResults"):
web_page_list = context.searchResults(
reference=reference,
effective_date=effective_date,
language=(language, ''),
sort_on=(('language', 'descending'), ) + base_sort,
limit=1,
**kw)
else:
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
language=(language, ''),
sort_on=(('language', 'descending'), ) + base_sort,
limit=1,
**kw)
if len(web_page_list) == 0 and language != 'en':
# Search again with English as a fallback.
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
language='en',
sort_on=base_sort,
limit=1,
**kw)
if len(web_page_list) == 0:
# Search again without the language
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
sort_on=base_sort,
limit=1,
**kw)
if len(web_page_list) == 0:
# Default returns None
web_page = None
......
# Copyright (c) 2002-2017 Nexedi SA and Contributors. All Rights Reserved.
from DateTime import DateTime
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from base64 import b64decode
class TestErp5Officejs(ERP5TypeTestCase):
def test_webPageRestrictedTraverseOnViewSkinSelection(self):
"""
Check we can restricted traverse an image from a web page on the default
skin selection. (`web_page.getDocumentValue(reference)`)
"""
# test initialisation
image = self.portal.image_module.newContent(
portal_type="Image",
reference="TEST-Test.Restricted.Traverse.With.ERP5.Officejs",
version="001",
language="en",
filename="white_pixel.png",
data=b64decode("".join([
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAsTAAALEw",
"EAmpwYAAAAB3RJTUUH4QUdBikq4C9IOgAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdp",
"dGggR0lNUFeBDhcAAAAMSURBVAjXY/j//z8ABf4C/tzMWecAAAAASUVORK5CYII=",
])),
)
image.publish()
web_page = self.portal.web_page_module.newContent(
portal_type="Web Page",
)
self.tic()
# actual test
other_image = web_page.restrictedTraverse("TEST-Test.Restricted.Traverse.With.ERP5.Officejs")
self.assertEquals(image.getUid(), other_image.getUid())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testErp5Officejs</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testErp5Officejs</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
test.erp5.testErp5Officejs
\ No newline at end of file
erp5_full_text_mroonga_catalog
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment