Back to index

plone3  3.1.7
Install.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## GroupUserFolder
00003 ## Copyright (C)2006 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see the file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 
00020 """
00021 __version__ = "$Revision:  $"
00022 # $Source:  $
00023 # $Id: Install.py 30098 2006-09-08 12:35:01Z encolpe $
00024 __docformat__ = 'restructuredtext'
00025 
00026 from Products.GroupUserFolder import groupuserfolder_globals
00027 from Products.GroupUserFolder.GroupUserFolder import GroupUserFolder
00028 from StringIO import StringIO
00029 from Products.CMFCore.utils import getToolByName
00030 from Products.CMFCore.DirectoryView import addDirectoryViews
00031 from Acquisition import aq_base
00032 from OFS.Folder import manage_addFolder
00033 
00034 
00035 SKIN_NAME = "gruf"
00036 _globals = globals()
00037 
00038 def install_plone(self, out):
00039     pass
00040 
00041 def install_subskin(self, out, skin_name=SKIN_NAME, globals=groupuserfolder_globals):
00042     print >>out, "  Installing subskin."
00043     skinstool=getToolByName(self, 'portal_skins')
00044     if skin_name not in skinstool.objectIds():
00045         print >>out, "    Adding directory view for GRUF"
00046         addDirectoryViews(skinstool, 'skins', globals)
00047 
00048     for skinName in skinstool.getSkinSelections():
00049         path = skinstool.getSkinPath(skinName)
00050         path = [i.strip() for i in  path.split(',')]
00051         try:
00052             if skin_name not in path:
00053                 path.insert(path.index('custom') +1, skin_name)
00054         except ValueError:
00055             if skin_name not in path:
00056                 path.append(skin_name)
00057 
00058         path = ','.join(path)
00059         skinstool.addSkinSelection( skinName, path)
00060     print >>out, "  Done installing subskin."
00061 
00062 def walk(out, obj, operation):
00063     if obj.isPrincipiaFolderish:
00064         for content in obj.objectValues():
00065             walk(out, content, operation)
00066     operation(out, obj)
00067 
00068 
00069 def migrate_user_folder(obj, out, ):
00070     """
00071     Move a user folder into a temporary folder, create a GroupUserFolder,
00072     and then move the old user folder into the Users portion of the GRUF.
00073     NOTE: You cant copy/paste between CMF and Zope folder.  *sigh*
00074     """
00075     id = obj.getId()
00076     if id == 'acl_users':
00077         if obj.__class__.__name__ == "GroupUserFolder":
00078             # Avoid already-created GRUFs
00079             print >>out, "    Do NOT migrate acl_users at %s, as it is already a GroupUserFolder" % ('/'.join( obj.getPhysicalPath() ), )
00080             return out.getvalue()
00081 
00082         print >>out, "    Migrating acl_users folder at %s to a GroupUserFolder" % ('/'.join( obj.getPhysicalPath() ), )
00083 
00084         container = obj.aq_parent
00085 
00086         # Instead of using Copy/Paste we hold a reference to the acl_users
00087         # and use that reference instead of physically moving objects in ZODB
00088         tmp_users=container._getOb('acl_users')
00089         tmp_allow=container.__allow_groups__
00090 
00091         del container.__allow_groups__
00092         if 'acl_users' in container.objectIds():
00093             container.manage_delObjects('acl_users')
00094 
00095         container.manage_addProduct['GroupUserFolder'].manage_addGroupUserFolder()
00096         container.acl_users.Users.manage_delObjects( 'acl_users' )
00097         container.acl_users.Users._setObject('acl_users', aq_base(tmp_users))
00098         container.__allow_groups__ = aq_base(getattr(container,'acl_users'))
00099 
00100     return out.getvalue()
00101 
00102 
00103 def migrate_plone_site_to_gruf(self, out = None):
00104     if out is None:
00105         out = StringIO()
00106     print >>out, "  Attempting to migrate UserFolders to GroupUserFolders..."
00107     urltool=getToolByName(self, 'portal_url')
00108     plonesite = urltool.getPortalObject()
00109     ## We disable the 'walk' operation because if the acl_users object is deep inside
00110     ## the Plone site, that is a real problem. Furthermore, that may be because
00111     ## we're already digging an GRUF and have the risk to update a GRUF/User/acl_users
00112     ## object !
00113 ##    walk(out, plonesite, migrate_user_folder)
00114     for obj in plonesite.objectValues():
00115         migrate_user_folder(obj, out, )
00116     print >>out, "  Done Migrating UserFolders to GroupUserFolders."
00117     return out.getvalue()
00118 
00119 def install(self):
00120     out = StringIO()
00121     print >>out, "Installing GroupUserFolder"
00122     install_subskin(self, out)
00123     install_plone(self, out)
00124     migrate_plone_site_to_gruf(self, out)
00125     print >>out, "Done."
00126     return out.getvalue()