From: Cris E. <svn...@pl...> - 2008-08-13 19:10:41
|
Author: cewing Date: Wed Aug 13 19:10:35 2008 New Revision: 69837 Modified: Products.membrane/trunk/Products/membrane/plugins/groupmanager.py Products.membrane/trunk/Products/membrane/tests/testMembraneGroupManager.py Log: a bug in groupmanager.enumerateGroups caused searches for groups by ID with exact_match set to True to return groups with ids that were similar, but not identiccal to the one searched for. This changeset includes a test exposing this problem, and a fix to the groupmanager.enumerateGroups code that repairs the problem. This issue was reported to the membrane issue tracker (http://plone.org/products/membrane/issues/17/) Modified: Products.membrane/trunk/Products/membrane/plugins/groupmanager.py ============================================================================== --- Products.membrane/trunk/Products/membrane/plugins/groupmanager.py (original) +++ Products.membrane/trunk/Products/membrane/plugins/groupmanager.py Wed Aug 13 19:10:35 2008 @@ -108,8 +108,11 @@ query = {} if id: - query['getGroupId'] = exact_match and id or \ - ['%s*' % i for i in id] + if exact_match: + query['exact_getGroupId'] = id + else: + query['getGroupId'] = ['%s*' % i for i in id] + elif title: query['Title'] = exact_match and title or \ ['%s*' % t for t in title] Modified: Products.membrane/trunk/Products/membrane/tests/testMembraneGroupManager.py ============================================================================== --- Products.membrane/trunk/Products/membrane/tests/testMembraneGroupManager.py (original) +++ Products.membrane/trunk/Products/membrane/tests/testMembraneGroupManager.py Wed Aug 13 19:10:35 2008 @@ -166,6 +166,24 @@ exact_match=True, max_results=1)), 1) self.failUnlessEqual(len(enumgrps(id=self.group.getGroupName(), exact_match=True, max_results=0)), 0) + + def testEnumerateGroupsWithSimilarIds(self): + """ ensure that enumerating groups while exact_match==True returns only + exact matches for a given id + """ + # add a new group with a similar id + self.newgroup = _createObjectByType('TestGroup', self.portal, 'testgroup-2') + self.newgroup.setTitle('New Test group') + self.newgroup.setDescription('A test group') + self.newgroup.reindexObject() + + enumgrps = self.portal.pmm.enumerateGroups + # only an exact match should be found when exact_match==True + self.failUnlessEqual(len(enumgrps(id=self.group.getGroupName(), + exact_match=True)), 1) + self.failUnlessEqual(len(enumgrps(id=self.group.getGroupName(), + exact_match=False)), 2) + class TestMembraneGroupIntrospection( base.MembraneTestCase |