Skip to content

Commit

Permalink
Merge fb94734 into ba9f5ae
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Jan 6, 2022
2 parents ba9f5ae + fb94734 commit c96f083
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -11,6 +11,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.4 (unreleased)
----------------

- Enable WebDAV PUT factories to change a newly created object's ID
(`#997 <https://github.com/zopefoundation/Zope/issues/997>`_)

- Fix potential race condition in ``App.version_txt.getZopeVersion``
(`#999 <https://github.com/zopefoundation/Zope/issues/999>`_)

Expand Down
3 changes: 3 additions & 0 deletions src/webdav/NullResource.py
Expand Up @@ -184,6 +184,9 @@ def PUT(self, REQUEST, RESPONSE):
(ob.__class__, repr(parent), sys.exc_info()[1],)
raise Unauthorized(sMsg)

# A PUT factory may have changed the object's ID
name = ob.getId() or name

# Delegate actual PUT handling to the new object,
# SDS: But just *after* it has been stored.
self.__parent__._setObject(name, ob)
Expand Down
17 changes: 17 additions & 0 deletions src/webdav/tests/testPUT_factory.py
Expand Up @@ -90,3 +90,20 @@ def testCollector2261(self):
'PUT factory should not acquire content')
# check for the newly created file
self.assertEqual(str(self.app.A.B.a), 'bar')

def testPUT_factory_changes_name(self):
# A custom PUT factory may want to change the object ID,
# for example to remove file name extensions.
from OFS.Image import File

def custom_put_factory(name, typ, body):
new_name = 'newname'
if not isinstance(body, bytes):
body = body.encode('UTF-8')
return File(new_name, '', body, content_type=typ)
self.app.folder.PUT_factory = custom_put_factory

request = self.app.REQUEST
put = request.traverse('/folder/doc')
put(request, request.RESPONSE)
self.assertTrue('newname' in self.folder.objectIds())

0 comments on commit c96f083

Please sign in to comment.