Roundtrip-safe DAV

Emiliano Heyns <[email protected]>
Newsgroups gmane.comp.web.zope.devel,gmane.comp.web.zope.coders
Message-ID <[email protected]>
Hello people,

I'm currently working with some content editors that would like to
keep their current WYSIWYG tools and use them in combination with
Zope/Plone, and using the DAV interface seemed like the best approach,
and it does indeed mostly work. One of the larger problems we face
using this approach is that quite a few products expose objects via
DAV that are not roundtrip-safe; getting-then-putting will result in
unwanted behaviour in some cases, and for other objects I don't see
much value in allowing them to be accessed over DAV (like the contents
of acl_users).

I wrote the attached monkey patch to address this (be kind, I'm pretty
new to Python), and Sidnei da Silva (author of DavPack) suggested I
post the patch on these lists to see if there was an interest into
this approach.

What it does is disable DAV access for non-collection resources in
general and then selectively turns it on for some (non-exhaustive)
list. Folderish objects are enabled by default but can be turned off.
Objects/classes can also disable or enable themselves by explicitly
setting __dav_resource__ to 0 or 1. I'm not suggesting this particular
list is the correct one.

Thoughts?

With kind regard,
Emiliano Heyns

_______________________________________________
Zope-Dev maillist  -  [email protected]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )
__init__.py (application/octet-stream, 9.2 KB)
##############################################################################
#
# SafeDAV -- A set of patches to limit DAV access to those objects that
#            can safely/usefully be edited through DAV (i.e. acl_users and
#            its content would be excluded
# Copyright (C) 2004 Iris Advies
#               [email protected]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Some portions of this module are Copyright Zope Corporation and
# Contributors.
# The original copyright statement is reproduced below.
#
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id$
"""

from zLOG import LOG, INFO

def safeToList(x):
   return (hasattr(x, '__dav_resource__') and x.__dav_resource__ != 0)

def listDAVObjects(self):
   objectValues = getattr(self, 'objectValues', None)
   if objectValues is not None:
      return filter(safeToList, objectValues())
   return []

def log(msg):
   LOG('SafeDAV', INFO, msg)

from App.version_txt import getZopeVersion, version_txt
zope_version = getZopeVersion()
str_version = version_txt().split()[1].strip(',')
if not zope_version < (2, 7, 4):
   log('Zope %s. Patches *NOT* applied.' % str_version)
else:
   log('Zope %s. Applying patches.' % str_version)

   from webdav.Resource import Resource
   from webdav.Collection import Collection

   del Resource.__dav_resource__
   log('General DAV Resource patched')

   Collection.__dav_resource__ = 1
   Collection.listDAVObjects = listDAVObjects
   log('General DAV Collection patched')

   # enable some resources
   try:
      from Products.CMFDefault.Document import Document
   except:
      log('CMFDefault.Document not found, not patching')
   else:
      Document.__dav_resource__ = 1
      log('CMFDefault.Document patched')

   try:
      from Products.CMFDefault.Image import Image
   except:
      log('CMFDefault.Image not found, not patching')
   else:
      Image.__dav_resource__ = 1
      log('CMFDefault.Image patched')

   try:
      from Products.CMFDefault.File import File
   except:
      log('CMFDefault.File not found, not patching')
   else:
      File.__dav_resource__ = 1
      log('CMFDefault.File patched')

   try:
      from Products.CMFPhoto.Photo import Photo
   except:
      log('CMFPhoto.Photo not found, not patching')
   else:
      Photo.__dav_resource__ = 1
      log('CMFPhoto.Photo patched')

   # disable some collections
   try:
      from App.ApplicationManager import ApplicationManager
   except:
      log('App.ApplicationManager not found, not patching')
   else:
      ApplicationManager.__dav_resource__ = 0
      log('App.ApplicationManager patched')

   try:
      from Products.Archetypes.ArchetypeTool import ArchetypeTool
   except:
      log('Products.Archetypes.ArchetypeTool not found, not patching')
   else:
      ArchetypeTool.__dav_resource__ = 0
      log('Products.Archetypes.ArchetypeTool patched')

   try:
      from Products.Archetypes.ArchTTWTool import ArchTTWTool
   except:
      log('Products.Archetypes.ArchTTWTool not found, not patching')
   else:
      ArchTTWTool.__dav_resource__ = 0
      log('Products.Archetypes.ArchTTWTool patched')

   try:
      from Products.CMFBoard.ForumFolder import ForumFolder
   except:
      log('Products.CMFBoard.ForumFolder not found, not patching')
   else:
      ForumFolder.__dav_resource__ = 0
      log('Products.CMFBoard.ForumFolder patched')

   try:
      from Products.CMFCore.ActionsTool import ActionsTool
   except:
      log('Products.CMFCore.ActionsTool not found, not patching')
   else:
      ActionsTool.__dav_resource__ = 0
      log('Products.CMFCore.ActionsTool patched')

   try:
      from Products.CMFCore.SkinsTool import SkinsTool
   except:
      log('Products.CMFCore.SkinsTool not found, not patching')
   else:
      SkinsTool.__dav_resource__ = 0
      log('Products.CMFCore.SkinsTool patched')

   try:
      from Products.CMFCore.TypesTool import TypesTool
   except:
      log('Products.CMFCore.TypesTool not found, not patching')
   else:
      TypesTool.__dav_resource__ = 0
      log('Products.CMFCore.TypesTool patched')

   try:
      from Products.CMFCore.WorkflowTool import WorkflowTool
   except:
      log('Products.CMFCore.WorkflowTool not found, not patching')
   else:
      WorkflowTool.__dav_resource__ = 0
      log('Products.CMFCore.WorkflowTool patched')

   try:
      from Products.CMFCore.CatalogTool import CatalogTool
   except:
      log('Products.CMFCore.CatalogTool not found, not patching')
   else:
      CatalogTool.__dav_resource__ = 0
      log('Products.CMFCore.CatalogTool patched')

   try:
      from Products.CMFPlone.FactoryTool import FactoryTool
   except:
      log('Products.CMFPlone.FactoryTool not found, not patching')
   else:
      FactoryTool.__dav_resource__ = 0
      log('Products.CMFPlone.FactoryTool patched')

   try:
      from Products.CMFPlone.PropertiesTool import PropertiesTool
   except:
      log('Products.CMFPlone.PropertiesTool not found, not patching')
   else:
      PropertiesTool.__dav_resource__ = 0
      log('Products.CMFPlone.PropertiesTool patched')

   try:
      from Products.CMFPlone.PloneControlPanel import PloneControlPanel
   except:
      log('Products.CMFPlone.PloneControlPanel not found, not patching')
   else:
      PloneControlPanel.__dav_resource__ = 0
      log('Products.CMFPlone.PloneControlPanel patched')

   try:
      from Products.CMFTopic.Topic import Topic
   except:
      log('Products.CMFTopic.Topic not found, not patching')
   else:
      Topic.__dav_resource__ = 0
      log('Products.CMFTopic.Topic patched')

   try:
      from Products.DCWorkflow.ContainerTab import ContainerTab
   except:
      log('Products.DCWorkflow.ContainerTab not found, not patching')
   else:
      ContainerTab.__dav_resource__ = 0
      log('Products.DCWorkflow.ContainerTab patched')

   try:
      from Products.DCWorkflow.DCWorkflow import DCWorkflow
   except:
      log('Products.DCWorkflow.DCWorkflow not found, not patching')
   else:
      DCWorkflow.__dav_resource__ = 0
      log('Products.DCWorkflow.DCWorkflow patched')

   try:
      from Products.GroupUserFolder.GRUFFolder import GRUFFolder
   except:
      log('Products.GroupUserFolder.GRUFFolder not found, not patching')
   else:
      GRUFFolder.__dav_resource__ = 0
      log('Products.GroupUserFolder.GRUFFolder patched')

   try:
      from Products.GroupUserFolder.GroupUserFolder import GroupUserFolder
   except:
      log('Products.GroupUserFolder.GroupUserFolder not found, not patching')
   else:
      GroupUserFolder.__dav_resource__ = 0
      log('Products.GroupUserFolder.GroupUserFolder patched')

   try:
      from Products.PlacelessTranslationService.PlacelessTranslationService import PlacelessTranslationService
   except:
      log('Products.PlacelessTranslationService.PlacelessTranslationService not found, not patching')
   else:
      PlacelessTranslationService.__dav_resource__ = 0
      log('Products.PlacelessTranslationService.PlacelessTranslationService patched')

   try:
      from Products.PortalTransforms.zope.MimeTypesTool import MimeTypesTool
   except:
      log('Products.PortalTransforms.zope.MimeTypesTool not found, not patching')
   else:
      MimeTypesTool.__dav_resource__ = 0
      log('Products.PortalTransforms.zope.MimeTypesTool patched')

   try:
      from Products.PortalTransforms.zope.TransformTool import TransformTool
   except:
      log('Products.PortalTransforms.zope.TransformTool not found, not patching')
   else:
      TransformTool.__dav_resource__ = 0
      log('Products.PortalTransforms.zope.TransformTool patched')

   try:
      from Products.CMFQuickInstallerTool.QuickInstallerTool import QuickInstallerTool
   except:
      log('Products.CMFQuickInstallerTool.QuickInstallerTool not found, not patching')
   else:
      QuickInstallerTool.__dav_resource__ = 0
      log('Products.CMFQuickInstallerTool.QuickInstallerTool patched')

   try:
      from Products.ZCatalog.ZCatalog import ZCatalog
   except:
      log('Products.ZCatalog.ZCatalog not found, not patching')
   else:
      ZCatalog.__dav_resource__ = 0
      log('Products.ZCatalog.ZCatalog patched')
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.