[Checkins] SVN: Products.PluggableAuthService/trunk/ DynamicGroupsPlugin.enumerateGroups: return an empty sequence for unknown ID.
Tres Seaver
tseaver at palladion.com
Thu Jul 1 18:05:35 EDT 2010
Log message for revision 114080:
DynamicGroupsPlugin.enumerateGroups: return an empty sequence for unknown ID.
Don't raise KeyError.
Fixes https://bugs.launchpad.net/zope-pas/+bug/585365
Changed:
U Products.PluggableAuthService/trunk/CHANGES.txt
U Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py
U Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py
-=-
Modified: Products.PluggableAuthService/trunk/CHANGES.txt
===================================================================
--- Products.PluggableAuthService/trunk/CHANGES.txt 2010-07-01 21:51:01 UTC (rev 114079)
+++ Products.PluggableAuthService/trunk/CHANGES.txt 2010-07-01 22:05:35 UTC (rev 114080)
@@ -4,10 +4,14 @@
1.7.1 (unreleased)
------------------
-- Raise new-style exceptions.
+- Updated ``DynamicGroupsPlugin.enumerateGroups`` to return an empty sequence
+ for an unknown group ID, rather than raising KeyError.
+ https://bugs.launchpad.net/zope-pas/+bug/585365
-- Avoid dependency on zope.app.testing.
+- Updated all code to raise new-style exceptions.
+- Removed dependency on ``zope.app.testing``.
+
- Cleaned out a number of old imports, we require Zope >= 2.12.
- Updated setDefaultRoles to use the addPermission API if available.
Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py 2010-07-01 21:51:01 UTC (rev 114079)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py 2010-07-01 22:05:35 UTC (rev 114080)
@@ -250,22 +250,25 @@
group_ids = self.listGroupIds()
group_filter = _DynamicGroupFilter( id, **kw )
+ known = self.listGroupIds()
for group_id in group_ids:
+ g_info = self.getGroupInfo(group_id, raise_keyerror=False)
+ if g_info is not None:
- url = '/%s/%s/manage_propertiesForm' % ( self.absolute_url( 1 )
- , group_id )
- info = {}
- info.update( self.getGroupInfo( group_id ) )
+ url = '/%s/%s/manage_propertiesForm' % (
+ self.absolute_url(1), group_id)
+ info = {}
+ info.update( self.getGroupInfo( group_id ) )
- info[ 'pluginid' ] = plugin_id
- info[ 'properties_url' ] = url
- info[ 'members_url' ] = url
+ info[ 'pluginid' ] = plugin_id
+ info[ 'properties_url' ] = url
+ info[ 'members_url' ] = url
- info[ 'id' ] = '%s%s' % (self.prefix, info['id'])
+ info[ 'id' ] = '%s%s' % (self.prefix, info['id'])
- if not group_filter or group_filter( info ):
- if info[ 'active' ]:
- group_info.append( info )
+ if not group_filter or group_filter( info ):
+ if info[ 'active' ]:
+ group_info.append( info )
# Put the computed value into the cache
self.ZCacheable_set(group_info, view_name=view_name, keywords=keywords)
@@ -283,12 +286,13 @@
return self.objectIds( DynamicGroupDefinition.meta_type )
security.declareProtected( ManageGroups, 'getGroupInfo' )
- def getGroupInfo( self, group_id ):
+ def getGroupInfo( self, group_id, raise_keyerror=True ):
""" Return a mappings describing one dynamic group we manage.
- o Raise KeyError if we don't have an existing group definition
- for 'group_ id'.
+ o If 'raise_keyerror' is True, raise KeyError if we don't have an
+ existing group definition for 'group_ id'. Otherwise, return
+ None.
o Keys include:
@@ -304,10 +308,16 @@
try:
original = self._getOb( group_id[len(self.prefix):] )
except AttributeError:
- raise KeyError, group_id
+ if raise_keyerror:
+ raise KeyError, group_id
+ else:
+ return None
if not isinstance( original, DynamicGroupDefinition ):
- raise KeyError, group_id
+ if raise_keyerror:
+ raise KeyError, group_id
+ else:
+ return None
info = {}
Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py 2010-07-01 21:51:01 UTC (rev 114079)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py 2010-07-01 22:05:35 UTC (rev 114080)
@@ -302,6 +302,23 @@
self.assertEqual( info[ 'properties_url' ], URL )
self.assertEqual( info[ 'members_url' ], URL )
+ def test_enumerateGroups_exact_miss( self ):
+ # See https://bugs.launchpad.net/zope-pas/+bug/585365
+
+ from Products.PluggableAuthService.tests.test_PluggableAuthService \
+ import FauxRoot
+
+ root = FauxRoot()
+ dpg = self._makeOne( 'enumerating' ).__of__( root )
+
+ dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
+ dpg.addGroup( 'noone', 'python:False', active=True )
+ dpg.addGroup( 'hohum', 'nothing', active=True )
+
+ info_list = dpg.enumerateGroups( id='nonesuch', exact_match=True )
+
+ self.assertEqual( len( info_list ), 0 )
+
def test_enumerateGroups_skip_inactive( self ):
from Products.PluggableAuthService.tests.test_PluggableAuthService \
More information about the checkins
mailing list