From 8b6b20a5f635803871eb239da8e1e2b02214ef38 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 26 Apr 2011 08:32:15 +0000
Subject: [PATCH] Use tool-level preference accessor.

This simplifies code a lot, with added bonus of enabling use of highest-precedence System Preference.
Also, user_name is not used in the local cached function, so move it to cache key instead.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45678 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../ERP5Site_getMaxUserInactivityDuration.xml | 20 ++++---------------
 bt5/erp5_auto_logout/bt/revision              |  2 +-
 2 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/bt5/erp5_auto_logout/SkinTemplateItem/portal_skins/erp5_auto_logout/ERP5Site_getMaxUserInactivityDuration.xml b/bt5/erp5_auto_logout/SkinTemplateItem/portal_skins/erp5_auto_logout/ERP5Site_getMaxUserInactivityDuration.xml
index 5501deb394..65d91a7e6c 100644
--- a/bt5/erp5_auto_logout/SkinTemplateItem/portal_skins/erp5_auto_logout/ERP5Site_getMaxUserInactivityDuration.xml
+++ b/bt5/erp5_auto_logout/SkinTemplateItem/portal_skins/erp5_auto_logout/ERP5Site_getMaxUserInactivityDuration.xml
@@ -51,28 +51,16 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>""" Get (in seconds) authentication expire interval for an user. """\n
-from zExceptions import Unauthorized\n
 from Products.ERP5Type.Cache import CachingMethod\n
 \n
-def getMaxUserInactivityDuration(user_name=None):\n
-  expire_interval = None\n
-  portal_preferences = context.portal_preferences\n
-  try:\n
-    active_preference = portal_preferences.getActivePreference()\n
-  except Unauthorized:\n
-    # when logging for first time through login_form user is still anonymous \n
-    # and so getActivePreference is not accessible. Try to get default preference\n
-    # for an ERP5 site \n
-    active_preference = getattr(portal_preferences, \'default_site_preference\', None)\n
-  if active_preference  is not None:\n
-    expire_interval = active_preference.getPreferredMaxUserInactivityDuration()\n
-  return expire_interval\n
+def getMaxUserInactivityDuration():\n
+  return context.portal_preferences.getPreferredMaxUserInactivityDuration()\n
 \n
 getMaxUserInactivityDuration = CachingMethod( \\\n
                                  getMaxUserInactivityDuration, \\\n
-                                 "ERP5Site_getMaxUserInactivityDuration", \\\n
+                                 "ERP5Site_getMaxUserInactivityDuration_%s" % (user_name, ), \\\n
                                  cache_factory=\'erp5_ui_medium\')\n
-return getMaxUserInactivityDuration(user_name)\n
+return getMaxUserInactivityDuration()\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_auto_logout/bt/revision b/bt5/erp5_auto_logout/bt/revision
index f11c82a4cb..9a037142aa 100644
--- a/bt5/erp5_auto_logout/bt/revision
+++ b/bt5/erp5_auto_logout/bt/revision
@@ -1 +1 @@
-9
\ No newline at end of file
+10
\ No newline at end of file
-- 
2.30.9