Setting review_state *quick* programmatically?

As part of a migration we need to set arbitrary review states on arbitrary content objects. The workflows in the old and new system are identical. So is there a quick way to assign a review state (including the related security settings) to an object without performing one or more workflow transitions? I remember that there was a quick and dirty way for doing this...any pointers?

If the workflow definition contains the setting manager_bypass="True" you can set the review state without a transition.

We often use the plone.app.workflow.remap.remap_workflow to switch workflows for content types. This function contains the following lines:

// ...
new_status = {'action': None,
              'actor': None,
              'comments': 'State remapped from control panel',
              'review_state': state_map.get(old_state, new_wf.initial_state),
              'time': DateTime()}
portal_workflow.setStatusOf(new_wf_name, obj, new_status)

# Trigger any automatic transitions, or else just make sure the role mappings are right
auto_transition = new_wf._findAutomaticTransition(obj, new_wf._getWorkflowStateOf(obj))
if auto_transition is not None:
    new_wf._changeStateOf(obj, auto_transition)
else:
    new_wf.updateRoleMappingsFor(obj)

and then a

obj.reindexObject(idxs=['allowedRolesAndUsers', 'review_state'])

That should be all you need.

1 Like

Maybe you could use plone.api.

Something like:

api.content.transition(obj=my_item, transition=new_state)

Should be

api.content.transition(obj=my_item, to_state=new_state)

But this only works if there is an auto transition available, or by setting manager_bypass="True" in the workflow definition.

Using plone.restapi with workflow is only sanely usable when you know the configuration of the underlying workflows:

You didn't mention to use the restapi before :wink:

Use portal_workflow:


(well, write a custom rest endpoint, should be trivial)

should not be the new state, but like this (I think):

`transition='publish')`