[Zope] How do I replace the top level acl_users folder.

Brian Lloyd Brian@digicool.com
Thu, 8 Apr 1999 10:14:32 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------ =_NextPart_000_01BE81CA.22BAE340
Content-Type: text/plain

> >I am trying to use the UserDB package for authroization via 
> ODBC, however
> >the management screen won't let me delete the top level 
> acl_users folder.
> You can't!
> 
> I had the same problem. What I had to do is:
> - create the Roles in the toplevel folder,
> - create the users database connection in the top level folder
> - create a UserDB in *all* subfolders of the top level 
> folder, that use
> the toplevel database.
> - and put only anonymous stuff in the top level folder.
> 
> If someone has a better approach, I am interested.

Ack. This is something we need to fix somehow. The problem is that 
if you get rid of the top-level userfolder, there is nothing to
perform authentication/authorization and the site is effectively
inaccessible :(

I have come up with a fix for this that will appear in 1.11.0. 
You will now be able to delete the top-level user folder in 
order to replace it. Note, however, that during the time that
you have no top-level userfolder, the mgmt interface for the
top-level folder will be accessible *only* to the superuser.

The fix involves only two files in lib/python/OFS/: 
Application.py and ObjectManager.py. I have attached
new versions of these files that you can drop into your
1.10.2 installation if you like. After replacing the
files, restart Zope and you should be able to replace
your top-level userfolder with a userdb or other
userfolder-like object.

Let me know if you have any problems!


Brian Lloyd        brian@digicool.com
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com 


------ =_NextPart_000_01BE81CA.22BAE340
Content-Type: application/octet-stream;
	name="Application.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Application.py"

########################################################################=
######=0A=
# =0A=
# Zope Public License (ZPL) Version 0.9.7=0A=
# ---------------------------------------=0A=
# =0A=
# Copyright (c) Digital Creations.  All rights reserved.=0A=
# =0A=
# This license has been certified as Open Source(tm).=0A=
# =0A=
# Redistribution and use in source and binary forms, with or without=0A=
# modification, are permitted provided that the following conditions =
are=0A=
# met:=0A=
# =0A=
# 1. Redistributions in source code must retain the above copyright=0A=
#    notice, this list of conditions, and the following disclaimer.=0A=
# =0A=
# 2. Redistributions in binary form must reproduce the above =
copyright=0A=
#    notice, this list of conditions, and the following disclaimer =
in=0A=
#    the documentation and/or other materials provided with the=0A=
#    distribution.=0A=
# =0A=
# 3. Digital Creations requests that attribution be given to Zope=0A=
#    in any manner possible. Zope includes a "Powered by Zope"=0A=
#    button that is installed by default. While it is not a license=0A=
#    violation to remove this button, it is requested that the=0A=
#    attribution remain. A significant investment has been put=0A=
#    into Zope, and this effort will continue if the Zope community=0A=
#    continues to grow. This is one way to assure that growth.=0A=
# =0A=
# 4. All advertising materials and documentation mentioning=0A=
#    features derived from or use of this software must display=0A=
#    the following acknowledgement:=0A=
# =0A=
#      "This product includes software developed by Digital =
Creations=0A=
#      for use in the Z Object Publishing Environment=0A=
#      (http://www.zope.org/)."=0A=
# =0A=
#    In the event that the product being advertised includes an=0A=
#    intact Zope distribution (with copyright and license included)=0A=
#    then this clause is waived.=0A=
# =0A=
# 5. Names associated with Zope or Digital Creations must not be used =
to=0A=
#    endorse or promote products derived from this software without=0A=
#    prior written permission from Digital Creations.=0A=
# =0A=
# 6. Modified redistributions of any form whatsoever must retain=0A=
#    the following acknowledgment:=0A=
# =0A=
#      "This product includes software developed by Digital =
Creations=0A=
#      for use in the Z Object Publishing Environment=0A=
#      (http://www.zope.org/)."=0A=
# =0A=
#    Intact (re-)distributions of any official Zope release do not=0A=
#    require an external acknowledgement.=0A=
# =0A=
# 7. Modifications are encouraged but must be packaged separately as=0A=
#    patches to official Zope releases.  Distributions that do not=0A=
#    clearly separate the patches from the original work must be =
clearly=0A=
#    labeled as unofficial distributions.  Modifications which do =
not=0A=
#    carry the name Zope may be packaged in any form, as long as =
they=0A=
#    conform to all of the clauses above.=0A=
# =0A=
# =0A=
# Disclaimer=0A=
# =0A=
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY=0A=
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, =
THE=0A=
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A =
PARTICULAR=0A=
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR =
ITS=0A=
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A=
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT=0A=
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=0A=
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED =
AND=0A=
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT =
LIABILITY,=0A=
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY =
OUT=0A=
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY =
OF=0A=
#   SUCH DAMAGE.=0A=
# =0A=
# =0A=
# This software consists of contributions made by Digital Creations =
and=0A=
# many individuals on behalf of Digital Creations.  Specific=0A=
# attributions are listed in the accompanying credits file.=0A=
# =0A=
########################################################################=
######=0A=
__doc__=3D'''Application support=0A=
=0A=
=0A=
$Id: Application.py,v 1.88 1999/02/11 00:49:45 amos Exp $'''=0A=
__version__=3D'$Revision: 1.88 $'[11:-2]=0A=
=0A=
=0A=
import Globals,Folder,os,regex,sys,App.Product, App.ProductRegistry=0A=
import time, traceback, os, string=0A=
from string import strip, lower, find, rfind, join=0A=
from DateTime import DateTime=0A=
from AccessControl.User import UserFolder=0A=
from HelpSys.HelpSys import HelpSys=0A=
from App.ApplicationManager import ApplicationManager=0A=
from Globals import Persistent=0A=
from FindSupport import FindSupport=0A=
from ImageFile import ImageFile=0A=
from urllib import quote=0A=
from cStringIO import StringIO=0A=
=0A=
=0A=
_standard_error_msg=3D'''\=0A=
<!--#var standard_html_header-->=0A=
<!--#if error_message-->=0A=
 <!--#var error_message-->=0A=
<!--#else-->=0A=
<TABLE BORDER=3D"0" WIDTH=3D"100%">=0A=
<TR>=0A=
  <TD WIDTH=3D"10%" ALIGN=3D"CENTER">=0A=
  <STRONG><FONT SIZE=3D"+6" COLOR=3D"#77003B">!</FONT></STRONG>=0A=
  </TD>=0A=
  <TD WIDTH=3D"90%"><BR>=0A=
  <FONT SIZE=3D"+2">System Unavailable</FONT>=0A=
  <P>This site is currently experiencing technical difficulties. =0A=
Please contact the site administrator for more information.  For=0A=
additional technical information, please refer to the HTML source for =
this=0A=
page.  Thank you for your patience.</P>=0A=
  </TD>=0A=
</TR>=0A=
</TABLE>=0A=
<!--=0A=
 Error type:  <!--#var error_type-->=0A=
 Error value: <!--#var error_value-->=0A=
 -->=0A=
<!--#comment-->=0A=
 Here, events like logging and other actions may also be performed, =
such as=0A=
 sending mail automatically to the administrator.=0A=
<!--#/comment-->=0A=
<!--#endif-->=0A=
<!--#var standard_html_footer-->'''=0A=
=0A=
=0A=
class Application(Globals.ApplicationDefaultPermissions, =
Folder.Folder,=0A=
                  App.ProductRegistry.ProductRegistry, FindSupport):=0A=
    """Top-level system object"""=0A=
    title    =3D'Zope'=0A=
    __roles__=3D['Manager', 'Anonymous']=0A=
    __defined_roles__=3D('Manager','Anonymous')=0A=
    web__form__method=3D'GET'=0A=
    isTopLevelPrincipiaApplicationObject=3D1=0A=
=0A=
    # Create the help system object=0A=
    HelpSys=3DHelpSys()=0A=
    =0A=
    class misc_:=0A=
        "Miscellaneous product information"=0A=
        __roles__=3DNone=0A=
=0A=
    class p_:=0A=
        "Shared system information"=0A=
        __roles__=3DNone=0A=
=0A=
        folder=3DImageFile('www/Folder_icon.gif', globals())=0A=
        image =3DImageFile('www/Image_icon.gif', globals())=0A=
        file  =3DImageFile('www/File_icon.gif', globals())=0A=
        dtmldoc=3Ddoc=3DImageFile('www/dtmldoc.gif', globals())=0A=
        dtmlmethod =3DImageFile('www/dtmlmethod.gif', globals())=0A=
        =0A=
        broken=3DImageFile('www/broken.gif', globals())=0A=
=0A=
        =
UserFolder=3DImageFile('AccessControl/www/UserFolder_icon.gif')=0A=
        User_icon =3DImageFile('AccessControl/www/User_icon.gif')=0A=
=0A=
        locked=3DImageFile('www/modified.gif', globals())=0A=
        lockedo=3DImageFile('www/locked.gif', globals())=0A=
=0A=
        pl=3DImageFile('TreeDisplay/www/Plus_icon.gif')=0A=
        mi=3DImageFile('TreeDisplay/www/Minus_icon.gif')=0A=
        rtab=3DImageFile('App/www/rtab.gif')=0A=
        ltab=3DImageFile('App/www/ltab.gif')=0A=
        =
ControlPanel_icon=3DImageFile('OFS/www/ControlPanel_icon.gif')=0A=
        =
ApplicationManagement_icon=3DImageFile('App/www/cpSystem.gif')=0A=
        DatabaseManagement_icon=3DImageFile('App/www/dbManage.gif')=0A=
        =
InstalledProduct_icon=3DImageFile('App/www/installedProduct.gif')=0A=
        BrokenProduct_icon=3DImageFile('App/www/brokenProduct.gif')=0A=
        Product_icon=3DImageFile('App/www/product.gif')=0A=
        Factory_icon=3DImageFile('App/www/factory.gif')=0A=
        ProductFolder_icon=3DImageFile('App/www/productFolder.gif')=0A=
        =
PyPoweredSmall_Gif=3DImageFile('App/www/PythonPoweredSmall.gif')=0A=
=0A=
        ZopeButton=3DImageFile('App/www/zope_button.gif')=0A=
=0A=
        #up=3DImageFile('www/UpFolder_icon.gif', globals())=0A=
        #help=3DImageFile('www/Help_icon.gif', globals())=0A=
=0A=
    manage_options=3D(=0A=
    {'icon':'OFS/Folder_icon.gif', 'label':'Contents',=0A=
     'action':'manage_main',   'target':'manage_main'},=0A=
    {'icon':'OFS/Properties_icon.gif', 'label':'Properties',=0A=
     'action':'manage_propertiesForm',   'target':'manage_main'},=0A=
    {'label':'Import/Export', 'action':'manage_importExportForm',=0A=
     'target':'manage_main'},=0A=
    {'icon':'', 'label':'Security',=0A=
     'action':'manage_access',   'target':'manage_main'},=0A=
    {'icon':'App/undo_icon.gif', 'label':'Undo',=0A=
     'action':'manage_UndoForm',   'target':'manage_main'},=0A=
    {'label':'Find', 'action':'manage_findFrame',=0A=
     'target':'manage_main'},=0A=
    )=0A=
=0A=
    _reserved_names=3D('standard_html_header',=0A=
                     'standard_html_footer',=0A=
                     'standard_error_message',=0A=
                     'Control_Panel')=0A=
=0A=
    # This class-default __allow_groups__ ensures that the=0A=
    # superuser can still access the system if the top-level=0A=
    # UserFolder is deleted. This is necessary to allow people=0A=
    # to replace the top-level UserFolder object.=0A=
    =0A=
    __allow_groups__=3DUserFolder()=0A=
=0A=
    def _init(self):=0A=
        # Initialize users=0A=
        self.__allow_groups__=3DUserFolder()=0A=
        self._setObject('acl_users', self.__allow_groups__)=0A=
=0A=
        # Initialize control panel=0A=
        cpl=3DApplicationManager()=0A=
        cpl._init()=0A=
        self._setObject('Control_Panel', cpl)=0A=
=0A=
        # Note that this may happen before products are=0A=
        # installed, so we have to use addDocument as stand-alone.=0A=
        import Document=0A=
        Document.manage_addDocument(=0A=
            self,=0A=
            'standard_html_header',=0A=
            'Standard Html Header',=0A=
            '<HTML><HEAD><TITLE><!--#var title_or_id-->' \=0A=
            '</TITLE></HEAD><BODY BGCOLOR=3D"#FFFFFF">')=0A=
        Document.manage_addDocument(=0A=
            self,=0A=
            'standard_html_footer',=0A=
            'Standard Html Footer',=0A=
            '</BODY></HTML>')=0A=
        Document.manage_addDocument(=0A=
            self,=0A=
            'standard_error_message',=0A=
            'Standard Error Message',=0A=
            _standard_error_msg)=0A=
=0A=
=0A=
=0A=
=0A=
    def id(self):=0A=
        try:    return self.REQUEST['SCRIPT_NAME'][1:]=0A=
        except: return self.title=0A=
=0A=
    def folderClass(self): return Folder.Folder=0A=
=0A=
    def __class_init__(self): Globals.default__class_init__(self)=0A=
=0A=
    def PrincipiaRedirect(self,destination,URL1):=0A=
        """Utility function to allow user-controlled redirects"""=0A=
        if find(destination,'//') >=3D 0: raise 'Redirect', =
destination=0A=
        raise 'Redirect', ("%s/%s" % (URL1, destination))=0A=
    Redirect=3DZopeRedirect=3DPrincipiaRedirect=0A=
=0A=
    def __bobo_traverse__(self, REQUEST, name=3DNone):=0A=
        if name is None and =
REQUEST.has_key(Globals.SessionNameName):=0A=
            =
pd=3DGlobals.SessionBase[REQUEST[Globals.SessionNameName]]=0A=
            alternate_self=3Dpd.jar[self._p_oid]=0A=
            if hasattr(self, 'aq_parent'):=0A=
                =
alternate_self=3Dalternate_self.__of__(self.aq_parent)=0A=
            return alternate_self=0A=
=0A=
        try:    self._p_jar.cache.incrgc() # Perform incremental GC=0A=
        except: pass=0A=
=0A=
        try: return getattr(self, name)=0A=
        except AttributeError:=0A=
            try: return self[name]=0A=
            except KeyError:=0A=
                raise 'NotFound',(=0A=
                    "Sorry, the requested document does not =
exist.<p>"=0A=
                    "\n<!--\n%s\n%s\n-->" % =
(name,REQUEST['REQUEST_METHOD']))=0A=
=0A=
    def PrincipiaTime(self, *args):=0A=
        """Utility function to return current date/time"""=0A=
        return apply(DateTime, args)=0A=
    ZopeTime=3DPrincipiaTime=0A=
=0A=
    def ZopeAttributionButton(self):=0A=
        """Returns an HTML fragment that displays the 'powered by =
zope'=0A=
        button along with a link to the Zope site. Use this method =
to=0A=
        easily comply with the Zope attribute requirement."""=0A=
        return '<a href=3D"http://www.zope.org/Credits"><img ' \=0A=
               'src=3D"%s/p_/ZopeButton" width=3D"60" height=3D"82" ' =
\=0A=
               'border=3D"0" alt=3D"Powered by Zope"></a>' % =
self.REQUEST.BASE1=0A=
=0A=
class Expired(Persistent):=0A=
    icon=3D'p_/broken'=0A=
=0A=
    def __setstate__(self, s=3D{}):=0A=
        dict=3Dself.__dict__=0A=
        if s.has_key('id'):=0A=
            dict['id']=3Ds['id']=0A=
        elif s.has_key('__name__'):=0A=
            dict['id']=3Ds['__name__']=0A=
        else: dict['id']=3D'Unknown'=0A=
        dict['title']=3D'** Expired **'=0A=
=0A=
    def __save__(self):=0A=
        pass=0A=
=0A=
    __inform_commit__=3D__save__=0A=
=0A=
def open_bobobase():=0A=
    # Open the application database=0A=
=0A=
    import_products()=0A=
=0A=
    revision=3Dread_only=3DNone=0A=
=0A=
    if os.environ.has_key('ZOPE_READ_ONLY'):=0A=
        read_only=3D1=0A=
        try: =
revision=3DDateTime(os.environ['ZOPE_READ_ONLY']).timeTime()=0A=
        except: pass=0A=
        =0A=
    Bobobase=3DGlobals.Bobobase=3DGlobals.PickleDictionary(=0A=
        Globals.BobobaseName, read_only=3Dread_only, =
revision=3Drevision)=0A=
=0A=
    product_dir=3Dos.path.join(SOFTWARE_HOME,'Products')=0A=
=0A=
    __traceback_info__=3Dsys.path=0A=
    =0A=
    try: app=3DBobobase['Application']=0A=
    except KeyError:=0A=
        app=3DApplication()=0A=
        app._init()=0A=
        Bobobase['Application']=3Dapp=0A=
        get_transaction().note('created Application object')=0A=
        get_transaction().commit()=0A=
=0A=
    # The following items marked b/c are backward compatibility =
hacks=0A=
    # which make sure that expected system objects are added to the=0A=
    # bobobase. This is required because the bobobase in use may =
pre-=0A=
    # date the introduction of certain system objects such as those=0A=
    # which provide Lever support.=0A=
=0A=
    # b/c: Ensure that Control Panel exists.=0A=
    if not hasattr(app, 'Control_Panel'):=0A=
        cpl=3DApplicationManager()=0A=
        cpl._init()=0A=
        app._setObject('Control_Panel', cpl)=0A=
        get_transaction().note('Added Control_Panel')=0A=
        get_transaction().commit()=0A=
=0A=
    # b/c: Ensure that a ProductFolder exists.=0A=
    if not hasattr(app.Control_Panel.aq_base, 'Products'):=0A=
        app.Control_Panel.Products=3DApp.Product.ProductFolder()=0A=
        get_transaction().note('Added Control_Panel.Products')=0A=
        get_transaction().commit()=0A=
=0A=
    # b/c: Ensure that std err msg exists.=0A=
    if not hasattr(app, 'standard_error_message'):=0A=
        import Document=0A=
        Document.manage_addDocument(=0A=
            app,=0A=
            'standard_error_message',=0A=
            'Standard Error Message',=0A=
            _standard_error_msg)=0A=
        get_transaction().note('Added standard_error_message')=0A=
        get_transaction().commit()=0A=
=0A=
    install_products(app)=0A=
    get_transaction().note('Product installations')=0A=
    get_transaction().commit()=0A=
=0A=
    return Bobobase=0A=
=0A=
def import_products(_st=3Dtype('')):=0A=
    # Try to import each product, checking for and catching errors.=0A=
    path_join=3Dos.path.join=0A=
    product_dir=3Dpath_join(SOFTWARE_HOME,'Products')=0A=
    isdir=3Dos.path.isdir=0A=
    exists=3Dos.path.exists=0A=
    DictType=3Dtype({})=0A=
=0A=
    product_names=3Dos.listdir(product_dir)=0A=
    product_names.sort()=0A=
    global_dict=3Dglobals()=0A=
    silly=3D('__doc__',)=0A=
    modules=3Dsys.modules=0A=
    have_module=3Dmodules.has_key=0A=
=0A=
    for product_name in product_names:=0A=
        package_dir=3Dpath_join(product_dir, product_name)=0A=
        if not isdir(package_dir): continue=0A=
        if not exists(path_join(package_dir, '__init__.py')):=0A=
            if not exists(path_join(package_dir, '__init__.pyc')):=0A=
                continue=0A=
=0A=
        pname=3D"Products.%s" % product_name=0A=
        try:=0A=
            product=3D__import__(pname, global_dict, global_dict, =
silly)=0A=
            if hasattr(product, '__module_aliases__'):=0A=
                for k, v in product.__module_aliases__:=0A=
                    if not have_module(k):=0A=
                        if type(v) is _st and have_module(v): =
v=3Dmodules[v]=0A=
                        modules[k]=3Dv=0A=
        except:=0A=
            f=3DStringIO()=0A=
            traceback.print_exc(100,f)=0A=
            f=3Df.getvalue()=0A=
            try: modules[pname].__import_error__=3Df=0A=
            except: pass=0A=
=0A=
def install_products(app):=0A=
    # Install a list of products into the basic folder class, so=0A=
    # that all folders know about top-level objects, aka products=0A=
=0A=
    path_join=3Dos.path.join=0A=
    product_dir=3Dpath_join(SOFTWARE_HOME,'Products')=0A=
    isdir=3Dos.path.isdir=0A=
    exists=3Dos.path.exists=0A=
    DictType=3Dtype({})=0A=
=0A=
    from Folder import Folder=0A=
    folder_permissions=3D{}=0A=
    for p in Folder.__ac_permissions__:=0A=
        permission, names =3D p[:2]=0A=
        folder_permissions[permission]=3Dnames=0A=
=0A=
    meta_types=3Dlist(Folder.dynamic_meta_types)=0A=
=0A=
    product_names=3Dos.listdir(product_dir)=0A=
    product_names.sort()=0A=
    global_dict=3Dglobals()=0A=
    silly=3D('__doc__',)=0A=
=0A=
    for product_name in product_names:=0A=
        package_dir=3Dpath_join(product_dir, product_name)=0A=
        __traceback_info__=3Dproduct_name=0A=
        if not isdir(package_dir): continue=0A=
        if not exists(path_join(package_dir, '__init__.py')):=0A=
            if not exists(path_join(package_dir, '__init__.pyc')):=0A=
                continue=0A=
=0A=
        product=3D__import__("Products.%s" % product_name,=0A=
                           global_dict, global_dict, silly)=0A=
=0A=
        permissions=3D{}=0A=
        new_permissions=3D{}=0A=
        for permission, names in pgetattr(product, =
'__ac_permissions__', ()):=0A=
            if names:=0A=
                for name in names: permissions[name]=3Dpermission=0A=
            elif not folder_permissions.has_key(permission):=0A=
                new_permissions[permission]=3D()=0A=
=0A=
        for meta_type in pgetattr(product, 'meta_types', ()):=0A=
            if product_name=3D=3D'OFSP': =
meta_types.insert(0,meta_type)=0A=
            else: meta_types.append(meta_type)=0A=
            name=3Dmeta_type['name']=0A=
=0A=
        for name,method in pgetattr(product, 'methods', {}).items():=0A=
            if not hasattr(Folder, name):=0A=
                setattr(Folder, name, method)=0A=
                if name[-9:]=3D=3D'__roles__': continue # Just setting =
roles=0A=
                if (permissions.has_key(name) and=0A=
                    not =
folder_permissions.has_key(permissions[name])):=0A=
                    permission=3Dpermissions[name]=0A=
                    if new_permissions.has_key(permission):=0A=
                        new_permissions[permission].append(name)=0A=
                    else:=0A=
                        new_permissions[permission]=3D[name]=0A=
        =0A=
        if new_permissions:=0A=
            new_permissions=3Dnew_permissions.items()=0A=
            for permission, names in new_permissions:=0A=
                folder_permissions[permission]=3Dnames=0A=
            new_permissions.sort()=0A=
            Folder.__dict__['__ac_permissions__']=3Dtuple(=0A=
                list(Folder.__ac_permissions__)+new_permissions)=0A=
        =0A=
        misc_=3Dpgetattr(product, 'misc_', {})=0A=
        if type(misc_) is DictType: misc_=3DMisc_(product_name, =
misc_)=0A=
        Application.misc_.__dict__[product_name]=3Dmisc_=0A=
=0A=
        # Set up dynamic project information.=0A=
        App.Product.initializeProduct(product, product_name, =
package_dir, app)=0A=
=0A=
        get_transaction().note('Installed product '+product_name)=0A=
        get_transaction().commit()=0A=
=0A=
    Folder.dynamic_meta_types=3Dtuple(meta_types)=0A=
=0A=
    Globals.default__class_init__(Folder)=0A=
=0A=
=0A=
def pgetattr(product, name, default=3Dinstall_products, =
__init__=3D0):=0A=
    if not __init__ and hasattr(product, name): return getattr(product, =
name)=0A=
    if hasattr(product, '__init__'):=0A=
        product=3Dproduct.__init__=0A=
        if hasattr(product, name): return getattr(product, name)=0A=
=0A=
    if default is not install_products: return default=0A=
=0A=
    raise AttributeError, name=0A=
=0A=
class Misc_:=0A=
    "Miscellaneous product information"=0A=
=0A=
    __roles__=3DNone=0A=
=0A=
    def __init__(self, name, dict):=0A=
        self._d=3Ddict=0A=
        self.__name__=3Dname=0A=
=0A=
    def __str__(self): return self.__name__=0A=
    def __getitem__(self, name): return self._d[name]=0A=

------ =_NextPart_000_01BE81CA.22BAE340
Content-Type: application/octet-stream;
	name="ObjectManager.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ObjectManager.py"

########################################################################=
######=0A=
# =0A=
# Zope Public License (ZPL) Version 0.9.7=0A=
# ---------------------------------------=0A=
# =0A=
# Copyright (c) Digital Creations.  All rights reserved.=0A=
# =0A=
# This license has been certified as Open Source(tm).=0A=
# =0A=
# Redistribution and use in source and binary forms, with or without=0A=
# modification, are permitted provided that the following conditions =
are=0A=
# met:=0A=
# =0A=
# 1. Redistributions in source code must retain the above copyright=0A=
#    notice, this list of conditions, and the following disclaimer.=0A=
# =0A=
# 2. Redistributions in binary form must reproduce the above =
copyright=0A=
#    notice, this list of conditions, and the following disclaimer =
in=0A=
#    the documentation and/or other materials provided with the=0A=
#    distribution.=0A=
# =0A=
# 3. Digital Creations requests that attribution be given to Zope=0A=
#    in any manner possible. Zope includes a "Powered by Zope"=0A=
#    button that is installed by default. While it is not a license=0A=
#    violation to remove this button, it is requested that the=0A=
#    attribution remain. A significant investment has been put=0A=
#    into Zope, and this effort will continue if the Zope community=0A=
#    continues to grow. This is one way to assure that growth.=0A=
# =0A=
# 4. All advertising materials and documentation mentioning=0A=
#    features derived from or use of this software must display=0A=
#    the following acknowledgement:=0A=
# =0A=
#      "This product includes software developed by Digital =
Creations=0A=
#      for use in the Z Object Publishing Environment=0A=
#      (http://www.zope.org/)."=0A=
# =0A=
#    In the event that the product being advertised includes an=0A=
#    intact Zope distribution (with copyright and license included)=0A=
#    then this clause is waived.=0A=
# =0A=
# 5. Names associated with Zope or Digital Creations must not be used =
to=0A=
#    endorse or promote products derived from this software without=0A=
#    prior written permission from Digital Creations.=0A=
# =0A=
# 6. Modified redistributions of any form whatsoever must retain=0A=
#    the following acknowledgment:=0A=
# =0A=
#      "This product includes software developed by Digital =
Creations=0A=
#      for use in the Z Object Publishing Environment=0A=
#      (http://www.zope.org/)."=0A=
# =0A=
#    Intact (re-)distributions of any official Zope release do not=0A=
#    require an external acknowledgement.=0A=
# =0A=
# 7. Modifications are encouraged but must be packaged separately as=0A=
#    patches to official Zope releases.  Distributions that do not=0A=
#    clearly separate the patches from the original work must be =
clearly=0A=
#    labeled as unofficial distributions.  Modifications which do =
not=0A=
#    carry the name Zope may be packaged in any form, as long as =
they=0A=
#    conform to all of the clauses above.=0A=
# =0A=
# =0A=
# Disclaimer=0A=
# =0A=
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY=0A=
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, =
THE=0A=
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A =
PARTICULAR=0A=
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR =
ITS=0A=
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A=
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT=0A=
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=0A=
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED =
AND=0A=
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT =
LIABILITY,=0A=
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY =
OUT=0A=
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY =
OF=0A=
#   SUCH DAMAGE.=0A=
# =0A=
# =0A=
# This software consists of contributions made by Digital Creations =
and=0A=
# many individuals on behalf of Digital Creations.  Specific=0A=
# attributions are listed in the accompanying credits file.=0A=
# =0A=
########################################################################=
######=0A=
__doc__=3D"""Object Manager=0A=
=0A=
$Id: ObjectManager.py,v 1.50 1999/01/29 15:41:39 brian Exp $"""=0A=
=0A=
__version__=3D'$Revision: 1.50 $'[11:-2]=0A=
=0A=
import App.Management, Acquisition, App.Undo, Globals=0A=
import App.FactoryDispatcher=0A=
from Globals import HTMLFile, HTMLFile, Persistent=0A=
from Globals import MessageDialog, default__class_init__=0A=
from urllib import quote=0A=
=0A=
=0A=
class ObjectManager(=0A=
    App.Management.Navigation,=0A=
    App.Management.Tabs,=0A=
    Acquisition.Implicit,=0A=
    Persistent,=0A=
    App.Undo.UndoSupport,=0A=
    ):=0A=
    """Generic object manager=0A=
=0A=
    This class provides core behavior for collections of heterogeneous =
objects. =0A=
    """=0A=
=0A=
    meta_type  =3D'ObjectManager'=0A=
    meta_types =3D dynamic_meta_types =3D ()=0A=
    id       =3D'default'=0A=
    title=3D''=0A=
    icon=3D'p_/folder'=0A=
    _objects   =3D()=0A=
    _properties =3D({'id':'title', 'type': 'string'},)=0A=
=0A=
    manage_main          =3DHTMLFile('main', globals())=0A=
=0A=
=0A=
    manage_options=3D(=0A=
    {'icon':icon,              'label':'Objects',=0A=
     'action':'manage_main',   'target':'manage_main'},=0A=
    {'icon':'OFS/Properties_icon.gif', 'label':'Properties',=0A=
     'action':'manage_propertiesForm',   'target':'manage_main'},=0A=
    {'icon':'OFS/Help_icon.gif', 'label':'Help',=0A=
     'action':'manage_help',   'target':'_new'},=0A=
    )=0A=
=0A=
    isAnObjectManager=3D1=0A=
=0A=
    isPrincipiaFolderish=3D1=0A=
=0A=
    def __class_init__(self):=0A=
        try:    mt=3Dlist(self.meta_types)=0A=
        except: mt=3D[]=0A=
        for b in self.__bases__:=0A=
            try:=0A=
                for t in b.meta_types:=0A=
                    if t not in mt: mt.append(t)=0A=
            except: pass=0A=
        mt.sort()=0A=
        self.meta_types=3Dtuple(mt)=0A=
        =0A=
        default__class_init__(self)=0A=
=0A=
    def all_meta_types(self):=0A=
        pmt=3D()=0A=
        if hasattr(self, '_product_meta_types'): =
pmt=3Dself._product_meta_types=0A=
        elif hasattr(self, 'aq_acquire'):=0A=
            try: pmt=3Dself.aq_acquire('_product_meta_types')=0A=
            except:  pass=0A=
        return self.meta_types+self.dynamic_meta_types+pmt=0A=
=0A=
    def _checkId(self,id):=0A=
        if not id:=0A=
            raise 'Bad Request', 'No <em>id</em> was specified'=0A=
        if quote(id) !=3D id: raise 'Bad Request', (=0A=
            """The id <em>%s<em>  is invalid - it=0A=
               contains characters illegal in URLs.""" % id)=0A=
        if id[:1]=3D=3D'_': raise 'Bad Request', (=0A=
            """The id <em>%s<em>  is invalid - it =0A=
               begins with an underscore character, _.""" % id)=0A=
        if hasattr(self, 'aq_base'):=0A=
            self=3Dself.aq_base=0A=
        if hasattr(self, id):=0A=
            raise 'Bad Request', (=0A=
            """The id <em>%s<em>  is invalid - it=0A=
               is already in use.""" % id)=0A=
=0A=
    def _checkObject(self, object):=0A=
        t=3Dobject.meta_type=0A=
        if callable(t): t=3Dt()=0A=
        for d in self.all_meta_types():=0A=
            if d['name']=3D=3Dt: return=0A=
        raise 'Bad Request', 'Object type is not supported'=0A=
=0A=
    def parentObject(self):=0A=
        try:=0A=
            if self.aq_parent.isAnObjectManager:=0A=
                return (self.aq_parent,)=0A=
        except: pass=0A=
        return ()=0A=
=0A=
    def _setObject(self,id,object,roles=3DNone,user=3DNone):=0A=
        self._checkId(id)=0A=
        setattr(self,id,object)=0A=
        try:    t=3Dobject.meta_type=0A=
        except: t=3DNone=0A=
        self._objects=3Dself._objects+({'id':id,'meta_type':t},)=0A=
=0A=
=0A=
    def _delObject(self,id):=0A=
        delattr(self,id)=0A=
        if id=3D=3D'acl_users':=0A=
            # Yikes - acl_users is referred to by two names and=0A=
            # must be treated as a special case! Only get rid of=0A=
            # __allow_groups__ if it is an instance attribute, to=0A=
            # avoid deleting the class-default __allow_groups__=0A=
            # in the top-level application object which is needed=0A=
            # to allow people to replace the top-level userfolder.=0A=
            if hasattr(self, '__allow_groups__') and \=0A=
               self.__dict__.has_key('__allow_groups__'):=0A=
                delattr(self, '__allow_groups__')=0A=
        self._objects=3Dtuple(filter(lambda i,n=3Did: i['id']!=3Dn, =
self._objects))=0A=
=0A=
    def objectIds(self, spec=3DNone):=0A=
        """Return a list of subobject ids.=0A=
=0A=
        Returns a list of subobject ids of the current object.  If =
'spec' is=0A=
        specified, returns objects whose meta_type matches 'spec'.=0A=
        """=0A=
        if spec is not None:=0A=
            if type(spec)=3D=3Dtype('s'):=0A=
                spec=3D[spec]=0A=
            set=3D[]=0A=
            for ob in self._objects:=0A=
                if ob['meta_type'] in spec:=0A=
                    set.append(ob['id'])=0A=
            return set=0A=
        return map(lambda i: i['id'], self._objects)=0A=
=0A=
    def objectValues(self, spec=3DNone):=0A=
        """Return a list of the actual subobjects.=0A=
=0A=
        Returns a list of actual subobjects of the current object.  =
If=0A=
        'spec' is specified, returns only objects whose meta_type match =
'spec'=0A=
        """=0A=
        if spec is not None:=0A=
            if type(spec)=3D=3Dtype('s'):=0A=
                spec=3D[spec]=0A=
            set=3D[]=0A=
            for ob in self._objects:=0A=
                if ob['meta_type'] in spec:=0A=
                    set.append(getattr(self, ob['id']))=0A=
            return set=0A=
        return map(lambda i,s=3Dself: getattr(s,i['id']), =
self._objects)=0A=
=0A=
    def objectItems(self, spec=3DNone):=0A=
        """Return a list of (id, subobject) tuples.=0A=
=0A=
        Returns a list of (id, subobject) tuples of the current =
object.=0A=
        If 'spec' is specified, returns only objects whose meta_type =
match=0A=
        'spec'=0A=
        """=0A=
        if spec is not None:=0A=
            if type(spec)=3D=3Dtype('s'):=0A=
                spec=3D[spec]=0A=
            set=3D[]=0A=
            for ob in self._objects:=0A=
                if ob['meta_type'] in spec:=0A=
                    set.append((ob['id'], getattr(self, ob['id'])))=0A=
            return set=0A=
        return map(lambda i,s=3Dself: (i['id'], getattr(s,i['id'])),=0A=
                                    self._objects)=0A=
    def objectMap(self):=0A=
        # Return a tuple of mappings containing subobject meta-data=0A=
        return self._objects=0A=
=0A=
    def objectIds_d(self,t=3DNone):=0A=
        v=3Dself.objectIds(t)=0A=
        try:    n=3Dself._reserved_names=0A=
        except: return v=0A=
        return filter(lambda x,r=3Dn: x not in r, v)=0A=
=0A=
    def objectValues_d(self,t=3DNone):=0A=
        v=3Dself.objectIds(t)=0A=
        try:    n=3Dself._reserved_names=0A=
        except: return map(lambda i,s=3Dself: getattr(s,i), v)=0A=
        return map(lambda i,s=3Dself: getattr(s,i),=0A=
                    filter(lambda x,r=3Dn: x not in r, v))=0A=
=0A=
    def objectItems_d(self,t=3DNone):=0A=
        v=3Dself.objectItems(t)=0A=
        try:    n=3Dself._reserved_names=0A=
        except: return v=0A=
        return filter(lambda x,r=3Dn: x[0] not in r, v)=0A=
=0A=
    def objectMap_d(self,t=3DNone):=0A=
        v=3Dself._objects=0A=
        try:    n=3Dself._reserved_names=0A=
        except: return v=0A=
        return filter(lambda x,r=3Dn: x['id'] not in r, v)=0A=
=0A=
    def superIds(self,t):=0A=
        if type(t)=3D=3Dtype('s'): t=3D(t,)=0A=
        obj=3Dself=0A=
        vals=3D[]=0A=
        x=3D0=0A=
        while x < 100:=0A=
            try:    set=3Dobj._objects=0A=
            except: set=3D()=0A=
            for i in set:=0A=
                try:=0A=
                    if i['meta_type'] in t:=0A=
                        id=3Di['id']=0A=
                        if not id in vals: vals.append(id)=0A=
                except: pass=0A=
            try:    obj=3Dobj.aq_parent=0A=
            except: return vals=0A=
            x=3Dx+1=0A=
        return vals=0A=
=0A=
    def superValues(self,t):=0A=
        if type(t)=3D=3Dtype('s'): t=3D(t,)=0A=
        obj=3Dself=0A=
        seen=3D{}=0A=
        vals=3D[]=0A=
        have=3Dseen.has_key=0A=
        x=3D0=0A=
        while x < 100:=0A=
            try:    set=3Dobj._objects=0A=
            except: set=3D()=0A=
            for i in set:=0A=
                try:=0A=
                    id=3Di['id']=0A=
                    if (not have(id)) and (i['meta_type'] in t):=0A=
                        vals.append(getattr(obj,id))=0A=
                        seen[id]=3D1=0A=
                except: pass=0A=
            try:    obj=3Dobj.aq_parent=0A=
            except: return vals=0A=
            x=3Dx+1=0A=
        return vals=0A=
=0A=
    def superItems(self,t):=0A=
        if type(t)=3D=3Dtype('s'): t=3D(t,)=0A=
        obj=3Dself=0A=
        seen=3D{}=0A=
        vals=3D[]=0A=
        have=3Dseen.has_key=0A=
        x=3D0=0A=
        while x < 100:=0A=
            try:    set=3Dobj._objects=0A=
            except: set=3D()=0A=
            for i in set:=0A=
                try:=0A=
                    id=3Di['id']=0A=
                    if (not have(id)) and (i['meta_type'] in t):=0A=
                        vals.append((id,getattr(obj,id),))=0A=
                        seen[id]=3D1=0A=
                except: pass=0A=
            try:    obj=3Dobj.aq_parent=0A=
            except: return vals=0A=
            x=3Dx+1=0A=
        return vals=0A=
=0A=
    def superHasAttr(self,attr):=0A=
        obj=3Dself=0A=
        seen=3D{}=0A=
        vals=3D[]=0A=
        have=3Dseen.has_key=0A=
        x=3D0=0A=
        while x < 100:=0A=
            try:    set=3Dobj._objects=0A=
            except: set=3D()=0A=
            for i in set:=0A=
                try:=0A=
                    id=3Di['id']=0A=
                    if not have(id):=0A=
                        v=3Dgetattr(obj,id)=0A=
                        if hasattr(v,attr):=0A=
                            vals.append(v)=0A=
                            seen[id]=3D1=0A=
                except: pass=0A=
            try:    obj=3Dobj.aq_parent=0A=
            except: return vals=0A=
            x=3Dx+1=0A=
        return vals=0A=
=0A=
=0A=
    manage_addProduct=3DApp.FactoryDispatcher.ProductDispatcher()=0A=
=0A=
=0A=
    def manage_delObjects(self, ids=3D[], REQUEST=3DNone):=0A=
        """Delete a subordinate object=0A=
        =0A=
        The objects specified in 'ids' get deleted.=0A=
        """=0A=
        if type(ids) is type(''): ids=3D[ids]=0A=
        if not ids:=0A=
            return MessageDialog(title=3D'No items specified',=0A=
                   message=3D'No items were specified!',=0A=
                   action =3D'./manage_main',)=0A=
        try:    p=3Dself._reserved_names=0A=
        except: p=3D()=0A=
        for n in ids:=0A=
            if n in p:=0A=
                return MessageDialog(title=3D'Not Deletable',=0A=
                       message=3D'<EM>%s</EM> cannot be deleted.' % =
n,=0A=
                       action =3D'./manage_main',)=0A=
        while ids:=0A=
            id=3Dids[-1]=0A=
            if not hasattr(self, id) or not =
self.__dict__.has_key(id):=0A=
                raise 'BadRequest', '%s does not exist' % ids[-1]=0A=
            self._delObject(id)=0A=
            del ids[-1]=0A=
        if REQUEST is not None:=0A=
                return self.manage_main(self, REQUEST, =
update_menu=3D1)=0A=
=0A=
=0A=

------ =_NextPart_000_01BE81CA.22BAE340--