87de5969721ade5d109d84321451192f74c93be2
1 # -*- coding: utf-8 -*-
3 ## Copyright (C)2006 Ingeniweb
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2 of the License, or
8 ## (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; see the file COPYING. If not, write to the
17 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 __version__
= "$Revision: $"
23 # $Id: Install.py 30098 2006-09-08 12:35:01Z encolpe $
24 __docformat__
= 'restructuredtext'
26 from Products
.GroupUserFolder
import groupuserfolder_globals
27 from Products
.GroupUserFolder
.GroupUserFolder
import GroupUserFolder
28 from StringIO
import StringIO
29 from Products
.CMFCore
.utils
import getToolByName
30 from Products
.CMFCore
.DirectoryView
import addDirectoryViews
31 from Acquisition
import aq_base
32 from OFS
.Folder
import manage_addFolder
38 def install_plone(self
, out
):
41 def install_subskin(self
, out
, skin_name
=SKIN_NAME
, globals=groupuserfolder_globals
):
42 print >>out
, " Installing subskin."
43 skinstool
=getToolByName(self
, 'portal_skins')
44 if skin_name
not in skinstool
.objectIds():
45 print >>out
, " Adding directory view for GRUF"
46 addDirectoryViews(skinstool
, 'skins', globals)
48 for skinName
in skinstool
.getSkinSelections():
49 path
= skinstool
.getSkinPath(skinName
)
50 path
= [i
.strip() for i
in path
.split(',')]
52 if skin_name
not in path
:
53 path
.insert(path
.index('custom') +1, skin_name
)
55 if skin_name
not in path
:
56 path
.append(skin_name
)
59 skinstool
.addSkinSelection( skinName
, path
)
60 print >>out
, " Done installing subskin."
62 def walk(out
, obj
, operation
):
63 if obj
.isPrincipiaFolderish
:
64 for content
in obj
.objectValues():
65 walk(out
, content
, operation
)
69 def migrate_user_folder(obj
, out
, ):
71 Move a user folder into a temporary folder, create a GroupUserFolder,
72 and then move the old user folder into the Users portion of the GRUF.
73 NOTE: You cant copy/paste between CMF and Zope folder. *sigh*
77 if obj
.__class
__.__name
__ == "GroupUserFolder":
78 # Avoid already-created GRUFs
79 print >>out
, " Do NOT migrate acl_users at %s, as it is already a GroupUserFolder" % ('/'.join( obj
.getPhysicalPath() ), )
82 print >>out
, " Migrating acl_users folder at %s to a GroupUserFolder" % ('/'.join( obj
.getPhysicalPath() ), )
84 container
= obj
.aq_parent
86 # Instead of using Copy/Paste we hold a reference to the acl_users
87 # and use that reference instead of physically moving objects in ZODB
88 tmp_users
=container
._getOb
('acl_users')
89 tmp_allow
=container
.__allow
_groups
__
91 del container
.__allow
_groups
__
92 if 'acl_users' in container
.objectIds():
93 container
.manage_delObjects('acl_users')
95 container
.manage_addProduct
['GroupUserFolder'].manage_addGroupUserFolder()
96 container
.acl_users
.Users
.manage_delObjects( 'acl_users' )
97 container
.acl_users
.Users
._setObject
('acl_users', aq_base(tmp_users
))
98 container
.__allow
_groups
__ = aq_base(getattr(container
,'acl_users'))
100 return out
.getvalue()
103 def migrate_plone_site_to_gruf(self
, out
= None):
106 print >>out
, " Attempting to migrate UserFolders to GroupUserFolders..."
107 urltool
=getToolByName(self
, 'portal_url')
108 plonesite
= urltool
.getPortalObject()
109 ## We disable the 'walk' operation because if the acl_users object is deep inside
110 ## the Plone site, that is a real problem. Furthermore, that may be because
111 ## we're already digging an GRUF and have the risk to update a GRUF/User/acl_users
113 ## walk(out, plonesite, migrate_user_folder)
114 for obj
in plonesite
.objectValues():
115 migrate_user_folder(obj
, out
, )
116 print >>out
, " Done Migrating UserFolders to GroupUserFolders."
117 return out
.getvalue()
121 print >>out
, "Installing GroupUserFolder"
122 install_subskin(self
, out
)
123 install_plone(self
, out
)
124 migrate_plone_site_to_gruf(self
, out
)
126 return out
.getvalue()