changeset 4773:c3e904a9c00b

Groups 2009: BackendManager gets request object in __init__
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sat, 30 May 2009 08:22:09 +0200
parents 8dcf18d0ae41
children fb0cce9e8621
files MoinMoin/_tests/wikiconfig.py MoinMoin/groups/__init__.py MoinMoin/groups/_tests/test_backend_manager.py MoinMoin/groups/_tests/test_group_manager.py MoinMoin/groups/_tests/test_group_manager_acl.py MoinMoin/security/__init__.py
diffstat 6 files changed, 35 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/wikiconfig.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/_tests/wikiconfig.py	Sat May 30 08:22:09 2009 +0200
@@ -25,7 +25,7 @@
     data_dir = os.path.join(_base_dir, "data")
     data_underlay_dir = os.path.join(_base_dir, "underlay")
 
-    group_manager = GroupManager([])
+    group_manager = lambda self, request: GroupManager([])
 
     #show_hosts = 1
 
@@ -33,4 +33,3 @@
 
     # used to check if it is really a wiki we may modify
     is_test_wiki = True
-
--- a/MoinMoin/groups/__init__.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/groups/__init__.py	Sat May 30 08:22:09 2009 +0200
@@ -16,12 +16,14 @@
     group name. It provides access to groups of specific backend.
     """
 
-    def __init__(self, backend, mapper_to_backend=lambda x: x, mapper_from_backend=lambda x: x):
+    def __init__(self, request, backend, mapper_to_backend=lambda x: x, mapper_from_backend=lambda x: x):
         """
         Creates backend manager object.
 
         XXX Decorators can be used for group name mapping.
 
+        @param request: request object.
+
         @type backend: group backend object.
         @param backend: the backend which provides access to the group
         definitions.
--- a/MoinMoin/groups/_tests/test_backend_manager.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/groups/_tests/test_backend_manager.py	Sat May 30 08:22:09 2009 +0200
@@ -26,7 +26,8 @@
                   u'EditorGroup': self.editor_group,
                   u'FruitGroup': self.fruit_group}
 
-        self.group_backend = BackendManager(backend=groups)
+        self.group_backend = BackendManager(request=self.request,
+                                            backend=groups)
 
     def test_getitem(self):
         """
@@ -91,11 +92,11 @@
         # Add "Group" postfix for every group name received from a backend
         mapper_from_backend = lambda group_name: "%sGroup" % group_name
 
-        self.group_backend = BackendManager(backend=groups,
+        self.group_backend = BackendManager(request=self.request,
+                                            backend=groups,
                                             mapper_to_backend=mapper_to_backend,
                                             mapper_from_backend=mapper_from_backend)
 
-
     def test_getitem(self):
         admin_group = self.group_backend[u'AdminGroup']
         assert self.admin_group == admin_group
--- a/MoinMoin/groups/_tests/test_group_manager.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager.py	Sat May 30 08:22:09 2009 +0200
@@ -4,6 +4,7 @@
 MoinMoin.groups.GroupManager test
 
 @copyright: 2009 MoinMoin:DmitrijsMilajevs
+            2008 MoinMoin: MelitaMihaljevic
 @license: GPL, see COPYING for details
 """
 
@@ -11,20 +12,23 @@
 
 from MoinMoin.groups import BackendManager, GroupManager
 
-
 class TestGroupManagerAPI(object):
     """
     Performs test of the API of GroupManager.
     """
 
-    def setup_method(self, method):
+    from MoinMoin._tests import wikiconfig
+    class Config(wikiconfig.Config):
+        pass
+
+    def setup_class(self):
         self.admin_group = frozenset([u'Admin', u'JohnDoe'])
         self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
         self.fruit_group = frozenset([u'Apple', u'Banana', u'Cherry'])
 
-        first_backend = BackendManager({u'AdminGroup': self.admin_group,
-                                        u'EditorGroup': self.editor_group,
-                                        u'FruitGroup': self.fruit_group})
+        first_backend_groups = {u'AdminGroup': self.admin_group,
+                                u'EditorGroup': self.editor_group,
+                                u'FruitGroup': self.fruit_group}
 
         self.user_group = frozenset([u'JohnDoe', u'Bob', u'Joe'])
         self.city_group = frozenset([u'Bolzano', u'Riga', u'London'])
@@ -32,15 +36,18 @@
         # and added himself to AdminGroup
         self.second_admin_group = frozenset([u'TheHacker'])
 
-        second_backend = BackendManager({u'UserGroup': self.user_group,
-                                         u'CityGroup': self.city_group,
-                                         # Here group name clash occurs.
-                                         # AdminGroup is defined in both
-                                         # first_backend and second_backend.
-                                         u'AdminGroup': self.second_admin_group})
+        second_backend_groups = {u'UserGroup': self.user_group,
+                                 u'CityGroup': self.city_group,
+                                 # Here group name clash occurs.
+                                 # AdminGroup is defined in both
+                                 # first_backend and second_backend.
+                                 u'AdminGroup': self.second_admin_group}
 
-        self.group_manager = GroupManager(backends = [first_backend,
-                                                      second_backend])
+        self.Config.group_manager = lambda self, request: GroupManager(backends=[BackendManager(request, first_backend_groups),
+                                                                                 BackendManager(request, second_backend_groups)])
+
+    def setup_method(self, method):
+        self.group_manager = self.request.cfg.group_manager(self.request)
 
     def test_getitem(self):
         """
--- a/MoinMoin/groups/_tests/test_group_manager_acl.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager_acl.py	Sat May 30 08:22:09 2009 +0200
@@ -23,9 +23,11 @@
     def setup_class(self):
         groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
                   u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}
-        group_manager = GroupManager([BackendManager(groups)])
 
-        self.Config.group_manager = group_manager
+        self.Config.group_manager = lambda self, request: GroupManager(backends=[BackendManager(request=request, backend=groups)])
+
+    def setup_method(self, method):
+        self.group_manager = self.request.cfg.group_manager(self.request)
 
     def testConfigBackendAcl(self):
         """
@@ -54,7 +56,8 @@
                  }
 
         # create config group manager backend object
-        group_manager_backend = GroupManager(BackendManager([groups]))
+        group_manager_backend = GroupManager(BackendManager(request=self.request,
+                                                            backend=[groups]))
 
         # check that a group named 'A' is available via the config backend
         assert 'A' in group_manager_backend
--- a/MoinMoin/security/__init__.py	Sat May 30 08:06:59 2009 +0200
+++ b/MoinMoin/security/__init__.py	Sat May 30 08:22:09 2009 +0200
@@ -308,7 +308,7 @@
         else: # we have a #acl on the page (self.acl can be [] if #acl is empty!)
             acl = self.acl
 
-        group_manager = request.cfg.group_manager
+        group_manager = request.cfg.group_manager(request)
 
         allowed = None
         for entry, rightsdict in acl:
@@ -452,4 +452,3 @@
     pi, dummy = wikiutil.get_processing_instructions(text)
     acl_lines = [args for verb, args in pi if verb == 'acl']
     return AccessControlList(request.cfg, acl_lines)
-