Commit 6902ff1b authored by Casey Duncan's avatar Casey Duncan

Yanked OM browser default implementation for alpha 1, planning on a more...

Yanked OM browser default implementation for alpha 1, planning on a more modular implementation for alpha 2.
parent 9d4c5f8c
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
Folders are the basic container objects and are analogous to directories. Folders are the basic container objects and are analogous to directories.
$Id: Folder.py,v 1.99 2002/04/01 19:52:39 andreasjung Exp $""" $Id: Folder.py,v 1.100 2002/06/07 18:10:31 caseman Exp $"""
__version__='$Revision: 1.99 $'[11:-2] __version__='$Revision: 1.100 $'[11:-2]
import Globals, SimpleItem, ObjectManager, PropertyManager import Globals, SimpleItem, ObjectManager, PropertyManager
import AccessControl.Role, webdav.Collection, FindSupport import AccessControl.Role, webdav.Collection, FindSupport
...@@ -46,9 +46,6 @@ def manage_addFolder(self, id, title='', ...@@ -46,9 +46,6 @@ def manage_addFolder(self, id, title='',
self._setObject(id, ob) self._setObject(id, ob)
ob=self._getOb(id) ob=self._getOb(id)
# Acquire browser_default from parent
ob.setBrowserDefaultId(acquire=1)
checkPermission=getSecurityManager().checkPermission checkPermission=getSecurityManager().checkPermission
if createUserF: if createUserF:
...@@ -64,7 +61,7 @@ def manage_addFolder(self, id, title='', ...@@ -64,7 +61,7 @@ def manage_addFolder(self, id, title='',
'You are not authorized to add Page Templates.' 'You are not authorized to add Page Templates.'
) )
ob.manage_addProduct['PageTemplates'].manage_addPageTemplate( ob.manage_addProduct['PageTemplates'].manage_addPageTemplate(
id=ob.getBrowserDefaultId(acquire=1), title='') id='index_html', title='')
if REQUEST is not None: if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1) return self.manage_main(self, REQUEST, update_menu=1)
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
############################################################################## ##############################################################################
__doc__="""Object Manager __doc__="""Object Manager
$Id: ObjectManager.py,v 1.150 2002/04/15 10:15:26 htrd Exp $""" $Id: ObjectManager.py,v 1.151 2002/06/07 18:10:31 caseman Exp $"""
__version__='$Revision: 1.150 $'[11:-2] __version__='$Revision: 1.151 $'[11:-2]
import App.Management, Acquisition, Globals, CopySupport, Products import App.Management, Acquisition, Globals, CopySupport, Products
import os, App.FactoryDispatcher, re, Products import os, App.FactoryDispatcher, re, Products
...@@ -84,24 +84,6 @@ def checkValidId(self, id, allow_dup=0): ...@@ -84,24 +84,6 @@ def checkValidId(self, id, allow_dup=0):
'The id "%s" contains characters illegal in URLs.' % id 'The id "%s" contains characters illegal in URLs.' % id
) )
class BrowserDefault(Acquisition.Implicit, Persistent):
"""Callable default browser object for object managers. This is made as a
class so that folderish objs not overriding browser_default can simply
not define it. We also define this class as replaceable so that TTW
scripts can override it
"""
security = ClassSecurityInfo()
__replaceable__ = REPLACEABLE # Allow this to be overridden in instances
def __call__(self, request):
"""Return the proper default method name to be published
This name is acquired from the parent object"""
return self.aq_parent, \
(self.aq_acquire('_object_manager_browser_default_id'),)
default__class_init__(BrowserDefault)
class BeforeDeleteException( Exception ): pass # raise to veto deletion class BeforeDeleteException( Exception ): pass # raise to veto deletion
class BreakoutException ( Exception ): pass # raised to break out of loops class BreakoutException ( Exception ): pass # raised to break out of loops
...@@ -132,10 +114,8 @@ class ObjectManager( ...@@ -132,10 +114,8 @@ class ObjectManager(
('manage_importObject','manage_importExportForm', ('manage_importObject','manage_importExportForm',
'manage_exportObject') 'manage_exportObject')
), ),
('View', ('getBrowserDefaultId',)),
('Manage folderish settings', ('Manage folderish settings',
('manage_settings', 'setBrowserDefaultId', ('manage_settings',)
'isBrowserDefaultAcquired','hasCustomBrowserDefault')
), ),
) )
...@@ -153,7 +133,6 @@ class ObjectManager( ...@@ -153,7 +133,6 @@ class ObjectManager(
manage_options=( manage_options=(
{'label':'Contents', 'action':'manage_main', {'label':'Contents', 'action':'manage_main',
'help':('OFSP','ObjectManager_Contents.stx')}, 'help':('OFSP','ObjectManager_Contents.stx')},
{'label':'Settings', 'action':'manage_settings'},
) )
isAnObjectManager=1 isAnObjectManager=1
...@@ -677,73 +656,6 @@ class ObjectManager( ...@@ -677,73 +656,6 @@ class ObjectManager(
return NullResource(self, key, request).__of__(self) return NullResource(self, key, request).__of__(self)
raise KeyError, key raise KeyError, key
#######################################################################
# Death to index_html implementation (casey)
def setBrowserDefaultId(self, id='', acquire=0, REQUEST=None):
"""Set the id of the browser_default method. If acquire is true
then the local browser_default is cleared and the setting is
acquired
"""
if self.hasCustomBrowserDefault():
# If a custom browser default is installed, don't override it
raise BadRequestException, \
'Cannot override custom browser default'
if acquire:
try:
del self._object_manager_browser_default_id
except (AttributeError, KeyError):
pass # If its already gone, so be it
id = self.aq_acquire('_object_manager_browser_default_id')
else:
self._checkId(id, allow_dup=1)
self._object_manager_browser_default_id = id
if id == 'index_html':
# This is a small optimization since the publisher stills falls
# back on this default value if there is no browser_default
# method at all for bw compatibility
try:
del self.browser_default
except (AttributeError, KeyError):
pass
else:
# Create a browser_default callable
self.browser_default = BrowserDefault()
if REQUEST:
REQUEST.RESPONSE.redirect(REQUEST.URL1 +
'/manage_settings?manage_tabs_message=Settings+Changed')
def getBrowserDefaultId(self, acquire=0):
"""Get the id of the browser_default method. If acquire is true
then the acquired value is returned if there is no local setting,
otherwise None is returned. None is also returned if
browser_default has been overidden in this (or a higher) instance
using a custom callable.
"""
if self.hasCustomBrowserDefault():
return None
if acquire:
return self.aq_acquire('_object_manager_browser_default_id')
else:
return getattr(self, '_object_manager_browser_default_id', None)
def isBrowserDefaultAcquired(self):
"""Return true if the current browser default is being acquired"""
return not hasattr(self, '_object_manager_browser_default_id')
def hasCustomBrowserDefault(self):
"""Return true if a custom browser_default object has been
installed
"""
try:
return getattr(self.browser_default, '__class__', None) \
is not BrowserDefault
except AttributeError:
return 0
def findChilds(obj,dirname=''): def findChilds(obj,dirname=''):
""" recursive walk through the object hierarchy to """ recursive walk through the object hierarchy to
find all childs of an object (ajung) find all childs of an object (ajung)
......
# Added to test new ObjectManager functions
# for death to index_html implementation
# Not really a complete test suite for OM yet -Casey
import os, sys, unittest
import string, cStringIO, re
import ZODB, Acquisition
from OFS.Application import Application
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addFile
from OFS.ObjectManager import BadRequestException
from Testing.makerequest import makerequest
from webdav.common import rfc1123_date
from AccessControl import SecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from mimetools import Message
from multifile import MultiFile
class UnitTestSecurityPolicy:
"""
Stub out the existing security policy for unit testing purposes.
"""
#
# Standard SecurityPolicy interface
#
def validate( self
, accessed=None
, container=None
, name=None
, value=None
, context=None
, roles=None
, *args
, **kw):
return 1
def checkPermission( self, permission, object, context) :
return 1
class UnitTestUser( Acquisition.Implicit ):
"""
Stubbed out manager for unit testing purposes.
"""
def getId( self ):
return 'unit_tester'
getUserName = getId
def allowed( self, object, object_roles=None ):
return 1
def makeConnection():
import ZODB
from ZODB.DemoStorage import DemoStorage
s = DemoStorage(quota=(1<<20))
return ZODB.DB( s ).open()
def test_browser_default(self, request):
return self, ('foo.html',)
class TestObjectManager( unittest.TestCase ):
def setUp( self ):
self.connection = makeConnection()
try:
r = self.connection.root()
a = Application()
a.manage_addFolder = manage_addFolder
r['Application'] = a
self.root = a
responseOut = self.responseOut = cStringIO.StringIO()
self.app = makerequest( self.root, stdout=responseOut )
manage_addFolder( self.app, 'folder1' )
self.folder1 = folder1 = getattr( self.app, 'folder1' )
manage_addFolder( folder1, 'folder2' )
self.folder2 = folder2 = getattr( folder1, 'folder2' )
folder1.all_meta_types = folder2.all_meta_types = \
( { 'name' : 'File'
, 'action' : 'manage_addFile'
, 'permission' : 'Add images and files'
},
{ 'name':'Some Folderish',
'action':'manage_addFolder',
'permission':'Add Some Folderish'
},
{ 'name':'Folder',
'action':'manage_addFolder',
'permission':'Add Folders' }
)
manage_addFile( folder1, 'other_html'
, file='', content_type='text/plain')
manage_addFile( folder1, 'index_html'
, file='', content_type='text/plain')
# Hack, we need a _p_mtime for the file, so we make sure that it
# has one. We use a subtransaction, which means we can rollback
# later and pretend we didn't touch the ZODB.
get_transaction().commit()
except:
self.connection.close()
raise
get_transaction().begin()
self.policy = UnitTestSecurityPolicy()
self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
newSecurityManager( None, UnitTestUser().__of__( self.root ) )
def tearDown( self ):
noSecurityManager()
SecurityManager.setSecurityPolicy( self.oldPolicy )
del self.oldPolicy
del self.policy
del self.folder2
del self.folder1
get_transaction().abort()
self.app._p_jar.sync()
self.connection.close()
del self.app
del self.responseOut
del self.root
del self.connection
def testSetBrowserDefaultBogus( self ):
# try to change it to an invalid id
try:
self.folder1.setBrowserDefaultId('_bogus')
self.fail()
except BadRequestException:
pass
# Try to override a custom browser_default
try:
self.folder1.browser_default = test_browser_default
self.folder1.setBrowserDefaultId('index_html')
self.fail()
except BadRequestException:
del self.folder1.browser_default
def testBrowserDefault( self ):
# Test setting and acquisition of setting
self.failUnless( self.folder1.isBrowserDefaultAcquired() )
self.folder1.setBrowserDefaultId('other_html')
self.failIf( self.folder1.isBrowserDefaultAcquired() )
self.assertEqual( self.folder1.getBrowserDefaultId(), 'other_html')
self.assertEqual( self.folder2.getBrowserDefaultId(), None )
self.assertEqual( self.folder2.getBrowserDefaultId(1), 'other_html' )
self.folder1.setBrowserDefaultId(acquire=1)
self.failUnless( self.folder1.isBrowserDefaultAcquired() )
self.assertEqual( self.folder1.getBrowserDefaultId(), None )
default = self.root.getBrowserDefaultId()
self.assertEqual( self.folder1.getBrowserDefaultId(1), default )
self.assertEqual( self.folder2.getBrowserDefaultId(1), default )
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestObjectManager ) )
return suite
def main():
unittest.TextTestRunner().run(test_suite())
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment