[CMF-checkins] CVS: Products/CMFCore - CMFCorePermissions.py:1.14.10.3 PortalFolder.py:1.45.4.9

Tres Seaver tseaver at zope.com
Mon Aug 9 12:33:44 EDT 2004


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv29799/CMFCore

Modified Files:
      Tag: CMF-1_4-branch
	CMFCorePermissions.py PortalFolder.py 
Log Message:


 - CMFCore.PortalFolder: Enforce check of "Delete objects" permission
   during cut + paste. (http://zope.org/Collectors/259)

   N.B.  This fix depends on an update to the underlying Zope software,
         e.g., Zope 2.7.3 or later.  Two new unit tests fail on
         Zope 2.7.2 and earlier.


=== Products/CMFCore/CMFCorePermissions.py 1.14.10.2 => 1.14.10.3 ===
--- Products/CMFCore/CMFCorePermissions.py:1.14.10.2	Fri Apr 23 17:11:33 2004
+++ Products/CMFCore/CMFCorePermissions.py	Mon Aug  9 12:33:14 2004
@@ -24,6 +24,7 @@
 # General Zope permissions
 View = Permissions.view
 AccessContentsInformation = Permissions.access_contents_information
+DeleteObjects = Permissions.delete_objects
 UndoChanges = Permissions.undo_changes
 ChangePermissions = Permissions.change_permissions
 ViewManagementScreens = Permissions.view_management_screens


=== Products/CMFCore/PortalFolder.py 1.45.4.8 => 1.45.4.9 ===
--- Products/CMFCore/PortalFolder.py:1.45.4.8	Wed Aug  4 06:22:05 2004
+++ Products/CMFCore/PortalFolder.py	Mon Aug  9 12:33:14 2004
@@ -23,6 +23,7 @@
 from CMFCorePermissions import ListFolderContents
 from CMFCorePermissions import AddPortalFolders
 from CMFCorePermissions import AddPortalContent
+from CMFCorePermissions import DeleteObjects
 from CMFCatalogAware import CMFCatalogAware
 from OFS.Folder import Folder
 from OFS.ObjectManager import REPLACEABLE
@@ -139,7 +140,7 @@
     def manage_addPortalFolder(self, id, title='', REQUEST=None):
         """Add a new PortalFolder object with id *id*.
         """
-        ob=PortalFolder(id, title)
+        ob = PortalFolder(id, title)
         self._setObject(id, ob)
         if REQUEST is not None:
             return self.folder_contents( # XXX: ick!
@@ -413,76 +414,94 @@
         # It enables the clipboard to function correctly
         # with objects created by a multi-factory.
         securityChecksDone = 0
-        if (hasattr(object, '__factory_meta_type__') and
-            hasattr(self, 'all_meta_types')):
-            mt = object.__factory_meta_type__
+
+        sm = getSecurityManager()
+        parent = aq_parent(aq_inner(object))
+        object_id = object.getId()
+        mt = getattr(object, '__factory_meta_type__', None)
+        meta_types = getattr(self, 'all_meta_types', None)
+
+        if mt is not None and meta_types is not None:
+
             method_name=None
             permission_name = None
-            meta_types = self.all_meta_types
-            if callable(meta_types): meta_types = meta_types()
+
+            if callable(meta_types):
+                meta_types = meta_types()
+
             for d in meta_types:
+
                 if d['name']==mt:
+
                     method_name=d['action']
                     permission_name = d.get('permission', None)
                     break
 
             if permission_name is not None:
-                if _checkPermission(permission_name,self):
-                    if not validate_src:
-                        # We don't want to check the object on the clipboard
-                        securityChecksDone = 1
-                    else:
-                        try: parent = aq_parent(aq_inner(object))
-                        except: parent = None
-                        if getSecurityManager().validate(None, parent,
-                                                         None, object):
-                            # validation succeeded
-                            securityChecksDone = 1
-                        else:
-                            raise 'Unauthorized', object.getId()
-                else:
-                    raise 'Unauthorized', permission_name
+
+                if not sm.checkPermission(permission_name,self):
+                    raise Unauthorized, method_name
+
+                if validate_src:
+                
+                    if not sm.validate(None, parent, None, object):
+                        raise Unauthorized, object_id
+
+                if validate_src > 1:
+                    if not sm.checkPermission(DeleteObjects, parent):
+                        raise Unauthorized
+
+                # validation succeeded
+                securityChecksDone = 1
             #
             # Old validation for objects that may not have registered 
             # themselves in the proper fashion.
             #
             elif method_name is not None:
-                meth=self.unrestrictedTraverse(method_name)
-                if hasattr(meth, 'im_self'):
-                    parent = meth.im_self
-                else:
-                    try:    parent = aq_parent(aq_inner(meth))
-                    except: parent = None
-                if getSecurityManager().validate(None, parent, None, meth):
-                    # Ensure the user is allowed to access the object on the
-                    # clipboard.
-                    if not validate_src:
-                        securityChecksDone = 1
-                    else:
-                        try: parent = aq_parent(aq_inner(object))
-                        except: parent = None
-                        if getSecurityManager().validate(None, parent,
-                                                         None, object):
-                            securityChecksDone = 1
-                        else:
-                            raise 'Unauthorized', object.getId()
-                else:
-                    raise 'Unauthorized', method_name
+
+                meth = self.unrestrictedTraverse(method_name)
+
+                factory = getattr(meth, 'im_self', None)
+
+                if factory is None:
+                    factory = aq_parent(aq_inner(meth))
+
+                if not sm.validate(None, factory, None, meth):
+                    raise Unauthorized, method_name
+
+                # Ensure the user is allowed to access the object on the
+                # clipboard.
+                if validate_src:
+
+                    if not sm.validate(None, parent, None, object):
+                        raise Unauthorized, object_id
+
+                if validate_src > 1: # moving
+                    if not sm.checkPermission(DeleteObjects, parent):
+                        raise Unauthorized
+
+                securityChecksDone = 1
 
         # Call OFS' _verifyObjectPaste if necessary
         if not securityChecksDone:
+
             PortalFolder.inheritedAttribute(
                 '_verifyObjectPaste')(self, object, validate_src)
 
         # Finally, check allowed content types
-        if hasattr(aq_base(object), '_getPortalTypeName'):
-            contentType = object._getPortalTypeName()
-            if contentType is not None:
+        content_type = getattr(aq_base(object), '_getPortalTypeName', None)
+        if content_type is not None:
+
+            content_type = content_type()
+
+            if content_type is not None:
+
                 pt = getToolByName(self, 'portal_types')
                 myType = pt.getTypeInfo(self)
-                if myType is not None and not myType.allowType(contentType):
-                    raise ValueError, \
-                          "Disallowed to paste subobject type '%s'." % contentType
+
+                if myType is not None and not myType.allowType(content_type):
+                    raise ValueError(
+                          "Cannot paste subobject type '%s'." % content_type )
 
     security.setPermissionDefault(AddPortalContent, ('Owner','Manager'))
     security.setPermissionDefault(AddPortalFolders, ('Owner','Manager'))



More information about the CMF-checkins mailing list