Skip to content

Commit

Permalink
Merge pull request #6 from plone/datakurre-missing-aq-wrapper
Browse files Browse the repository at this point in the history
Ensure that draft target is acquisition wrapped
  • Loading branch information
datakurre committed Jul 3, 2017
2 parents 31188b6 + 34d80e3 commit 189ea1b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -4,8 +4,8 @@ Changelog
1.1.2 (unreleased)
------------------

- Nothing changed yet.

- Fix issue where draft sync failed because draft might have been withotu aq wrapper
[datakurre]

1.1.1 (2016-09-09)
------------------
Expand Down
2 changes: 1 addition & 1 deletion plone/app/drafts/__init__.py
Expand Up @@ -3,8 +3,8 @@
from plone.app.drafts.interfaces import IDrafting
from plone.app.drafts.lifecycle import syncDraftOnSave
from plone.uuid.interfaces import IUUID
from zope.globalrequest import getRequest
from zope import event
from zope.globalrequest import getRequest
from zope.lifecycleevent import ObjectModifiedEvent


Expand Down
1 change: 1 addition & 0 deletions plone/app/drafts/dexterity.py
Expand Up @@ -281,6 +281,7 @@ def save(event):
draft = getCurrentDraft(event.action.form.request)
target = getattr(draft, '_draftAddFormTarget', None)
if target:
target = target.__of__(event.action.form.context)
syncDraftOnSave(target, event)
else:
discardDraftsOnCancel(event.action.form.context, event)
Expand Down
34 changes: 17 additions & 17 deletions plone/app/drafts/interfaces.py
Expand Up @@ -17,9 +17,9 @@ class IDraft(Interface):
to it as required.
"""

_draftUserId = schema.TextLine(title=u"User id")
_draftTargetKey = schema.TextLine(title=u"Target object key")
__name__ = schema.TextLine(title=u"Unique draft name")
_draftUserId = schema.TextLine(title=u'User id')
_draftTargetKey = schema.TextLine(title=u'Target object key')
__name__ = schema.TextLine(title=u'Unique draft name')


class IDraftStorage(Interface):
Expand All @@ -29,18 +29,18 @@ class IDraftStorage(Interface):
"""

enabled = schema.Bool(
title=u"Whether drafting is enabled",
title=u'Whether drafting is enabled',
default=True,
)

drafts = schema.Dict(
title=u"Drafts",
description=u"Use the methods below to inspect and manipulate this",
key_type=schema.TextLine(title=u"User id"),
title=u'Drafts',
description=u'Use the methods below to inspect and manipulate this',
key_type=schema.TextLine(title=u'User id'),
value_type=schema.Dict(
key_type=schema.TextLine(title=u"Draft target key"),
key_type=schema.TextLine(title=u'Draft target key'),
value_type=schema.Dict(
key_type=schema.TextLine(title=u"Draft name"),
key_type=schema.TextLine(title=u'Draft name'),
value_type=schema.Object(schema=IDraft),
),
),
Expand Down Expand Up @@ -147,18 +147,18 @@ class ICurrentDraftManagement(Interface):
been set.
"""

userId = schema.TextLine(title=u"Current user id")
targetKey = schema.TextLine(title=u"Current target key")
draftName = schema.TextLine(title=u"Current draft name")
userId = schema.TextLine(title=u'Current user id')
targetKey = schema.TextLine(title=u'Current target key')
draftName = schema.TextLine(title=u'Current draft name')
path = schema.TextLine(
title=u"Path prefix in which the data should be retained")
title=u'Path prefix in which the data should be retained')
defaultPath = schema.TextLine(
title=u"Default path prefix for this request", readonly=True)
title=u'Default path prefix for this request', readonly=True)

draft = schema.Object(
title=u"Current draft",
description=u"If userId, targetKey and draftName are set, the "
u"draft will be lazily fetched from the storage",
title=u'Current draft',
description=u'If userId, targetKey and draftName are set, the '
u'draft will be lazily fetched from the storage',
schema=IDraft,
)

Expand Down
6 changes: 3 additions & 3 deletions plone/app/drafts/storage.py
Expand Up @@ -41,13 +41,13 @@ def createDraft(self, userId, targetKey, factory=None):
draft = factory(userId, targetKey)

if not draft.__name__:
draft.__name__ = u"draft"
draft.__name__ = u'draft'

if draft.__name__ in container:
idx = len(container)
while u"{0}-{1}".format(draft.__name__, idx, ) in container:
while u'{0}-{1}'.format(draft.__name__, idx, ) in container:
idx += 1
draft.__name__ = u"{0}-{1}".format(draft.__name__, idx, )
draft.__name__ = u'{0}-{1}'.format(draft.__name__, idx, )

container[draft.__name__] = draft
return draft
Expand Down
1 change: 1 addition & 0 deletions plone/app/drafts/testing.py
Expand Up @@ -114,6 +114,7 @@ def setUpPloneSite(self, portal):
fti.global_allow = True
portal.portal_types._setObject('MyDocument', fti)


DRAFTS_DX_FIXTURE = DexterityDraftingLayer()
DRAFTS_DX_INTEGRDXION_TESTING = IntegrationTesting(
bases=(DRAFTS_DX_FIXTURE,), name='Drafts:DX:Integration')
Expand Down
17 changes: 16 additions & 1 deletion plone/app/drafts/tests.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.drafts.draft import Draft
from plone.app.drafts.interfaces import DRAFT_NAME_KEY
from plone.app.drafts.interfaces import ICurrentDraftManagement
from plone.app.drafts.interfaces import IDraft
from plone.app.drafts.interfaces import IDrafting
Expand All @@ -20,6 +21,7 @@
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import TEST_USER_PASSWORD
from plone.dexterity.utils import createContent
from plone.protect.authenticator import createToken
from plone.testing.z2 import Browser
from plone.uuid.interfaces import IUUID
Expand Down Expand Up @@ -1180,6 +1182,19 @@ def test_add_to_portal_root_save(self):
browser.cookies.forURL(browser.url),
)

# Simulate save action for creating a draft
storage = queryUtility(IDraftStorage)
draft = storage.createDraft(TEST_USER_ID, '++add++MyDocument')
target = createContent('MyDocument')
draft._draftAddFormTarget = target
transaction.commit()

browser.cookies.create(
DRAFT_NAME_KEY,
u'draft',
path='/plone'
)

# We can now fill in the required fields and save. The cookies should
# expire.

Expand Down Expand Up @@ -1219,7 +1234,7 @@ def test_add_to_folder(self):
cookies['plone.app.drafts.path']
)
self.assertEqual( # noqa
'"{}"'.format(IUUID(self.folder)),
'"{0}"'.format(IUUID(self.folder)),
cookies['plone.app.drafts.targetKey'],
)
self.assertNotIn(
Expand Down
1 change: 1 addition & 0 deletions test-4.x.cfg
Expand Up @@ -17,5 +17,6 @@ flake8-ignore = E501,C901

[versions]
setuptools =
zc.buildout =
coverage = >=3.7
plone.tiles =
2 changes: 2 additions & 0 deletions test-5.x.cfg
Expand Up @@ -17,5 +17,7 @@ flake8-ignore = E501,C901

[versions]
setuptools =
zc.buildout =
coverage = >=3.7
plone.tiles =
plone.app.drafts =

0 comments on commit 189ea1b

Please sign in to comment.