zopefoundation / Products.DCWorkflow

Customizable workflows for the Zope Content Management Framework (CMF).
Other
4 stars 7 forks source link

Top-level workflow definition links broken after almost any change to definition, in Zope 4 and Zope 5 #30

Open seanupton opened 2 weeks ago

seanupton commented 2 weeks ago

BUG/PROBLEM REPORT

What I did:

What I expect to happen:

What actually happened:

impact

in more detail — what actions are broken:

What version of Python and Zope/Addons I am using:

What is failing here:

Workaround (which has limited testing) is a monkey patch:

def workflow_zmi_manage_main_wrapper(self, REQUEST, manage_tabs_message=None):
    view = REQUEST.steps[-1]
    target = 'manage_main'
    if view != target:
        query = '?manage_tabs_message={}'.format(manage_tabs_message or '')
        REQUEST.response.redirect(
            './{}/{}{}'.format(
                self.__class__.__name__.lower(),  # States -> states in url
                target,
                query if manage_tabs_message else '',
            )
        )
        return
    return self._old_manage_main(REQUEST, manage_tabs_message)

def workflow_zmi_manage_permissions_wrapper(
        self,
        REQUEST,
        manage_tabs_message=None
        ):
    if REQUEST.steps[-1] != 'manage_permissions':
        query = '?manage_tabs_message={}'.format(manage_tabs_message or '')
        REQUEST.response.redirect(
            '{}/manage_permissions{}'.format(
                self.absolute_url(),
                query if manage_tabs_message else '',
            )
        )
        return
    return self._old_manage_permissions(REQUEST, manage_tabs_message)

Which can be applied in ZCML via collective.monkepatcher like:

<!-- more elided, but you need to patch States, Transitions, Variables, Worklists with first function above -->
  <monkey:patch
      description="patch DCWorkflow ZMI Worklists manage_main to fix tab links"
      class="Products.DCWorkflow.Worklists.Worklists"
      original="manage_main"
      preserveOriginal="true"
      replacement=".monkeypatch.workflow_zmi_manage_main_wrapper"
      />

  <monkey:patch
      description="patch DCWorkflow ZMI manage_permissions to fix tab links"
      class="Products.DCWorkflow.WorkflowUIMixin.WorkflowUIMixin"
      original="manage_permissions"
      preserveOriginal="true"
      replacement=".monkeypatch.workflow_zmi_manage_permissions_wrapper"
      />

I am not 100% confident in the correctness or side-effect profile of this patching, though (it works for me, but I'm unclear if there is a better solution than redirecting, e.g. fixing the DTML tab links).

petschki commented 2 weeks ago

At least there's a similar report from 2019 #15