Back to index

plone3  3.1.7
Classes | Functions | Variables
GenericSetup.rolemap Namespace Reference

Classes

class  RolemapExportConfigurator
class  RolemapImportConfigurator

Functions

def importRolemap
def exportRolemap

Variables

string _FILENAME = 'rolemap.xml'

Function Documentation

Export roles / permission map as an XML file

o 'context' must implement IExportContext.

o Register via Python:

  registry = site.setup_tool.export_steps
  registry.registerStep( 'exportRolemap'
                       , Products.GenericSetup.rolemap.exportRolemap
                       , 'Role / Permission export'
                       , 'Export additional roles, and '
                         'role / permission map '
                       )

o Register via XML:

  <export-script id="exportRolemap"
                 version="20040518-01"
                 handler="Products.GenericSetup.rolemap.exportRolemap"
                 title="Role / Permission export"
  >Export additional roles, and role / permission map.</export-script>

Definition at line 110 of file rolemap.py.

00110 
00111 def exportRolemap( context ):
00112 
00113     """ Export roles / permission map as an XML file
00114 
00115     o 'context' must implement IExportContext.
00116 
00117     o Register via Python:
00118 
00119       registry = site.setup_tool.export_steps
00120       registry.registerStep( 'exportRolemap'
00121                            , Products.GenericSetup.rolemap.exportRolemap
00122                            , 'Role / Permission export'
00123                            , 'Export additional roles, and '
00124                              'role / permission map '
00125                            )
00126 
00127     o Register via XML:
00128 
00129       <export-script id="exportRolemap"
00130                      version="20040518-01"
00131                      handler="Products.GenericSetup.rolemap.exportRolemap"
00132                      title="Role / Permission export"
00133       >Export additional roles, and role / permission map.</export-script>
00134 
00135     """
00136     site = context.getSite()
00137     logger = context.getLogger('rolemap')
00138 
00139     rc = RolemapExportConfigurator(site).__of__(site)
00140     text = rc.generateXML()
00141 
00142     context.writeDataFile( _FILENAME, text, 'text/xml' )
00143 
00144     logger.info('Role / permission map exported.')
00145 

Here is the caller graph for this function:

Import roles / permission map from an XML file.

o 'context' must implement IImportContext.

o Register via Python:

  registry = site.setup_tool.setup_steps
  registry.registerStep( 'importRolemap'
                       , '20040518-01'
                       , Products.GenericSetup.rolemap.importRolemap
                       , ()
                       , 'Role / Permission import'
                       , 'Import additional roles, and map '
                       'roles to permissions'
                       )

o Register via XML:

  <setup-step id="importRolemap"
              version="20040518-01"
              handler="Products.GenericSetup.rolemap.importRolemap"
              title="Role / Permission import"
  >Import additional roles, and map roles to permissions.</setup-step>

Definition at line 35 of file rolemap.py.

00035 
00036 def importRolemap( context ):
00037 
00038     """ Import roles / permission map from an XML file.
00039 
00040     o 'context' must implement IImportContext.
00041 
00042     o Register via Python:
00043 
00044       registry = site.setup_tool.setup_steps
00045       registry.registerStep( 'importRolemap'
00046                            , '20040518-01'
00047                            , Products.GenericSetup.rolemap.importRolemap
00048                            , ()
00049                            , 'Role / Permission import'
00050                            , 'Import additional roles, and map '
00051                            'roles to permissions'
00052                            )
00053 
00054     o Register via XML:
00055 
00056       <setup-step id="importRolemap"
00057                   version="20040518-01"
00058                   handler="Products.GenericSetup.rolemap.importRolemap"
00059                   title="Role / Permission import"
00060       >Import additional roles, and map roles to permissions.</setup-step>
00061 
00062     """
00063     site = context.getSite()
00064     encoding = context.getEncoding()
00065     logger = context.getLogger('rolemap')
00066 
00067     if context.shouldPurge():
00068 
00069         items = site.__dict__.items()
00070 
00071         for k, v in items: # XXX: WAAA
00072 
00073             if k == '__ac_roles__':
00074                 delattr( site, k )
00075 
00076             if k.startswith( '_' ) and k.endswith( '_Permission' ):
00077                 delattr( site, k )
00078 
00079     text = context.readDataFile( _FILENAME )
00080 
00081     if text is not None:
00082 
00083         rc = RolemapImportConfigurator(site, encoding)
00084         rolemap_info = rc.parseXML( text )
00085 
00086         immediate_roles = list( getattr(site, '__ac_roles__', []) )
00087         already = {}
00088 
00089         for role in site.valid_roles():
00090             already[ role ] = 1
00091 
00092         for role in rolemap_info[ 'roles' ]:
00093 
00094             if already.get( role ) is None:
00095                 immediate_roles.append( role )
00096                 already[ role ] = 1
00097 
00098         immediate_roles.sort()
00099         site.__ac_roles__ = tuple( immediate_roles )
00100 
00101         for permission in rolemap_info[ 'permissions' ]:
00102 
00103             site.manage_permission( permission[ 'name' ]
00104                                   , permission.get('roles', [])
00105                                   , permission[ 'acquire' ]
00106                                   )
00107 
00108     logger.info('Role / permission map imported.')
00109 

Here is the caller graph for this function:


Variable Documentation

string GenericSetup.rolemap._FILENAME = 'rolemap.xml'

Definition at line 33 of file rolemap.py.