[CMF-checkins] CVS: CMF/CMFSetup - rolemap.py:1.1 __init__.py:1.2
Tres Seaver
tseaver at zope.com
Tue May 18 15:55:26 EDT 2004
Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv26621
Modified Files:
__init__.py
Added Files:
rolemap.py
Log Message:
- Add exporter for role-permission map, and tests.
=== Added File CMF/CMFSetup/rolemap.py ===
""" CMFSetup: Role-permission export / import
$Id: rolemap.py,v 1.1 2004/05/18 19:54:52 tseaver Exp $
"""
from AccessControl import ClassSecurityInfo
from AccessControl.Permission import Permission
from Acquisition import Implicit
from Globals import InitializeClass
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from permissions import ManagePortal
from utils import _xmldir
#
# Export
#
class RolemapExporter( Implicit ):
""" Synthesize XML description of sitewide role-permission settings.
"""
security = ClassSecurityInfo()
security.setDefaultAccess( 'allow' )
def __init__( self, site ):
self.site = site
_rolemap = PageTemplateFile( 'rmeExport.xml'
, _xmldir
, __name__='_rolemap'
)
security.declareProtected( ManagePortal, 'listRoles' )
def listRoles( self ):
""" List the valid role IDs for our site.
"""
return self.site.valid_roles()
security.declareProtected( ManagePortal, 'listPermissions' )
def listPermissions( self ):
""" List permissions for export.
o Returns a sqeuence of mappings describing locally-modified
permission / role settings. Keys include:
'permission' -- the name of the permission
'acquire' -- a flag indicating whether to acquire roles from the
site's container
'roles' -- the list of roles which have the permission.
o Do not include permissions which both acquire and which define
no local changes to the acquired policy.
"""
permissions = []
valid_roles = self.listRoles()
for perm in self.site.ac_inherited_permissions( 1 ):
name = perm[ 0 ]
p = Permission( name, perm[ 1 ], self.site )
roles = p.getRoles( default=[] )
acquire = isinstance( roles, list ) # tuple means don't acquire
roles = [ r for r in roles if r in valid_roles ]
if roles or not acquire:
permissions.append( { 'name' : name
, 'acquire' : acquire
, 'roles' : roles
} )
return permissions
security.declareProtected( ManagePortal, 'generateXML' )
def generateXML( self ):
""" Pseudo API.
"""
return self._rolemap()
InitializeClass( RolemapExporter )
def exportRolemap(site):
""" Export roles / permission map as an XML file
"""
rpe = RolemapExporter( site ).__of__( site )
return rpe.generateXML(), 'text/xml', 'rolemap.xml'
=== CMF/CMFSetup/__init__.py 1.1 => 1.2 ===
--- CMF/CMFSetup/__init__.py:1.1 Tue May 11 21:35:47 2004
+++ CMF/CMFSetup/__init__.py Tue May 18 15:54:52 2004
@@ -1,4 +1,4 @@
-""" CMFConfiguration product initialization
+""" CMFSetup product initialization
$Id$
"""
More information about the CMF-checkins
mailing list