changeset 1854:2d54d55bc351

reuse page object we already have for ACL checks
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 08 Mar 2007 14:13:13 +0100
parents 3ddf2193a16e
children 472566340cd8
files MoinMoin/security/__init__.py
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/security/__init__.py	Fri Mar 02 22:45:12 2007 +0100
+++ b/MoinMoin/security/__init__.py	Thu Mar 08 14:13:13 2007 +0100
@@ -22,6 +22,14 @@
 ### Basic Permissions Interface -- most features enabled by default
 #############################################################################
 
+def _check(request, pagename, user, right):
+    if pagename == request.page.page_name:
+        p = request.page # reuse is good
+    else:
+        p = Page(request, pagename)
+    acl = p.getACL(request) # this will be fast in a reused page obj
+    return acl.may(request, user, right)
+
 
 class Permissions:
     """ Basic interface for user permissions and system policy.
@@ -50,14 +58,7 @@
         """
         request = self.request
         if attr in request.cfg.acl_rights_valid:
-            def check(request, pagename, user, right):
-                if pagename == request.page.page_name:
-                    p = request.page # reuse is good
-                else:
-                    p = Page(request, pagename)
-                acl = p.getACL(request) # this will be fast in a reused page obj
-                return acl.may(request, user, right)
-            return lambda pagename: check(self.request, pagename, self.name, attr)
+            return lambda pagename: _check(self.request, pagename, self.name, attr)
             ##return lambda pagename, Page=Page, request=request, attr=attr: Page(request, pagename).getACL(request).may(request, self.name, attr)
         else:
             raise AttributeError, attr