From b72eff1ab4c2a82ba98135c0ba3fdfbfb7934d1a Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Fri, 3 Jul 2020 11:42:39 +0900 Subject: [PATCH] testWebDAVSupport: Fix failures due to 21becf4c. WebDAVSupport module was migrated to ZODB Components in 21becf4c. This module contains a monkey patch (5c7d50d5) on webdav.NullResource.PUT which should really be in Products.ERP5Type.patches and was not applied anymore since the migration. --- .../module.erp5.WebDAVSupport.py | 47 ------------------- product/ERP5Type/patches/WebDAV.py | 42 +++++++++++++++++ 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py b/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py index d04398fe35..954818bca6 100644 --- a/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py +++ b/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py @@ -142,50 +142,3 @@ class TextContent: return len(self.manage_FTPget()) InitializeClass(TextContent) - -from webdav.common import Locked, PreconditionFailed -from webdav.interfaces import IWriteLock -from webdav.NullResource import NullResource -NullResource_PUT = NullResource.PUT - -def PUT(self, REQUEST, RESPONSE): - """Create a new non-collection resource. - """ - if getattr(self.__parent__, 'PUT_factory', None) is not None: # BBB - return NullResource_PUT(self, REQUEST, RESPONSE) - - self.dav__init(REQUEST, RESPONSE) - if REQUEST.environ['REQUEST_METHOD'] != 'PUT': - raise Forbidden, 'REQUEST_METHOD should be PUT.' - - name = self.__name__ - parent = self.__parent__ - - ifhdr = REQUEST.get_header('If', '') - if IWriteLock.providedBy(parent) and parent.wl_isLocked(): - if ifhdr: - parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1) - else: - # There was no If header at all, and our parent is locked, - # so we fail here - raise Locked - elif ifhdr: - # There was an If header, but the parent is not locked - raise PreconditionFailed - - # <ERP5> - # XXX: Do we really want to force 'id' - # when PUT is called on Contribution Tool ? - kw = {'id': name, 'data': None, 'filename': name} - contribution_tool = parent.getPortalObject().portal_contributions - if aq_base(contribution_tool) is not aq_base(parent): - kw.update(container=parent, discover_metadata=False) - ob = contribution_tool.newContent(**kw) - # </ERP5> - - ob.PUT(REQUEST, RESPONSE) - RESPONSE.setStatus(201) - RESPONSE.setBody('') - return RESPONSE - -NullResource.PUT = PUT diff --git a/product/ERP5Type/patches/WebDAV.py b/product/ERP5Type/patches/WebDAV.py index 67929105b8..c97a45e3c1 100644 --- a/product/ERP5Type/patches/WebDAV.py +++ b/product/ERP5Type/patches/WebDAV.py @@ -62,3 +62,45 @@ def MKCOL(self, REQUEST, RESPONSE): from webdav.NullResource import NullResource NullResource.MKCOL = MKCOL + +NullResource_PUT = NullResource.PUT +def PUT(self, REQUEST, RESPONSE): + """Create a new non-collection resource. + """ + if getattr(self.__parent__, 'PUT_factory', None) is not None: # BBB + return NullResource_PUT(self, REQUEST, RESPONSE) + + self.dav__init(REQUEST, RESPONSE) + if REQUEST.environ['REQUEST_METHOD'] != 'PUT': + raise Forbidden, 'REQUEST_METHOD should be PUT.' + + name = self.__name__ + parent = self.__parent__ + + ifhdr = REQUEST.get_header('If', '') + if IWriteLock.providedBy(parent) and parent.wl_isLocked(): + if ifhdr: + parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1) + else: + # There was no If header at all, and our parent is locked, + # so we fail here + raise Locked + elif ifhdr: + # There was an If header, but the parent is not locked + raise PreconditionFailed + + # <ERP5> + # XXX: Do we really want to force 'id' + # when PUT is called on Contribution Tool ? + kw = {'id': name, 'data': None, 'filename': name} + contribution_tool = parent.getPortalObject().portal_contributions + if aq_base(contribution_tool) is not aq_base(parent): + kw.update(container=parent, discover_metadata=False) + ob = contribution_tool.newContent(**kw) + # </ERP5> + + ob.PUT(REQUEST, RESPONSE) + RESPONSE.setStatus(201) + RESPONSE.setBody('') + return RESPONSE +NullResource.PUT = PUT -- 2.30.9