Commit c5027fb7 authored by Sven Franck's avatar Sven Franck

erp5_web: add Static Web Site for domain redirection

/reviewed-on nexedi/erp5!737
parent 0d7a728a
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/WebSite_view</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
##############################################################################
#
# Copyright (c) 2002-2006 Nexedi SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from erp5.component.document import StaticWebSection
from Products.ERP5Type import Permissions, PropertySheet
class StaticWebSite(StaticWebSection.StaticWebSection):
"""
The Web Site root class is specialises WebSection
by defining a global webmaster user.
"""
# CMF Type Definition
meta_type = 'ERP5 Static Web Site'
portal_type = 'Static Web Site'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.WebSection
, PropertySheet.WebSite
, PropertySheet.Predicate
)
security.declareProtected(Permissions.AccessContentsInformation, 'getWebSiteValue')
def getWebSiteValue(self):
"""
Returns the current web site (ie. self) though containment acquisition
"""
return self
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Document 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>StaticWebSite</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>document.erp5.StaticWebSite</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Document 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>
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<item>Web Section</item> <item>Web Section</item>
</portal_type> </portal_type>
<portal_type id="Web Site Module"> <portal_type id="Web Site Module">
<item>Static Web Site</item>
<item>Web Site</item> <item>Web Site</item>
</portal_type> </portal_type>
</allowed_content_type_list> </allowed_content_type_list>
\ No newline at end of file
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
<item>aggregate</item> <item>aggregate</item>
<item>caching_policy</item> <item>caching_policy</item>
</portal_type> </portal_type>
<portal_type id="Static Web Site">
<item>aggregate</item>
<item>caching_policy</item>
</portal_type>
<portal_type id="Web Page"> <portal_type id="Web Page">
<item>predecessor</item> <item>predecessor</item>
<item>publication_section</item> <item>publication_section</item>
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<portal_type id="Static Web Section"> <portal_type id="Static Web Section">
<item>SortIndex</item> <item>SortIndex</item>
</portal_type> </portal_type>
<portal_type id="Static Web Site">
<item>WebSitePreference</item>
</portal_type>
<portal_type id="Web Page"> <portal_type id="Web Page">
<item>Reference</item> <item>Reference</item>
<item>SortIndex</item> <item>SortIndex</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_property_domain_dict</string> </key>
<value>
<dictionary>
<item>
<key> <string>short_title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>acquire_local_roles</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>content_icon</string> </key>
<value> <string>web_site.png</string> </value>
</item>
<item>
<key> <string>content_meta_type</string> </key>
<value> <string>ERP5 Web Site</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>A Static Web Site defines an optional default web page and a predicate to select content listed in that section. Contrary to Web Site it disables acquisition to provide only document from the DMS</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addWebSite</string> </value>
</item>
<item>
<key> <string>filter_content_types</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Static Web Site</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
<value> <string>StaticWebSite_init</string> </value>
</item>
<item>
<key> <string>permission</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>StaticWebSite</string> </value>
</item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>short_title</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>title</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
<type>Static Web Section</type> <type>Static Web Section</type>
<workflow>category_publication_workflow, edit_workflow</workflow> <workflow>category_publication_workflow, edit_workflow</workflow>
</chain> </chain>
<chain>
<type>Static Web Site</type>
<workflow>category_publication_workflow, edit_workflow</workflow>
</chain>
<chain> <chain>
<type>Web Page</type> <type>Web Page</type>
<workflow>document_conversion_interaction_workflow, document_security_interaction_workflow, edit_workflow, processing_status_workflow, publication_workflow</workflow> <workflow>document_conversion_interaction_workflow, document_security_interaction_workflow, edit_workflow, processing_status_workflow, publication_workflow</workflow>
......
<registered_skin_selection>
<skin_folder_selection>
<skin_folder>erp5_web_redirect_assist</skin_folder>
<skin_selection>RedirectAssist</skin_selection>
</skin_folder_selection>
<skin_folder_selection>
<skin_folder>erp5_xhtml_style</skin_folder>
<skin_selection>RedirectAssist</skin_selection>
</skin_folder_selection>
</registered_skin_selection>
\ No newline at end of file
"""
================================================================================
Set default parameters of static web site for redirection
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
context.edit(
layout_configuration_form_id="StaticWebSite_viewRedirectAssistConfiguration",
skin_selection_name="RedirectAssist",
custom_render_method_id="StaticWebSite_getRedirectSourceUrl"
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSite_init</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Guard" module="Products.DCWorkflow.Guard"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>roles</string> </key>
<value>
<tuple>
<string>Owner</string>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>This form provides access to frontend configuration properties handled on the backend (eg redirect)</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left (Style)</string>
<string>right (Widgets)</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left (Style)</string> </key>
<value>
<list>
<string>my_redirect_domain</string>
<string>my_use_moved_temporarily</string>
</list>
</value>
</item>
<item>
<key> <string>right (Widgets)</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSite_viewRedirectAssistConfiguration</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>StaticWebSite_viewRedirectAssistConfiguration</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Redirect Assist Configuration</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>input_type</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_redirect_domain</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string>url</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Redirect Domain</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>description</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_use_moved_temporarily</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string>By default, redirects will respond 301 Moved Permanently. Ticking the box will respond using 302 Moved Temporarily.</string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_checkbox</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewWebFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Override 301 with 302 Status Code</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>business_template_skin_layer_priority</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>float</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>business_template_skin_layer_priority</string> </key>
<value> <float>50.0</float> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_web_redirect_assist</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
================================================================================
Proxy of StaticWebSection_getDocumentValue to allow redirection
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
# name main_template
context.REQUEST.other['actual_url'] = context.REQUEST['ACTUAL_URL']
# catch KeyError on source_path with urls "", "?", "/?", "...&"
try:
context.REQUEST.other['source_path'] = name
except KeyError:
return context
return context
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>name, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSite_getDocumentValue</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
================================================================================
Redirect to domain specified as layout property on website
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
INDEX = "index.html"
REQUEST = context.REQUEST
query_string = REQUEST["QUERY_STRING"]
redirect_domain = context.getLayoutProperty("redirect_domain")
redirect_url = redirect_domain
status_code = 301
if context.getLayoutProperty("use_moved_temporarily"):
status_code = 302
try:
source_path = REQUEST.other["source_path"]
redirect_url = "/".join([redirect_url, source_path])
except(KeyError):
redirect_url = redirect_url + "/"
if query_string:
redirect_url = '?'.join([redirect_url, query_string])
if redirect_url.find(INDEX) > -1 and not redirect_url.endswith(INDEX):
redirect_url = redirect_url.replace(INDEX, '')
if redirect_url.find(INDEX) > -1 and REQUEST.other['actual_url'].find(INDEX) == -1:
redirect_url = redirect_url.replace(INDEX, '')
return context.Base_redirect(redirect_url, status_code=status_code)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSite_getRedirectSourceUrl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -9,6 +9,7 @@ Static Web Section | predicate ...@@ -9,6 +9,7 @@ Static Web Section | predicate
Static Web Section | section_content Static Web Section | section_content
Static Web Section | view Static Web Section | view
Static Web Section | web_view Static Web Section | web_view
Static Web Site | view
Web Page Module | list_ui Web Page Module | list_ui
Web Page Module | sort_on Web Page Module | sort_on
Web Page Module | view Web Page Module | view
......
document.erp5.StaticWebSection document.erp5.StaticWebSection
\ No newline at end of file document.erp5.StaticWebSite
\ No newline at end of file
...@@ -8,6 +8,7 @@ Web Section | Image ...@@ -8,6 +8,7 @@ Web Section | Image
Web Section | Role Definition Web Section | Role Definition
Web Section | Static Web Section Web Section | Static Web Section
Web Section | Web Section Web Section | Web Section
Web Site Module | Static Web Site
Web Site Module | Web Site Web Site Module | Web Site
Web Site | File Web Site | File
Web Site | Image Web Site | Image
......
Static Web Section | aggregate Static Web Section | aggregate
Static Web Section | caching_policy Static Web Section | caching_policy
Static Web Site | aggregate
Static Web Site | caching_policy
Web Page Module | business_application Web Page Module | business_application
Web Page | predecessor Web Page | predecessor
Web Page | publication_section Web Page | publication_section
......
Static Web Section Static Web Section
Static Web Site
Web Page Web Page
Web Page Module Web Page Module
Web Section Web Section
......
Static Web Section | SortIndex Static Web Section | SortIndex
Static Web Site | WebSitePreference
Web Page | Reference Web Page | Reference
Web Page | SortIndex Web Page | SortIndex
Web Section | SortIndex Web Section | SortIndex
......
...@@ -4,6 +4,8 @@ Category | category_publication_workflow ...@@ -4,6 +4,8 @@ Category | category_publication_workflow
Domain | category_publication_workflow Domain | category_publication_workflow
Static Web Section | category_publication_workflow Static Web Section | category_publication_workflow
Static Web Section | edit_workflow Static Web Section | edit_workflow
Static Web Site | category_publication_workflow
Static Web Site | edit_workflow
Web Page | document_conversion_interaction_workflow Web Page | document_conversion_interaction_workflow
Web Page | document_security_interaction_workflow Web Page | document_security_interaction_workflow
Web Page | edit_workflow Web Page | edit_workflow
......
erp5_web_redirect_assist | RedirectAssist
erp5_xhtml_style | RedirectAssist
\ No newline at end of file
erp5_web erp5_web
erp5_web_crm erp5_web_crm
erp5_web_minimal_theme erp5_web_minimal_theme
erp5_web_redirect_assist
erp5_web_widget_library erp5_web_widget_library
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2002-2018 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import urlparse
import httplib
import unittest
LOCATION = "Location"
WEB_SITE_ID = "bouncer"
class TestStaticWebSectionRedirection(ERP5TypeTestCase):
def getTitle(self):
return "Test Static Web Section Redirection."
def getBusinessTemplateList(self):
return (
"erp5_base",
"erp5_web",
"erp5_ui_test_core"
)
def afterSetup(self):
"""
This is ran before anything, used to set the environment
"""
self.portal = self.getPortalObject()
def setupWebSite(self, use_moved_temporarily=None, **kw):
"""
Setup Web Site
"""
if WEB_SITE_ID in self.portal.web_site_module.objectIds():
self.portal.web_site_module.manage_delObjects(WEB_SITE_ID)
website = self.portal.web_site_module.newContent(
portal_type="Static Web Site",
id=WEB_SITE_ID,
**kw
)
website.edit(
redirect_domain="https://www.example.org",
use_moved_temporarily=use_moved_temporarily or 0
)
website.publish()
self.tic()
return website
def runTestRedirect(self, source_path, expected_failure=None, use_moved_temporarily=None, **kw):
"""
Redirect to backend configuration redirect_domain
"""
# create website and websection
website = self.setupWebSite(use_moved_temporarily=use_moved_temporarily)
absolute_url = website.absolute_url()
# XXX can't handle "?" at path end, swallowed before __bobo_traverse__
if source_path.endswith("/?"):
source_path = source_path[:-2]
if source_path.endswith("?"):
source_path = source_path[:-1]
_, api_netloc, _, _, _ = urlparse.urlsplit(absolute_url)
redirect_url = website.getLayoutProperty("redirect_domain")
redirect_location = "/".join([redirect_url, source_path])
connection = httplib.HTTPConnection(api_netloc)
connection.request(
method="GET",
url='%s/%s' % (absolute_url, source_path)
)
response = connection.getresponse()
status_to_assert = httplib.MOVED_PERMANENTLY
if use_moved_temporarily:
status_to_assert = httplib.FOUND
self.assertEquals(response.status, status_to_assert)
self.assertEquals(response.getheader(LOCATION), redirect_location)
##############################################################################
def test_plainRedirect(self):
self.runTestRedirect("")
def test_plainRedirectIndex(self):
self.runTestRedirect("index.html")
def test_plainRedirectQuery(self):
self.runTestRedirect("?")
def test_plainRedirectQueryWithParams(self):
self.runTestRedirect("?a=b&c=&amp;d=e&")
def test_plainRedirectFolderNoSlash(self):
self.runTestRedirect("foo")
def test_plainRedirectFolderSlash(self):
self.runTestRedirect("foo/")
def test_plainRedirectFolderNested(self):
self.runTestRedirect("foo/bar")
def test_plainRedirectFolderDeepNested(self):
self.runTestRedirect("foo/bar/baz")
def test_plainRedirectFolderNestedWithIndex(self):
self.runTestRedirect("foo/bar/index.html")
def test_queryStringRedirectFolder(self):
self.runTestRedirect("foo?baz=bam")
def test_queryStringRedirectFolderSlash(self):
self.runTestRedirect("foo/?baz=bam")
def test_queryStringRedirectFolderNested(self):
self.runTestRedirect("foo/bar?baz=bam")
def test_queryStringRedirectFolderDeepNested(self):
self.runTestRedirect("foo/bar/baz?baz=bam&cous=cous&amp;the=end")
def test_queryStringRedirectSlashQuestion(self):
self.runTestRedirect("foo/bar/?")
@unittest.expectedFailure
def test_queryStringIgnoreLayout(self):
self.runTestRedirect("?ignore_layout=1")
def test_plainRedirectGetId(self):
self.runTestRedirect("getId")
def test_plainRedirectWebSiteView(self):
self.runTestRedirect("WebSite_view")
def test_302queryStringRedirectFolderDeepNested(self):
self.runTestRedirect("foo/bar/baz?baz=bam&cous=cous&amp;the=end", use_moved_temporarily=1)
<?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>testStaticWebSiteRedirection</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Tests testing various redirections handled by static web site.</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testStaticWebSiteRedirection</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>
erp5_web erp5_web
erp5_ui_test_core
erp5_ui_test erp5_ui_test
\ No newline at end of file
test.erp5.testStaticWebSiteRedirection
\ No newline at end of file
erp5_full_text_mroonga_catalog
\ No newline at end of file
...@@ -180,7 +180,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -180,7 +180,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
acquiring it from the current section or its parents. acquiring it from the current section or its parents.
""" """
section = aq_inner(self) section = aq_inner(self)
while section.getPortalType() in ('Web Section', 'Web Site', 'Static Web Section'): while section.getPortalType() in ('Web Section', 'Web Site', 'Static Web Section', 'Static Web Site'):
result = section.getProperty(key, MARKER) result = section.getProperty(key, MARKER)
if result not in (MARKER, None): if result not in (MARKER, None):
return result return result
......
...@@ -31,4 +31,4 @@ if len(parameters): ...@@ -31,4 +31,4 @@ if len(parameters):
if abort_transaction: if abort_transaction:
from zExceptions import Redirect from zExceptions import Redirect
raise Redirect(redirect_url) raise Redirect(redirect_url)
return request.RESPONSE.redirect(redirect_url) return request.RESPONSE.redirect(redirect_url, status=status_code)
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>redirect_url=None, keep_items=(), abort_transaction=False, **kw</string> </value> <value> <string>redirect_url=None, keep_items=(), abort_transaction=False, status_code=302, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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