def fix_none_responsible(app):

    plone = setup_plone(app)

    print "Get brains of task..."
    brains = plone.portal_catalog(
        {'portal_type': 'opengever.task.task'})

    print "%s task found" % len(brains)

    print "check local roles on task ..."

    for brain in brains:
        task = brain.getObject()

        responsible = task.responsible

        if responsible.startswith('inbox:'):
            responsible = 'og_%s_eingangskorb' %(responsible[6:])

        if responsible == 'None':
            if task.predecessor:
                new_task = ISuccessorTaskController(task).get_predecessor()
            else:
                new_task = ISuccessorTaskController(task).get_successors()[0]

            new_responsible = new_task.responsible
            new_responsible_client = new_task.assigned_client

            print "None Responsible: Task %s should change to %s %s (%s:%s)" %(
                '/'.join(task.getPhysicalPath()),
                new_responsible, new_responsible_client,
                new_task.client_id, new_task.physical_path)

            task.responsible = new_responsible
            task.responsible_client = new_responsible_client

            index_task(task, None)

            last_response = IResponseContainer(task)[-1]

            new_changes = PersistentList()
            for change in last_response.changes:
                if change.get('id') in ['responsible', 'reponsible'] and change.get('after') == 'None':
                    # drop it
                    pass
                else:
                    new_changes.append(change)
            last_response.changes = new_changes

            transaction.commit()
    def test_reject_response_for_older_tasks(self, browser):
        """The responsible gets changed since the release 2018.4, before
        rejecting a task was only a status change, so we need to test for
        another message.
        """

        browser.login()

        # Reject task
        # (CSS class is .refuse even though the transition is named 'reject')
        self.click_task_button(browser, 'refuse')

        # Manually remove responsible change information from the response
        # to fake an old task situation.
        response = IResponseContainer(self.task)[-1]
        response.changes = [
            change for change in response.changes if change['id'] != 'responsible']
        transaction.commit()

        browser.reload()
        self.assertEqual(u'Rejected by M\xfcller Hans (test_user_1_).',
                         self.get_latest_answer(browser))