Repository navigation
Conversation
plone.exportimport restores workflow state by assigning workflow_history directly. That fires no transition, so besides the stale catalog entries the exportimport patch already repairs, it skips updateRoleMappingsFor: an additional workflow's permission map is never applied, and the object keeps the security of its initial state. The example Profile imported as active kept the roles pending grants for "Manage membership", Reviewer instead of Owner. The patch now also calls update_role_mappings(), which runs updateRoleMappingsFor for every workflow in the object's chain and reindexes the object's security when a mapping changed, as a transition's _reindexWorkflowVariables would. WorkflowTool only offers the site-wide updateRoleMappings(), so iterating the object's own chain is the targeted equivalent. Like reindex_workflow_variables(), it is shaped to move into update_workflow_history upstream unchanged. Tests: the functional import test asserts the imported state's roles, the spike asserts the unpatched import keeps the initial state's, and an integration class covers update_role_mappings() on a history written by hand, including when security is and is not reindexed. The docs no longer say a real transition would wrongly rewrite role mappings, describe the patch as covering permissions too, and tell sites with content imported before this fix to run updateRoleMappings on portal_workflow. Closes #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Imported content now gets the role mappings of the state its workflow history restores, rather than those of each workflow's initial state.
Why
plone.exportimportrestores workflow state by assigningworkflow_historydirectly. That fires no transition, and a transition does two things once it records a status:updateRoleMappingsForapplies the state's permission map, and_reindexWorkflowVariablescatalogs the workflow variables and the object's security. This package'sexportimportpatch already repaired the catalog entries. The role mappings were still skipped.The publication workflow escapes, because
update_review_stateruns a real transition just before. An additional workflow does not. On this package's own demo content,ortegasis imported asactivein the membership workflow, yet it kept the rolespendinggrants for "Manage membership": Reviewer instead of Owner.As the issue describes, a site whose own subscribers recompute role mappings on modification repairs individual objects whenever a later event reaches them, such as a child being created inside an imported container. That is what makes the bug look intermittent.
Changes
exportimport.update_role_mappings(obj)runsupdateRoleMappingsForfor each workflow ingetWorkflowsFor(obj), and callsreindexObjectSecurity()when any mapping changed, as a transition would.WorkflowToolonly offers the site-wideupdateRoleMappings(), so iterating the object's own chain is the targeted equivalent. Likereindex_workflow_variables(), it is written to move intoupdate_workflow_historyupstream unchanged.update_workflow_historywrapper calls it before the existing reindex, and only for items that carry aworkflow_history.update_review_statehas already transitioned that workflow.The fix proposed in the issue updated the mappings only. This one also reindexes the object's security when a mapping changed; without that, a workflow managing
Viewwould leaveallowedRolesAndUsersstale and search results wrong.Documentation
portal_workflow.updateRoleMappings(), the Update security settings button in the Zope Management Interface, as well as the reindex.News fragments
backend/news/6.bugfix.mdnews/6.documentation.mdTesting
make testmake mypyruff check,ruff format,zpretty --check srcmake html(clean build)make valeactiveroles.update_workflow_historyunwrapped through__wrapped__, the same import keeps thependingroles. That proves the demo content reproduces update_workflow_history restores state without updating role mappings #6 and the patch is load-bearing, and it goes red once upstream fixes the importer.update_role_mappings()on a history written by hand, the way the importer writes it: the stale premise, the restored mappings, the publication workflow'sViewmapping left unchanged, the return value, and security reindexed exactly once when a mapping changed and not at all when nothing did.Closes #6