Repository navigation
Serialize workflow_states, label contributed workflows, and fix @history permissions and bare review_state queries - #11
Merged
Merged
Conversation
The backend is split into subpackages that each hold one kind of component: - collective.multiworkflow.utils.workflow holds the values of the workflow_states index: format_state, parse_state, WORKFLOW_STATES, STATE_SEPARATOR, and the new formatted_workflow_states. - collective.multiworkflow.indexers.workflow_states holds the indexer, and collective.multiworkflow.subscribers.reindex the transition subscriber that keeps it fresh. - The @workflow and @history services move to collective.multiworkflow.restapi.services, and the expandable workflow element to collective.multiworkflow.restapi.serializer. collective.multiworkflow.indexers re-exports the four value helpers, so code importing them from there, as the 1.0.0a1 documentation did, keeps working. The indexer itself is not re-exported: its name would shadow the submodule the ZCML registers it from. The move left two ZCML factories and several relative imports pointing at modules that no longer existed, which stopped the suite at collection. Those are fixed, the tests import from the new modules, the module docstrings lost with the old indexers package are restored, and the Python API reference, the how-to guides and the tutorial point at the new layout.
The @history service is registered with the CMFEditions.AccessPreviousVersions permission, but nothing in this package loaded the ZCML defining it. Whether it existed depended on load order: when another package included this one from its own dependencies.zcml before Products.CMFEditions was configured, the instance failed at startup with a ComponentLookupError. The same package loads fine in a test layer based on the Plone fixture, so the suite never showed it. dependencies.zcml now includes the permission definitions. Products.CMFEditions is already a dependency of Products.CMFPlone, so this adds no requirement. Closes #7
The serialization of every Dexterity object now carries a workflow_states key beside review_state: the object's state in every workflow of its chain, in the same <workflow-id>|<state-id> form and order as the catalog index. Summaries of catalog results carry it too, through an IJSONSummarySerializerMetadata utility that adds the workflow_states metadata column to the default fields. The key is added by wrapping SerializeToJson.__call__ on plone.restapi's own class rather than by registering a more specific adapter. An adapter would be bypassed by every serializer registered for a more specific interface; wrapping the method in place reaches SerializeFolderToJson, SerializeCollectionToJson and any add-on serializer derived from them through super(), and the order in which the packages' ZCML is loaded no longer matters. The patch follows the exportimport one: applied once, on import of the serializer subpackage, with the original method reachable as __wrapped__. Tests cover the patch installation, each of plone.restapi's serializer classes and a derived one, a historical version, brain summaries and a real HTTP request, plus a spike that fails once plone.restapi returns the key itself. On a site with plone.volto, Document is folderish and Folder and Collection are not globally addable, so the tests use a Link, a Document, and a Collection created past the add constraints. The REST API reference documents the key with generated examples, which pin the object's UID and effective date: both would otherwise change between runs or between time zones. Closes #8
ReviewStateModifier moved every parsed review_state query onto workflow_states and qualified bare state ids with the first workflow of the site's default chain. That answered correctly only for content types driven by that workflow: a collection written before the add-on was installed silently lost every item whose review_state comes from another workflow. A query is now moved only when one of its values names a workflow. Otherwise it is returned as it came, on review_state, whose index is still maintained exactly as before. A query mixing bare and qualified values still moves, with the bare ones qualified: the catalog intersects the results of different indexes, so splitting one criterion between the two would turn its "any of" into an "all of". The collection editor offers only qualified values, so a criterion saved from it targets workflow_states from then on. The new query builder test goes through parseAndModifyFormquery: parseFormquery alone does not apply IParsedQueryIndexModifier utilities. Closes #10
<plone:additionalworkflows /> accepts an optional label naming the workflow in the user interface in place of its title. The attribute is a MessageID field, so the label is a message id in the i18n_domain of the ZCML file declaring it. The label belongs to the workflow, not to the marker: the directive registers it as an IAdditionalWorkflowLabel utility named after the workflow id, and declaration.workflow_label() looks it up, falling back to the workflow's title. Two places use it: - the title of the workflow's @workflow chain entry, translated. Every Volto component already shows that title, so the frontend only gains an updated doc comment on the type; - the vocabulary of the Review state collection criterion. A directive with a label must list exactly one workflow, and raises ConfigurationError otherwise, since nothing would say which workflow the label names. Two directives labelling the same workflow conflict, as any two utilities registered under one name do. Closes #9
The backend now serializes workflow_states on every content object and on each catalog summary, but the Volto add-on had no way to read them: StateBadge, meant for listings, needed a full @workflow chain entry, which a listing could only get with one request per item. - New helpers mirroring the backend's utils.workflow: getWorkflowStates, getAdditionalWorkflowStates, parseWorkflowState and formatWorkflowState, with the WORKFLOW_STATE_SEPARATOR and WORKFLOW_STATES_VOCABULARY constants and the WorkflowStateValue, ParsedWorkflowState and WithWorkflowStates types. - StateBadge takes either a chain entry, as before, or a workflow_states value with an optional translated label, falling back to the state id. A value with no separator renders nothing. The label comes from the workflow states vocabulary, whose titles now name a workflow by its declared label, and which anyone who can view the context may read. A hook fetching those titles was left out: Volto's token-title request serializes the token list in a way not verified against plone.restapi here. Declared labels need no code change, since the backend reports them as the chain entry's title. The story fixtures gain a labelled membership workflow, used by new StateBadge and AdditionalWorkflowMenu stories and a StateBadge test, and the doc comments say where a title comes from. The Volto reference, the component customization how-to and the package readme describe the new exports. Refs #8 Refs #9
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
Closes four issues in six commits:
Products.CMFEditionspermissions are loaded before the@historyservice is registered.workflow_statesin ISerializeToJson and ISerializeToJsonSummary #8: the REST API serialization of every Dexterity object, and each summary of a catalog result, now carriesworkflow_states.<plone:additionalworkflows />accepts an optional, translatablelabel, shown in place of the workflow's title.review_stateif value not in the formatworkflow|review_state#10: areview_statecollection criterion that names no workflow stays on the stockreview_stateindex.workflow_states, so a listing can show every item's states, and its stories show a declared label.Why
#7. Whenever another add-on included this one from its
dependencies.zcmlbeforeProducts.CMFEditionswas configured, the instance failed at startup with aComponentLookupErrorforCMFEditions.AccessPreviousVersions. A test layer based on the Plone fixture loads CMFEditions first, so the suite never showed it.#8.
review_statewas the only state in the standard payloads. A client wanting every workflow's state had to call@workflowper object, or know to request theworkflow_statesmetadata column on a search. The values are already computed for the catalog; returning them with the object and with each search result makes a listing one request. On the Volto side,StateBadgewas meant for listings but needed a full@workflowchain entry, which a listing could only get with one request per item.#9. A workflow's title is set in its GenericSetup definition, shared by every type and behavior using it, and translated only through the
plonedomain. A label declared beside the contribution lets the package contributing the workflow choose what users see, translated in its own domain.#10. Bare state ids were qualified with the first workflow of the site's default chain. That answered correctly only for content types driven by that workflow, so a collection written before the add-on was installed could silently lose every item whose
review_statecomes from another workflow.Changes
Backend reorganization (0f020a4)
collective.multiworkflow.utils.workflowholds the values of theworkflow_statesindex:WORKFLOW_STATES,STATE_SEPARATOR,format_state,parse_state, and the newformatted_workflow_states.indexers.workflow_statesholds the indexer, andsubscribers.reindexthe transition subscriber that keeps it fresh.@workflowand@historyservices move torestapi.services, and the expandable workflow element torestapi.serializer.collective.multiworkflow.indexersre-exports the four value helpers, so code importing them from there, as the 1.0.0a1 documentation showed, keeps working. The indexer itself is not re-exported: its name would shadow the submodule the ZCML registers it from.Load the
@historypermission (#7, 73c7c94)dependencies.zcmlnow includes the permission definitions:Products.CMFEditionsis already a dependency ofProducts.CMFPlone, so this adds no requirement.workflow_statesin serializations (#8, cc7431b)The key sits beside
review_state, in the same form and order as the catalog index:SerializeToJson.__call__is wrapped in place rather than overridden by a more specific adapter. An adapter is bypassed by every serializer registered for a more specific interface; wrapping the method reachesSerializeFolderToJson,SerializeCollectionToJson, and any add-on serializer derived from them throughsuper(), whatever order the ZCML loads in. The patch follows theexportimportone: applied once, on import of the serializer subpackage, with the original reachable as__wrapped__.review_state.IJSONSummarySerializerMetadatautility adds theworkflow_statesmetadata column to the default fields, so@searchresults carry it withoutmetadata_fields.On a site with
plone.volto,Documentis folderish andFolderandCollectionare not globally addable. The tests therefore coverSerializeToJsonwith a Link,SerializeFolderToJsonwith a Document, andSerializeCollectionToJsonwith a Collection created past the add constraints, plus a serializer derived from them. A spike test calls the unwrapped method and fails onceplone.restapireturns the key itself, which is the signal to drop the patch.A label on the
additionalworkflowsdirective (#9, e3ee6fe)labelis aMessageIDfield, so the label is a message id in thei18n_domainof the ZCML file declaring it.IAdditionalWorkflowLabelutility named after the workflow id, anddeclaration.workflow_label()looks it up, falling back to the workflow's title.@workflowchain entry'stitlecarries the label, translated. Every Volto component already shows that title, so none of them needs a code change for it. The vocabulary of the Review state collection criterion names the workflow's states with it too.labelwith more or fewer than one workflow id raisesConfigurationError, since nothing would say which workflow it names. Two directives labelling the same workflow raiseConfigurationConflictError, as any two utilities registered under one name do.Without a label, both places keep using the workflow's title, exactly as before.
review_statecriteria naming no workflow (#10, efa4024)publishedreview_stateworkflow_statesworkflow_statesA mixed query moves as a whole: the catalog intersects the results of different indexes, so splitting one criterion between the two would turn its any of into an all of. The collection editor offers only qualified values, so a criterion saved from it targets
workflow_statesfrom then on.Volto add-on (#8 and #9, e9a0ba0)
getWorkflowStates,getAdditionalWorkflowStates,parseWorkflowState, andformatWorkflowState, with theWORKFLOW_STATE_SEPARATORandWORKFLOW_STATES_VOCABULARYconstants and theWorkflowStateValue,ParsedWorkflowState, andWithWorkflowStatestypes.StateBadgefrom a value. It takes either a chainentry, as before, or aworkflow_statesvaluewith an optional translatedlabel, falling back to the state id. A value with no separator renders nothing.@vocabularieschecks onlyViewfor it, since it is not in plone.app.content's permission map. A hook fetching those titles is left out: Volto's token-title request serializes the token list in a way not verified against plone.restapi here.StateBadgeandAdditionalWorkflowMenustories and aStateBadgetest.Documentation
titlenow describes the label.labelattribute, what it registers, its errors, and the equivalent Python registration.review_statecriterion moves, and how the criterion's vocabulary names a labelled workflow.StateBadgein a listing fromworkflow_states.utils,subscribers, andrestapi, plusworkflow_labelandIAdditionalWorkflowLabel; import paths updated throughout, including the tutorial.News fragments
backend/news/:+reorganize.internal.md,7.bugfix.md,8.feature.md,9.feature.md,10.bugfix.mdnews/:+reorganize.documentation.md,8.documentation.md,9.documentation.md,10.documentation.mdfrontend/packages/volto-multiworkflow/news/:8.feature.md,9.internal.mdTesting
The backend suite was run on each backend commit's tree before committing: 230, 230, 254, 261, and 272 passed. Everything else below is the final state.
make test(backend)make mypyruff check,ruff format --check,zpretty --check srcvitest run(frontend)pnpm lint,pnpm prettiermake html(clean build)make valemake linkcheckbroken38 of the Vale warnings are the pre-existing set
mainpassed with in #5. The new one isMicrosoft.GeneralURLonreference/rest-api.mdline 158 ("whatGETon its URL returns"), kept because the page is written for developers.The label's translation is tested end to end:
TestDeclaredLabelregisters a translation domain of its own, and the@workflowpayload carries the translated text rather than the message id.tsc --noEmitin the frontend package reports three errors, none in a file this PR touches: two in Volto core sources, one instories.test.tsx. CI does not run it.Closes #7
Closes #8
Closes #9
Closes #10