changeset 4819:05a605c107ed

Groups2009: wiki_groups Group class was renamed to WikiGroup. userform.admin refactored to use new groups code. Basic test for it is written.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Thu, 25 Jun 2009 12:42:55 +0200
parents 66b7c4fe0265
children 17e9325712b3
files MoinMoin/groups/backends/wiki_groups.py MoinMoin/userform/_tests/test_admin.py MoinMoin/userform/admin.py
diffstat 3 files changed, 68 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/backends/wiki_groups.py	Wed Jun 24 20:03:29 2009 +0200
+++ b/MoinMoin/groups/backends/wiki_groups.py	Thu Jun 25 12:42:55 2009 +0200
@@ -20,7 +20,7 @@
 from MoinMoin.groups.backends import BaseGroup, BaseBackend, GroupDoesNotExistError
 
 
-class Group(BaseGroup):
+class WikiGroup(BaseGroup):
 
     def _load_group(self):
         request = self.request
@@ -42,7 +42,7 @@
                     raise caching.CacheError
             except caching.CacheError:
                 # either cache does not exist, is erroneous or not uptodate: recreate it
-                members, member_groups = super(Group, self)._load_group()
+                members, member_groups = super(WikiGroup, self)._load_group()
                 cache.update((members, member_groups))
                 return members, member_groups
         else:
@@ -58,7 +58,7 @@
         return iter(self.request.rootpage.getPageList(user='', filter=self.page_group_regex.search))
 
     def __getitem__(self, group_name):
-        return Group(request=self.request, name=group_name, backend=self)
+        return WikiGroup(request=self.request, name=group_name, backend=self)
 
     # * Member - ignore all but first level list items, strip
     # whitespace, strip free links markup. This is used for parsing
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/userform/_tests/test_admin.py	Thu Jun 25 12:42:55 2009 +0200
@@ -0,0 +1,49 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.userform.admin Tests
+
+    @copyright: 2009 MoinMoin:DmitrijsMilajevs
+    @license: GNU GPL, see COPYING for details.
+"""
+
+
+from MoinMoin.userform.admin import do_user_browser
+from MoinMoin.groups import ConfigGroups
+from MoinMoin.user import User
+from MoinMoin.Page import Page
+from MoinMoin._tests import nuke_user, become_superuser, wikiconfig
+
+class TestAdmin:
+
+    class Config(wikiconfig.Config):
+
+        def group_manager_init(self, request):
+            groups = {'OneGroup': ['TestUser, OtherUser'],
+                      'OtherGroup': ['TestUser']}
+            return ConfigGroups(request, groups)
+
+    def setup_class(self):
+        request = self.request
+        user_name = 'TestUser'
+        self.user_name = user_name
+
+        become_superuser(request)
+
+        assert not User(request, name=user_name).exists()
+        user = User(request, name=user_name, password=user_name).save()
+
+    def teardown_class(self):
+        nuke_user(self.request, self.user_name)
+
+    def setup_method(self, method):
+        self.request.page = Page(self.request, 'SystemAdmin')
+
+    def test_do_user_browser(self):
+        request = self.request
+
+        browser = do_user_browser(request)
+        assert browser
+
+
+coverage_modules = ['MoinMoin.userform.admin']
+
--- a/MoinMoin/userform/admin.py	Wed Jun 24 20:03:29 2009 +0200
+++ b/MoinMoin/userform/admin.py	Thu Jun 25 12:42:55 2009 +0200
@@ -3,18 +3,24 @@
     MoinMoin - User account administration
 
     @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
-                2003-2007 MoinMoin:ThomasWaldmann
-                2007-2008 MoinMoin:ReimarBauer
+                2003-2007 MoinMoin:ThomasWaldmann,
+                2007-2008 MoinMoin:ReimarBauer,
+                2009 MoinMoin:DmitrijsMilajevs
     @license: GNU GPL, see COPYING for details.
 """
+
+
 from MoinMoin import user, wikiutil
 from MoinMoin.util.dataset import TupleDataset, Column
 from MoinMoin.Page import Page
 from MoinMoin.widget import html
+from MoinMoin.groups.backends.wiki_groups import WikiGroup
+
 
 def do_user_browser(request):
     """ Browser for SystemAdmin macro. """
     _ = request.getText
+    groups = request.groups
 
     data = TupleDataset()
     data.columns = [
@@ -25,16 +31,18 @@
         Column('action', label=_('Action')),
     ]
 
-    isgroup = request.cfg.cache.page_group_regexact.search
-    groupnames = request.rootpage.getPageList(user='', filter=isgroup)
-
     # Iterate over users
     for uid in user.getUserList(request):
         account = user.User(request, uid)
 
-        grouppage_links = ', '.join([Page(request, groupname).link_to(request)
-                                     for groupname in groupnames
-                                     if request.dicts.has_member(groupname, account.name)])
+        account_groups = set(groups.groups_with_member(account.name))
+        wiki_groups = set([group for group in account_groups if isinstance(groups[group], WikiGroup)])
+        other_groups = list(account_groups - wiki_groups)
+
+        # First show groups that are defined in wikipages linking to it
+        # after show groups from other backends.
+        grouppage_links = ', '.join([Page(request, group_name).link_to(request) for group_name in wiki_groups] +
+                                    other_groups)
 
         userhomepage = Page(request, account.name)
         if userhomepage.exists():