Skip to content

Reapply role mappings when importing workflow history - #12

Merged
ericof merged 1 commit into
mainfrom
issue-6
Sep 13, 2026
Merged

ericof merged 1 commit into
mainfrom
issue-6

Conversation

@ericof

@ericof ericof commented Sep 13, 2026

Copy link
Copy Markdown
Member

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.exportimport restores workflow state by assigning workflow_history directly. That fires no transition, and a transition does two things once it records a status: updateRoleMappingsFor applies the state's permission map, and _reindexWorkflowVariables catalogs the workflow variables and the object's security. This package's exportimport patch already repaired the catalog entries. The role mappings were still skipped.

The publication workflow escapes, because update_review_state runs a real transition just before. An additional workflow does not. On this package's own demo content, ortegas is imported as active in the membership workflow, yet it kept the roles pending grants 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) runs updateRoleMappingsFor for each workflow in getWorkflowsFor(obj), and calls reindexObjectSecurity() when any mapping changed, as a transition 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 written to move into update_workflow_history upstream unchanged.
  • The update_workflow_history wrapper calls it before the existing reindex, and only for items that carry a workflow_history.
  • Single-workflow sites see no change: update_review_state has 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 View would leave allowedRolesAndUsers stale and search results wrong.

Documentation

  • Concept page: no longer says a real transition would wrongly rewrite role mappings, and explains that import skips them too.
  • "Add to an existing site" how-to: content imported before this fix needs portal_workflow.updateRoleMappings(), the Update security settings button in the Zope Management Interface, as well as the reindex.
  • Catalog, profiles, and API references: describe the patch as covering permissions as well as the index.

News fragments

  • backend/news/6.bugfix.md
  • news/6.documentation.md

Testing

Check Result
make test 280 passed
make mypy no issues
ruff check, ruff format, zpretty --check src clean
make html (clean build) build succeeded, no warnings
make vale 0 errors, 39 warnings, all pre-existing
  • Functional: the imported demo Profile has the active roles.
  • Spike: with update_workflow_history unwrapped through __wrapped__, the same import keeps the pending roles. 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.
  • Integration: update_role_mappings() on a history written by hand, the way the importer writes it: the stale premise, the restored mappings, the publication workflow's View mapping left unchanged, the return value, and security reindexed exactly once when a mapping changed and not at all when nothing did.

Closes #6

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
@ericof
ericof merged commit fffa985 into main Sep 13, 2026
20 checks passed
@ericof
ericof deleted the issue-6 branch September 13, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update_workflow_history restores state without updating role mappings

1 participant