Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effective date not set #761

Merged
merged 3 commits into from Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/760.bugfix
@@ -0,0 +1 @@
Set effective_date and reindex obj on workflow transitions. [wkbkhard]
5 changes: 5 additions & 0 deletions src/plone/restapi/services/workflow/transition.py
Expand Up @@ -16,6 +16,7 @@
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound
from DateTime import DateTime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordering of imports does not conform to the Plone style guide (https://docs.plone.org/develop/styleguide/python.html#grouping-and-sorting). But that was already the case before that change.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into this...


import plone.protect.interfaces

Expand Down Expand Up @@ -105,6 +106,10 @@ def recurse_transition(
)
deserializer(data=publication_dates)

if obj.EffectiveDate() == 'None':
obj.setEffectiveDate(DateTime())
obj.reindexObject()

self.wftool.doActionFor(obj, self.transition, comment=comment)
if include_children and IFolderish.providedBy(obj):
self.recurse_transition(
Expand Down
10 changes: 10 additions & 0 deletions src/plone/restapi/tests/test_workflow.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
from ZPublisher.pubevents import PubStart
from base64 import b64encode
Expand Down Expand Up @@ -126,6 +127,15 @@ def test_transition_action_succeeds(self):
u"published", self.wftool.getInfoFor(self.portal.doc1, u"review_state")
)

def test_transition_action_succeeds_changes_effective(self):
doc1 = self.portal.doc1
self.assertEqual(doc1.effective_date, None)
now = DateTime()
service = self.traverse('/plone/doc1/@workflow/publish')
service.reply()
self.assertTrue(isinstance(doc1.effective_date, DateTime))
self.assertTrue(doc1.effective_date >= now)

def test_calling_endpoint_without_transition_gives_400(self):
service = self.traverse("/plone/doc1/@workflow")
res = service.reply()
Expand Down