From d26b78d7498967ee7fd6649e66c4b0ec9a2b0279 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Thu, 7 Jan 2016 14:51:44 +0000
Subject: [PATCH] [erp5_web] Hateoas web section should not cache by default

Even in case of 401 HTTP code, IOS Safari caches query result, and so, prevent user to get result after being logged in.

Force no-cache header if the Hateoas rendering script does not explicitely request cache configuration.
---
 .../caching_policy_manager.xml                | 235 +++++++++++++++---
 1 file changed, 197 insertions(+), 38 deletions(-)

diff --git a/bt5/erp5_web/ToolTemplateItem/caching_policy_manager.xml b/bt5/erp5_web/ToolTemplateItem/caching_policy_manager.xml
index 6f46033866..2eb740aec9 100644
--- a/bt5/erp5_web/ToolTemplateItem/caching_policy_manager.xml
+++ b/bt5/erp5_web/ToolTemplateItem/caching_policy_manager.xml
@@ -6,6 +6,20 @@
     </pickle>
     <pickle>
       <dictionary>
+        <item>
+            <key> <string>_cache</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="CPMCache" module="Products.CMFCore.CachingPolicyManager"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary/>
+                </state>
+              </object>
+            </value>
+        </item>
         <item>
             <key> <string>_policies</string> </key>
             <value>
@@ -21,10 +35,11 @@
                 <string>one-hour-max-modification-date</string>
                 <string>must-revalidate</string>
                 <string>public-conversion-result-no-language</string>
+                <string>hateoas</string>
+                <string>hateoas-no-cache</string>
                 <string>public-conversion-result</string>
                 <string>unauthenticated no language</string>
                 <string>unauthenticated</string>
-                <string>hateoas</string>
                 <string>authenticated</string>
               </tuple>
             </value>
@@ -254,6 +269,111 @@
                       </object>
                     </value>
                 </item>
+                <item>
+                    <key> <string>hateoas-no-cache</string> </key>
+                    <value>
+                      <object>
+                        <klass> <reference id="2.1"/> </klass>
+                        <tuple/>
+                        <state>
+                          <dictionary>
+                            <item>
+                                <key> <string>_enable_304s</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_etag_func</string> </key>
+                                <value>
+                                  <persistent> <string encoding="base64">AAAAAAAAAAk=</string> </persistent>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_last_modified</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_max_age_secs</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_mtime_func</string> </key>
+                                <value>
+                                  <persistent> <string encoding="base64">AAAAAAAAAAo=</string> </persistent>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_must_revalidate</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_no_cache</string> </key>
+                                <value> <int>1</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_no_store</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_no_transform</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_policy_id</string> </key>
+                                <value> <string>hateoas-no-cache</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>_post_check</string> </key>
+                                <value>
+                                  <none/>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_pre_check</string> </key>
+                                <value>
+                                  <none/>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_predicate</string> </key>
+                                <value>
+                                  <persistent> <string encoding="base64">AAAAAAAAAAs=</string> </persistent>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_private</string> </key>
+                                <value> <int>1</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_proxy_revalidate</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_public</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_s_max_age_secs</string> </key>
+                                <value>
+                                  <none/>
+                                </value>
+                            </item>
+                            <item>
+                                <key> <string>_stale_if_error_secs</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_stale_while_revalidate_secs</string> </key>
+                                <value> <int>0</int> </value>
+                            </item>
+                            <item>
+                                <key> <string>_vary</string> </key>
+                                <value> <string></string> </value>
+                            </item>
+                          </dictionary>
+                        </state>
+                      </object>
+                    </value>
+                </item>
                 <item>
                     <key> <string>must-revalidate</string> </key>
                     <value>
@@ -269,7 +389,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAAk=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAAw=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -283,7 +403,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAAo=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAA0=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -321,7 +441,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAAs=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAA4=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -374,7 +494,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAAw=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAA8=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -388,7 +508,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAA0=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABA=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -426,7 +546,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAA4=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABE=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -479,7 +599,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAA8=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABI=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -493,7 +613,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABA=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABM=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -531,7 +651,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABE=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABQ=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -584,7 +704,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABI=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABU=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -598,7 +718,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABM=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABY=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -636,7 +756,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABQ=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABc=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -689,7 +809,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABU=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABg=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -703,7 +823,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABY=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABk=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -741,7 +861,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABc=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABo=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -794,7 +914,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABg=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABs=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -808,7 +928,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABk=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAABw=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -846,7 +966,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABo=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAB0=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -899,7 +1019,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABs=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAB4=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -913,7 +1033,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAABw=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAAB8=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -951,7 +1071,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAB0=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAACA=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -1004,7 +1124,7 @@
                             <item>
                                 <key> <string>_etag_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAB4=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAACE=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -1018,7 +1138,7 @@
                             <item>
                                 <key> <string>_mtime_func</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAAB8=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAACI=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -1056,7 +1176,7 @@
                             <item>
                                 <key> <string>_predicate</string> </key>
                                 <value>
-                                  <persistent> <string encoding="base64">AAAAAAAAACA=</string> </persistent>
+                                  <persistent> <string encoding="base64">AAAAAAAAACM=</string> </persistent>
                                 </value>
                             </item>
                             <item>
@@ -1199,7 +1319,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: getattr(object, \'getModificationDate\', object.modified)()</string> </value>
+            <value> <string>object/modified</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1212,7 +1332,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: (lambda x: x is not None and x.getCachingPolicy() == \'must-revalidate\')(object.getWebSectionValue())</string> </value>
+            <value> <string>python: (lambda x: x is not None and x.getCachingPolicy() =="hateoas")(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1238,7 +1358,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>object/modified</string> </value>
+            <value> <string>python: getattr(object, \'getModificationDate\', object.modified)()</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1251,7 +1371,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'no-cache\')(object.getWebSectionValue())</string> </value>
+            <value> <string>python: (lambda x: x is not None and x.getCachingPolicy() == \'must-revalidate\')(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1277,7 +1397,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: max(getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)(), DateTime().earliestTime())</string> </value>
+            <value> <string>object/modified</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1290,7 +1410,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'one-day-max-modification-date\')(object.getWebSectionValue())</string> </value>
+            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'no-cache\')(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1316,7 +1436,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: max(getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)(), DateTime().earliestTime()  + (DateTime().hour() /24.0))</string> </value>
+            <value> <string>python: max(getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)(), DateTime().earliestTime())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1329,7 +1449,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'one-hour-max-modification-date\')(object.getWebSectionValue())</string> </value>
+            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'one-day-max-modification-date\')(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1355,7 +1475,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: getattr(object, \'getModificationDate\', object.modified)()</string> </value>
+            <value> <string>python: max(getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)(), DateTime().earliestTime()  + (DateTime().hour() /24.0))</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1368,7 +1488,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: object.Base_isPublicConvertionResult() and (lambda x: x is not None and not (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
+            <value> <string>python: member is None and (lambda x: x is not None and x.getCachingPolicy() == \'one-hour-max-modification-date\')(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1407,7 +1527,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: object.Base_isPublicConvertionResult() and (lambda x: x is not None and (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
+            <value> <string>python: object.Base_isPublicConvertionResult() and (lambda x: x is not None and not (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1433,7 +1553,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)()</string> </value>
+            <value> <string>python: getattr(object, \'getModificationDate\', object.modified)()</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1446,7 +1566,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>python: member is None and (lambda x: x is not None and not (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
+            <value> <string>python: object.Base_isPublicConvertionResult() and (lambda x: x is not None and (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
         </item>
       </dictionary>
     </pickle>
@@ -1478,6 +1598,45 @@
     </pickle>
   </record>
   <record id="32" aka="AAAAAAAAACA=">
+    <pickle>
+      <global name="Expression" module="Products.CMFCore.Expression"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string>python: member is None and (lambda x: x is not None and not (len(x.getAvailableLanguageSet()) == 1 or x.getStaticLanguageSelection()))(object.getWebSectionValue())</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="33" aka="AAAAAAAAACE=">
+    <pickle>
+      <global name="Expression" module="Products.CMFCore.Expression"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="34" aka="AAAAAAAAACI=">
+    <pickle>
+      <global name="Expression" module="Products.CMFCore.Expression"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string>python: getattr(object, \'Base_getWebDocumentDrivenModificationDate\', object.modified)()</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="35" aka="AAAAAAAAACM=">
     <pickle>
       <global name="Expression" module="Products.CMFCore.Expression"/>
     </pickle>
-- 
2.30.9