Back to index

plone3  3.1.7
stripGRUFLocalRolePrefix.py
Go to the documentation of this file.
00001 # script to strip the group_ prefix from all local roles 
00002 
00003 from Acquisition import aq_base 
00004 
00005 def do(self): 
00006     """Do it!""" 
00007     print '---' 
00008     removePrefix(self) 
00009     # Reindex security settings recursively
00010     self.reindexObjectSecurity()
00011     print '---' 
00012     return 'Done!' 
00013      
00014 def removePrefix(folder): 
00015     """Recursive function""" 
00016     for id in folder.objectIds(): 
00017         obj = folder._getOb(id) 
00018         local_roles = getattr(aq_base(obj), '__ac_local_roles__', None) 
00019 
00020         if local_roles is not None: 
00021             needs_updating = [(r, local_roles[r]) for r in local_roles \
00022                                                    if r.startswith('group_')] 
00023             old = local_roles 
00024             for name, roles in needs_updating: 
00025                 new_name = name[6:] 
00026                 del local_roles[name] 
00027                 local_roles[new_name] = roles 
00028 
00029             if needs_updating: 
00030                 print 'Updating: ', obj.getPhysicalPath() 
00031                 print 'Old: ', old 
00032                 obj.__ac_local_roles__ = local_roles 
00033                 print 'New: ', local_roles 
00034 
00035         if obj.objectIds(): 
00036             removePrefix(obj)