[CMF-checkins] CVS: CMF/CMFDefault - Document.py:1.51 File.py:1.21 Image.py:1.19 Link.py:1.25 NewsItem.py:1.17 __init__.py:1.14

Florent Guillaume fg@nuxeo.com
Sat, 3 Aug 2002 23:52:27 -0400


Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv1625/CMFDefault

Modified Files:
	Document.py File.py Image.py Link.py NewsItem.py __init__.py 
Log Message:

Code cleanup:
Use declarative security instead of __ac_permissions__.
Use InitializeClass instead of default__class_init__.
Use AddPortalContent instead of ADD_CONTENT_PERMISSION.
Use AddPortalFolders instead of ADD_FOLDERS_PERMISSION.



=== CMF/CMFDefault/Document.py 1.50 => 1.51 ===
 $Id$
 """
 
-ADD_CONTENT_PERMISSION = 'Add portal content'
-
 import Globals, StructuredText, string, utils, re
 from StructuredText.HTMLWithImages import HTMLWithImages
 from Globals import DTMLFile, InitializeClass
@@ -100,7 +98,6 @@
     _last_safety_belt = ''
     _safety_belt = ''
 
-    # Declarative security (replaces __ac_permissions__)
     security = ClassSecurityInfo()
 
     def __init__(self, id, title='', description='', text_format='', text=''):


=== CMF/CMFDefault/File.py 1.20 => 1.21 ===
 make it more Portal-friendly.
 """
 
-ADD_CONTENT_PERMISSION = 'Add portal content'
+from Globals import InitializeClass
+from AccessControl import ClassSecurityInfo
 
-
-from Globals import HTMLFile, HTML
 from Products.CMFCore.PortalContent import PortalContent
-import Globals
 from DublinCore import DefaultDublinCoreImpl
 
 from Products.CMFCore.CMFCorePermissions import View
@@ -135,11 +133,8 @@
     _isDiscussable = 1
     icon = PortalContent.icon
 
-    __ac_permissions__ = (
-        (View, ('download',)),
-        (ModifyPortalContent, ('edit',)),
-        )
-    
+    security = ClassSecurityInfo()
+
     def __init__( self
                 , id
                 , title=''
@@ -160,7 +155,8 @@
         DefaultDublinCoreImpl.__init__( self, title, subject, description
                                , contributors, effective_date, expiration_date
                                , format, language, rights )
-    
+
+    security.declareProtected(View, 'SearchableText')
     def SearchableText(self):
         """
         SeachableText is used for full text seraches of a portal.  It
@@ -168,16 +164,19 @@
         """
         return "%s %s" % (self.title, self.description)
 
+    security.declarePrivate('manage_beforeDelete')
     def manage_afterAdd(self, item, container):
         """Both of my parents have an afterAdd method"""
         OFS.Image.File.manage_afterAdd(self, item, container)
         PortalContent.manage_afterAdd(self, item, container)
 
+    security.declarePrivate('manage_beforeDelete')
     def manage_beforeDelete(self, item, container):
         """Both of my parents have a beforeDelete method"""
         PortalContent.manage_beforeDelete(self, item, container)
         OFS.Image.File.manage_beforeDelete(self, item, container)
 
+    security.declarePrivate('_isNotEmpty')
     def _isNotEmpty(self, file):
         """ Do various checks on 'file' to try to determine non emptiness. """
         if not file:
@@ -195,6 +194,7 @@
             if t: return 1
             else: return 0
 
+    security.declarePrivate('_edit')
     def _edit(self, precondition='', file=''):
         """ Perform changes for user """
         if precondition: self.precondition = precondition
@@ -205,6 +205,7 @@
 
         self.setFormat(self.content_type)
 
+    security.declareProtected(ModifyPortalContent, 'edit')
     def edit(self, precondition='', file=''):
         """ Update and reindex. """
         self._edit( precondition, file )
@@ -212,6 +213,7 @@
 
     edit = WorkflowAction(edit)
 
+    security.declareProtected(View, 'download')
     def download(self, REQUEST, RESPONSE):
         """Download this item.
         
@@ -229,5 +231,6 @@
                            'attachment; filename=%s' % self.getId())
         return OFS.Image.File.index_html(self, REQUEST, RESPONSE)
 
-Globals.default__class_init__(File)
+
+InitializeClass(File)
 


=== CMF/CMFDefault/Image.py 1.18 => 1.19 ===
 Zope's built-in Image object.
 """
 
-ADD_CONTENT_PERMISSION = 'Add portal content'
+from Globals import InitializeClass
+from AccessControl import ClassSecurityInfo
 
-
-from Globals import HTMLFile, HTML
 from Products.CMFCore.PortalContent import PortalContent
-import Globals
 from DublinCore import DefaultDublinCoreImpl
 
 from Products.CMFCore.CMFCorePermissions import View
@@ -127,10 +125,8 @@
     _isDiscussable = 1
     icon = PortalContent.icon
 
-    __ac_permissions__ = (
-        (ModifyPortalContent, ('edit',)),
-        )
-    
+    security = ClassSecurityInfo()
+
     def __init__( self
                 , id
                 , title=''
@@ -151,7 +147,8 @@
         DefaultDublinCoreImpl.__init__( self, title, subject, description
                                , contributors, effective_date, expiration_date
                                , format, language, rights )
-    
+
+    security.declareProtected(View, 'SearchableText')
     def SearchableText(self):
         """
             SeachableText is used for full text seraches of a portal.
@@ -159,16 +156,19 @@
         """
         return "%s %s" % (self.title, self.description)
 
+    security.declarePrivate('manage_beforeDelete')
     def manage_afterAdd(self, item, container):
         """Both of my parents have an afterAdd method"""
         OFS.Image.Image.manage_afterAdd(self, item, container)
         PortalContent.manage_afterAdd(self, item, container)
 
+    security.declarePrivate('manage_beforeDelete')
     def manage_beforeDelete(self, item, container):
         """Both of my parents have a beforeDelete method"""
         PortalContent.manage_beforeDelete(self, item, container)
         OFS.Image.Image.manage_beforeDelete(self, item, container)
-        
+
+    security.declarePrivate('_isNotEmpty')
     def _isNotEmpty(self, file):
         """ Do various checks on 'file' to try to determine non emptiness. """
         if not file:
@@ -186,6 +186,7 @@
             if t: return 1
             else: return 0
 
+    security.declarePrivate('_edit')
     def _edit(self, precondition='', file=''):
         """ Update image. """
         if precondition: self.precondition = precondition
@@ -196,6 +197,7 @@
 
         self.setFormat(self.content_type)
 
+    security.declareProtected(ModifyPortalContent, 'edit')
     def edit(self, precondition='', file=''):
         """ Update and reindex. """
         self._edit( precondition, file )
@@ -203,6 +205,7 @@
 
     edit = WorkflowAction(edit)
 
+    security.declareProtected(View, 'index_html')
     def index_html(self, REQUEST, RESPONSE):
         """
         Display the image, with or without standard_html_[header|footer],
@@ -212,6 +215,6 @@
         #    return self.view(self, REQUEST)
         return OFS.Image.Image.index_html(self, REQUEST, RESPONSE)
 
-Globals.default__class_init__(Image)
+InitializeClass(Image)
 
 


=== CMF/CMFDefault/Link.py 1.24 => 1.25 ===
         self.remote_url = url
 
     security.declareProtected(ModifyPortalContent, 'edit')
-
     def edit(self, remote_url ):
         """ Update and reindex. """
         self._edit( remote_url )


=== CMF/CMFDefault/NewsItem.py 1.16 => 1.17 ===
 """
 """
 
-ADD_CONTENT_PERMISSION = 'Add portal content'
-
- 
-import Globals
-from Globals import HTMLFile, HTML
+from Globals import InitializeClass
 from Document import Document
 from utils import parseHeadersBody
 
@@ -97,5 +93,5 @@
         Document.edit( self, text_format, text )
 
 
-Globals.InitializeClass( NewsItem )
+InitializeClass( NewsItem )
 


=== CMF/CMFDefault/__init__.py 1.13 => 1.14 ===
 """
 """
 
-ADD_CONTENT_PERMISSION = 'Add portal content'
-
 from AccessControl import ModuleSecurityInfo
 
 prod_security = ModuleSecurityInfo( 'Products' )
@@ -31,10 +29,14 @@
 import RegistrationTool, URLTool, DublinCore, DiscussionTool
 import SyndicationTool
 from Products.CMFCore import utils
+from Products.CMFCore.CMFCorePermissions import AddPortalContent
 import Products.CMFCore
 from Products.CMFCore.DirectoryView import registerDirectory
 import DefaultWorkflow
 
+# Old name that some third-party packages may need.
+ADD_CONTENT_PERMISSION = AddPortalContent
+
 
 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 #   N.B.:  The following symbol controls whether we "inject" the
@@ -121,7 +123,7 @@
 
     utils.ContentInit( 'CMFDefault Content'
                      , content_types=contentClasses
-                     , permission=ADD_CONTENT_PERMISSION
+                     , permission=AddPortalContent
                      , extra_constructors=contentConstructors
                      , fti=Portal.factory_type_information
                      ).initialize( context )