changeset 4629:554e1d780e3b

fixed anon session detection, optimized trail code
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 07 Mar 2009 19:42:10 +0100
parents 3c6980b5e938
children 83483f4e26cb
files MoinMoin/auth/openidrp.py MoinMoin/user.py MoinMoin/web/session.py
diffstat 3 files changed, 14 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/auth/openidrp.py	Sat Mar 07 19:10:05 2009 +0100
+++ b/MoinMoin/auth/openidrp.py	Sat Mar 07 19:42:10 2009 +0100
@@ -254,7 +254,7 @@
         _ = request.getText
 
         # user entered something but the session can't be stored
-        if not request.session.is_stored:
+        if not request.cfg.cookie_lifetime[0]:
             return ContinueLogin(user_obj,
                                  _('Anonymous sessions need to be enabled for OpenID login.'))
 
--- a/MoinMoin/user.py	Sat Mar 07 19:10:05 2009 +0100
+++ b/MoinMoin/user.py	Sat Mar 07 19:42:10 2009 +0100
@@ -329,7 +329,6 @@
 
         # attrs not saved to profile
         self._request = request
-        self._trail = []
 
         # we got an already authenticated username:
         check_password = None
@@ -475,9 +474,6 @@
         if -24 <= self.tz_offset and self.tz_offset <= 24:
             self.tz_offset = self.tz_offset * 3600
 
-        # clear trail
-        self._trail = []
-
         if not self.disabled:
             self.valid = 1
 
@@ -877,7 +873,7 @@
     # Trail
 
     def _wantTrail(self):
-        return (not self.valid and self._request.session.is_stored  # anon session
+        return (not self.valid and self._request.cfg.cookie_lifetime[0]  # anon sessions enabled
                 or self.valid and (self.show_page_trail or self.remember_last_visit))  # logged-in session
 
     def addTrail(self, page):
@@ -886,9 +882,6 @@
         @param page: the page (object) to add to the trail
         """
         if self._wantTrail():
-            # load trail if not known
-            self.getTrail()
-
             pagename = page.page_name
             # Add only existing pages that the user may read
             if not (page.exists() and self._request.user.may.read(pagename)):
@@ -898,20 +891,18 @@
             if self._cfg.interwikiname:
                 pagename = self._interWikiName(pagename)
 
+            trail = self._request.session.get('trail', [])
+
             # Don't append tail to trail ;)
-            if self._trail and self._trail[-1] == pagename:
+            if trail and trail[-1] == pagename:
                 return
 
             # Append new page, limiting the length
-            self._trail = [p for p in self._trail if p != pagename]
-            self._trail = self._trail[-(self._cfg.trail_size-1):]
-            self._trail.append(pagename)
-            self.saveTrail()
-
-    def saveTrail(self):
-        """ Save trail into session """
-        if not self._request.session.is_new:
-            self._request.session['trail'] = self._trail
+            trail = [p for p in trail if p != pagename]
+            pagename_stripped = pagename.strip()
+            if pagename_stripped:
+                trail.append(pagename_stripped)
+            self._request.session['trail'] = trail[-(self._cfg.trail_size-1):]
 
     def getTrail(self):
         """ Return list of recently visited pages.
@@ -919,13 +910,11 @@
         @rtype: list
         @return: pages in trail
         """
-        if not self._trail and self._wantTrail():
+        if self._wantTrail():
             trail = self._request.session.get('trail', [])
-            trail = [t.strip() for t in trail]
-            trail = [t for t in trail if t]
-            self._trail = trail[-self._cfg.trail_size:]
-
-        return self._trail
+        else:
+            trail = []
+        return trail
 
     # -----------------------------------------------------------------
     # Other
--- a/MoinMoin/web/session.py	Sat Mar 07 19:10:05 2009 +0100
+++ b/MoinMoin/web/session.py	Sat Mar 07 19:42:10 2009 +0100
@@ -23,7 +23,6 @@
 class MoinSession(Session):
     """ Compatibility interface to Werkzeug-sessions for old Moin-code. """
     is_new = property(lambda s: s.new)
-    is_stored = property(lambda s: True)
 
 class SessionService(object):
     """