Esempio n. 1
0
    def test_oguid_by_path_returns_none_for_invalid_path(self):
        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            None,
            controller.get_oguid_by_path('/plone/not-existing/', 'client1'))
    def handle_continue(self, action):
        data, errors = self.extractData()

        if not errors:

            oguid = ISuccessorTaskController(self.context).get_oguid()

            # set forwarding flag
            is_forwarding = True

            dm = getUtility(IWizardDataStorage)
            dmkey = 'accept:%s' % oguid
            dm.set(dmkey, u'is_forwarding', is_forwarding)
            # activate the assign to dossier mode
            dm.set(dmkey, u'is_only_assign', True)
            dm.update(dmkey, data)

            method = data.get('method')

            if method == 'existing_dossier':
                url = '{}/@@accept_choose_dossier?oguid={}'.format(
                    self.context.get_responsible_org_unit().admin_unit.
                    public_url, oguid)
                return self.request.RESPONSE.redirect(url)

            elif method == 'new_dossier':
                oguid = ISuccessorTaskController(self.context).get_oguid()
                url = '{}/@@accept_select_repositoryfolder?oguid={}'.format(
                    self.context.get_responsible_org_unit().admin_unit.
                    public_url, oguid)
                return self.request.RESPONSE.redirect(url)
Esempio n. 3
0
    def test_set_predecessor_with_invalid_oguid_returns_false(self):
        task1 = create(Builder('task'))

        self.assertFalse(
            ISuccessorTaskController(task1).set_predecessor(u'incorrect:2'))
        self.assertFalse(
            ISuccessorTaskController(task1).set_predecessor(u'client1:3'))
Esempio n. 4
0
    def test_oguid_by_path_returns_none_for_invalid_path(self):
        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            None,
            controller.get_oguid_by_path('/plone/not-existing/', 'client1'))
Esempio n. 5
0
    def test_oguid_by_path_returns_none_for_invalid_admin_unit_id(self):
        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            None,
            controller.get_oguid_by_path('/'.join(task.getPhysicalPath()), 'client2'))
Esempio n. 6
0
    def test_set_predecessor_with_valid_oguid_returns_true(self):
        task1 = create(Builder('task'))
        task2 = create(Builder('task'))

        task2_oguid = ISuccessorTaskController(task2).get_oguid()
        self.assertTrue(
            ISuccessorTaskController(task1).set_predecessor(task2_oguid))
Esempio n. 7
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = Transporter()
    successor = transporter.transport_from(dossier, predecessor.admin_unit_id,
                                           predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(u'version_message_accept_task',
                default=u'Document copied from task (task accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Move current responsible from predecessor task to successor
    center = notification_center()
    center.add_task_responsible(successor, successor.responsible)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {
        'text': response_text.encode('utf-8'),
        'successor_oguid': successor_tc.get_oguid()
    }

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@accept_task_workflow_transition',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor task failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
Esempio n. 8
0
    def test_oguid_by_path_returns_none_for_invalid_admin_unit_id(self):
        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            None,
            controller.get_oguid_by_path('/'.join(task.getPhysicalPath()),
                                         'client2'))
Esempio n. 9
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    getRequest().set('X-CREATING-SUCCESSOR', True)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = Transporter()
    successor = transporter.transport_from(
        dossier, predecessor.admin_unit_id, predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(u'version_message_accept_task',
               default=u'Document copied from task (task accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Move current responsible from predecessor task to successor
    center = notification_center()
    center.add_task_responsible(successor, successor.responsible)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {'text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid()}

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@accept_task_workflow_transition',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor task failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
Esempio n. 10
0
 def get_predecessor_task(self):
     """ Get the original task
     """
     controller = ISuccessorTaskController(self.context)
     task = controller.get_predecessor()
     # box rendering need a list
     if not task:
         return []
     return [task]
Esempio n. 11
0
 def get_predecessor_task(self):
     """ Get the original task
     """
     controller = ISuccessorTaskController(self.context)
     task = controller.get_predecessor()
     # box rendering need a list
     if not task:
         return []
     return [task]
Esempio n. 12
0
    def test_oguid_is_admin_unit_id_and_task_id_separated_by_a_colon(self):
        intids = getUtility(IIntIds)

        task1 = create(Builder('task'))
        task2 = create(Builder('task'))

        self.assertEquals(u'client1:%s' % (intids.getId(task1)),
                          ISuccessorTaskController(task1).get_oguid())
        self.assertEquals(u'client1:%s' % (intids.getId(task2)),
                          ISuccessorTaskController(task2).get_oguid())
Esempio n. 13
0
    def get_related_tasks_to_sync(self, transition=''):
        tasks = []
        stc = ISuccessorTaskController(self.context)
        predecessor = stc.get_predecessor(None)
        if predecessor:
            tasks.append(predecessor)

        tasks.extend(stc.get_successors())

        return tasks
Esempio n. 14
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):

    predecessor = getUtility(ITaskQuery).get_task_by_oguid(predecessor_oguid)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = getUtility(ITransporter)
    successor = transporter.transport_from(
        dossier, predecessor.client_id, predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)
    with CustomInitialVersionMessage(
        _(u'version_message_accept_task',
          default=u'Document copied from task (task accepted)'),
        dossier.REQUEST):
        intids_mapping = doc_transporter.copy_documents_from_remote_task(
            predecessor, successor)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.client_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {'text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid()}

    response = remote_request(predecessor.client_id,
                              '@@accept_task_workflow_transition',
                              path=predecessor.physical_path,
                              data=request_data)

    if response.read().strip() != 'OK':
        raise Exception('Adding the response and changing the '
                        'workflow state on the predecessor task '
                        'failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
Esempio n. 15
0
    def test_oguid_by_path_returns_the_oguid_of_the_accordant_task(self):
        intids = getUtility(IIntIds)
        url_tool = getToolByName(self.portal, 'portal_url')

        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            u'client1:%s' % (intids.getId(task)),
            controller.get_oguid_by_path(
                '/'.join(url_tool.getRelativeContentPath(task)), 'client1'))
Esempio n. 16
0
def assign_forwarding_to_dossier(
        context, forwarding_oguid, dossier, response_text):

    forwarding = Task.query.by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # Reset issuer to the current inbox
    fielddata['issuer'] = get_current_org_unit().inbox().id()

    # Predefine the task_type to avoid tasks with an invalid task_type
    fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

    # lets create a new task - the successor task
    task = createContentInContainer(
        dossier, 'opengever.task.task', **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # Add issuer and responsible to the watchers of the newly created task
    center = notification_center()
    center.add_task_responsible(task, task.responsible)
    center.add_task_issuer(task, task.issuer)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(
        get_current_admin_unit().id(),
        '/'.join(forwarding_obj.getPhysicalPath()),
        intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(
        forwarding_obj,
        'forwarding-transition-assign-to-dossier',
        text=response_text,
        successor_oguid=successor_tc_task.get_oguid())

    IYearfolderStorer(forwarding_obj).store_in_yearfolder()

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
Esempio n. 17
0
def assign_forwarding_to_dossier(context, forwarding_oguid, dossier,
                                 response_text):

    forwarding = Task.query.by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # Reset issuer to the current inbox
    fielddata['issuer'] = get_current_org_unit().inbox().id()

    # Predefine the task_type to avoid tasks with an invalid task_type
    fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

    # lets create a new task - the successor task
    task = createContentInContainer(dossier, 'opengever.task.task',
                                    **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # Add issuer and responsible to the watchers of the newly created task
    center = notification_center()
    center.add_task_responsible(task, task.responsible)
    center.add_task_issuer(task, task.issuer)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(get_current_admin_unit().id(),
                                       '/'.join(
                                           forwarding_obj.getPhysicalPath()),
                                       intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(forwarding_obj,
                               'forwarding-transition-assign-to-dossier',
                               text=response_text,
                               successor_oguid=successor_tc_task.get_oguid())

    IYearfolderStorer(forwarding_obj).store_in_yearfolder()

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
Esempio n. 18
0
    def test_oguid_by_path_returns_the_oguid_of_the_accordant_task(self):
        intids = getUtility(IIntIds)
        url_tool = getToolByName(self.portal, 'portal_url')

        task = create(Builder('task'))

        controller = ISuccessorTaskController(task)
        self.assertEquals(
            u'client1:%s' % (intids.getId(task)),
            controller.get_oguid_by_path(
                '/'.join(url_tool.getRelativeContentPath(task)),
                'client1'))
Esempio n. 19
0
    def after_transition_hook(self, transition, disable_sync, transition_params):
        successor_task = self.create_successor_task(transition_params['dossier'])

        add_simple_response(
            self.context, transition=transition, text=transition_params.get('text'),
            successor_oguid=Oguid.for_object(successor_task).id)

        # set predecessor on successor task
        successor_tc_task = ISuccessorTaskController(successor_task)
        successor_tc_task.set_predecessor(Oguid.for_object(self.context).id)

        IYearfolderStorer(self.context).store_in_yearfolder()
        return successor_task
Esempio n. 20
0
    def test_successor_is_also_updated_when_modify_predecessors_deadline(
            self, browser):
        self.login(self.dossier_responsible, browser=browser)

        # Make predecessor <-> successor pair
        predecessor = self.task
        successor = self.seq_subtask_1
        ISuccessorTaskController(successor).set_predecessor(
            ISuccessorTaskController(predecessor).get_oguid())

        self._change_deadline(predecessor, datetime.date(2013, 10, 1),
                              'Lorem Ipsum')

        self.assertEquals(successor.deadline, datetime.date(2013, 10, 1))
    def sync_deadline(self, new_deadline, text):
        sct = ISuccessorTaskController(self.context)
        for successor in sct.get_successors():

            response = remote_request(
                successor.client_id,
                '@@remote_deadline_modifier',
                successor.physical_path,
                data={
                    'new_deadline': new_deadline.toordinal(),
                    'text': text})

            if response.read().strip() != 'OK':
                raise Exception(
                    'Updating deadline on remote client %s. failed (%s)' % (
                        successor.client_id, response.read()))
    def sync_deadline(self, new_deadline, text):
        sct = ISuccessorTaskController(self.context)
        for successor in sct.get_successors():

            response = remote_request(
                successor.client_id,
                '@@remote_deadline_modifier',
                successor.physical_path,
                data={
                    'new_deadline': new_deadline.toordinal(),
                    'text': text})

            if response.read().strip() != 'OK':
                raise Exception(
                    'Updating deadline on remote client %s. failed (%s)' % (
                        successor.client_id, response.read()))
Esempio n. 23
0
    def get_tasks_to_sync(self, transition):
        if not self._is_synced_transition(transition):
            return []

        tasks = []
        stc = ISuccessorTaskController(self.context)

        predecessor = stc.get_predecessor(None)

        # Fowarding predecessors should not be synced.
        if predecessor is not None and predecessor.task_type != u"forwarding_task_type":
            tasks.append(predecessor)

        tasks.extend(stc.get_successors())

        return tasks
Esempio n. 24
0
    def test_response_view(self):
        # test added objects info
        add_simple_response(self.task,
                            text=u'field',
                            added_object=[self.doc1, self.doc2])

        # test field changes info
        add_simple_response(self.task,
                            text=u'field',
                            field_changes=(
                                (ITask['responsible'], TEST_USER_ID),
                                (ITask['responsible_client'], 'plone'),
                            ),
                            transition=u'task-transition-open-in-progress')

        # test successsor info
        successor_oguid = ISuccessorTaskController(self.successor).get_oguid()
        add_simple_response(self.task, successor_oguid=successor_oguid)

        transaction.commit()

        self.assertEquals(len(IResponseContainer(self.task)), 3)

        # test different responeses and their infos
        self.browser.open('%s/tabbedview_view-overview' %
                          self.task.absolute_url())

        # TODO: replace with OGBrowse API. What is it looking for?
        self.assertEquals(
            'Added successor task',
            self.browser.css('div.response-info div span.label')
            [0].plain_text())

        successor_info = """<span class="issueChange"><span class="wf-task-state-open"><a href="http://nohost/plone/dossier-1/task-2" title="[Plone] > dossier-1 > Test task 1"><span class="rollover-breadcrumb icon-task-remote-task">Test task 1</span></a>  <span class="discreet">(Client2 / <a href="http://nohost/plone/@@user-details/testuser2">User 2 Test (testuser2)</a>)</span></span></span>"""

        self.assertTrue(successor_info in self.browser.contents)

        responsible_container = self.browser.xpath(
            "//div[@class='response-info']/div[descendant-or-self::*[contains(text(), 'label_responsible')]]"
        )[0]
        links = responsible_container.xpath("./*/a")
        self.assertEquals(
            ['User 2 Test (testuser2)', 'User Test (test_user_1_)'],
            [l.text for l in links])
        self.assertEquals([
            'http://nohost/plone/@@user-details/testuser2',
            'http://nohost/plone/@@user-details/test_user_1_'
        ], [l.attrib["href"] for l in links])

        documents = self.browser.css(
            ".contenttype-opengever-document-document")
        self.assertEquals(['Doc 1', 'Doc 2'],
                          [d.plain_text() for d in documents])
        self.assertEquals([
            'http://nohost/plone/dossier-1/document-1',
            'http://nohost/plone/dossier-1/document-2'
        ], [d.attrib["href"] for d in documents])

        # edit and delete should not be possible
        self.assertEquals([], self.browser.css("input[type='submit']"))
    def test_successor_is_also_updated_when_modify_predecessors_deadline(
            self, browser):
        predecessor = create(
            Builder('task').having(issuer=TEST_USER_ID,
                                   deadline=datetime.date(2013, 1, 1)))
        succesor = create(
            Builder('task').having(issuer=TEST_USER_ID,
                                   deadline=datetime.date(2013, 1, 1)))

        ISuccessorTaskController(succesor).set_predecessor(
            ISuccessorTaskController(predecessor).get_oguid())

        self._change_deadline(predecessor, datetime.date(2013, 10, 1),
                              'Lorem Ipsum')

        self.assertEquals(succesor.deadline, datetime.date(2013, 10, 1))
Esempio n. 26
0
def assign_forwarding_to_dossier(
    context, forwarding_oguid, dossier, response_text):

    forwarding = getUtility(ITaskQuery).get_task_by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # lets create a new task - the successor task
    task = createContentInContainer(
        dossier, 'opengever.task.task', **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(
        get_client_id(),
        '/'.join(forwarding_obj.getPhysicalPath()),
        intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(
        forwarding_obj,
        'forwarding-transition-assign-to-dossier',
        text=response_text,
        successor_oguid=successor_tc_task.get_oguid())

    inbox = aq_parent(aq_inner(forwarding_obj))
    yearfolder = _get_yearfolder(inbox)
    clipboard = inbox.manage_cutObjects((forwarding_obj.getId(),))
    yearfolder.manage_pasteObjects(clipboard)

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
Esempio n. 27
0
    def get_tasks_to_sync(self, transition):
        if not self._is_synced_transition(transition):
            return []

        tasks = []
        stc = ISuccessorTaskController(self.context)

        predecessor = stc.get_predecessor(None)

        #Fowarding predecessors should not be synced.
        if (predecessor is not None and
            predecessor.task_type != u'forwarding_task_type'):
            tasks.append(predecessor)

        tasks.extend(stc.get_successors())

        return tasks
Esempio n. 28
0
def assign_forwarding_to_dossier(context, forwarding_oguid, dossier,
                                 response_text):

    forwarding = getUtility(ITaskQuery).get_task_by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # lets create a new task - the successor task
    task = createContentInContainer(dossier, 'opengever.task.task',
                                    **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(get_client_id(),
                                       '/'.join(
                                           forwarding_obj.getPhysicalPath()),
                                       intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(forwarding_obj,
                               'forwarding-transition-assign-to-dossier',
                               text=response_text,
                               successor_oguid=successor_tc_task.get_oguid())

    inbox = aq_parent(aq_inner(forwarding_obj))
    yearfolder = _get_yearfolder(inbox)
    clipboard = inbox.manage_cutObjects((forwarding_obj.getId(), ))
    yearfolder.manage_pasteObjects(clipboard)

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
Esempio n. 29
0
    def after_create(self, obj):
        wtool = getToolByName(obj, 'portal_workflow')
        for transition in self.transitions:
            wtool.doActionFor(obj, transition)

        if self.predecessor:
            ISuccessorTaskController(obj).set_predecessor(self.predecessor)

        super(TaskBuilder, self).after_create(obj)
Esempio n. 30
0
    def after_create(self, obj):
        wtool = getToolByName(obj, 'portal_workflow')
        for transition in self.transitions:
            wtool.doActionFor(obj, transition)

        if self.predecessor:
            ISuccessorTaskController(obj).set_predecessor(self.predecessor)

        if self._as_sequential_task:
            alsoProvides(obj, IFromSequentialTasktemplate)

        super(TaskBuilder, self).after_create(obj)
Esempio n. 31
0
    def updateWidgets(self):
        if self.request.form.get('form.widgets.text', None) is None:
            if self.request.get('oguid', None) is None:
                oguid = ISuccessorTaskController(self.context).get_oguid()
                self.request.set('oguid', oguid)

            dm = getUtility(IWizardDataStorage)
            dmkey = 'accept:%s' % self.request.get('oguid')
            text = dm.get(dmkey, 'text')

            if text:
                self.request.set('form.widgets.text', text)

        super(ChooseMethodStepForm, self).updateWidgets()
Esempio n. 32
0
    def _is_close_successor_wizard_possible(self, transition):
        if not self._is_responsible_or_inbox_group_user():
            return False

        elif not self.context.predecessor:
            return False

        # check if the predessecor is a forwarding
        # in this case the successor wizard isn't possible and necessary
        elif ISuccessorTaskController(self.context).get_predecessor(
        ).task_type == u'forwarding_task_type':
            return False

        else:
            return True
Esempio n. 33
0
    def test_successors_predecessor_relation(self):
        task1 = create(Builder('task'))
        task2 = create(Builder('task'))
        task3 = create(Builder('task'))

        task1_oguid = ISuccessorTaskController(task1).get_oguid()

        task1_sql = ISuccessorTaskController(task1).get_indexed_data()
        task2_sql = ISuccessorTaskController(task2).get_indexed_data()
        task3_sql = ISuccessorTaskController(task3).get_indexed_data()

        ISuccessorTaskController(task2).set_predecessor(task1_oguid)
        ISuccessorTaskController(task3).set_predecessor(task1_oguid)

        self.assertEquals(task1_sql,
                          ISuccessorTaskController(task2).get_predecessor())
        self.assertEquals(task1_sql,
                          ISuccessorTaskController(task3).get_predecessor())

        self.assertEquals([task2_sql, task3_sql],
                          ISuccessorTaskController(task1).get_successors())
Esempio n. 34
0
    def test_forwarding_predecessors_are_skipped_when_syncing_deadline_modification(
            self, browser):
        self.login(self.secretariat_user, browser=browser)

        # Make predecessor (forwarding) <-> successor (task) pair, like
        # it's created when assigning a forwarding to a dossier.
        predecessor = self.inbox_forwarding
        successor = self.seq_subtask_1
        ISuccessorTaskController(successor).set_predecessor(
            Oguid.for_object(predecessor).id)

        self._change_deadline(successor, datetime.date(2013, 10, 1),
                              'Lorem Ipsum')

        self.assertEquals(successor.deadline, datetime.date(2013, 10, 1))
        self.assertEquals(None, predecessor.deadline)
Esempio n. 35
0
    def updateWidgets(self):
        if self.request.form.get('form.widgets.transition', None) is None:
            self.request.set('form.widgets.transition',
                             self.request.get('transition'))

        # Use text passed from response-add-form.
        if self.request.form.get('form.widgets.text', None) is None:
            dm = getUtility(IWizardDataStorage)
            oguid = ISuccessorTaskController(self.context).get_oguid()
            dmkey = 'delegate:%s' % oguid
            text = dm.get(dmkey, 'text')
            if text:
                self.request.set('form.widgets.text', text)

        Form.updateWidgets(self)

        self.widgets['transition'].mode = HIDDEN_MODE
Esempio n. 36
0
    def test_set_predecessor_resets_issuing_org_unit_to_predecessors_one(self):
        extra_au = create(Builder('admin_unit').id(u'extra-au'))
        extra_ou = create(
            Builder('org_unit').having(admin_unit=extra_au).id(u'extra-ou'))

        create(
            Builder('globalindex_task').having(int_id='1234',
                                               issuing_org_unit='extra-ou',
                                               admin_unit_id='extra-au'))
        successor = create(
            Builder('task').having(responsible_client='org-unit-1'))

        self.assertEquals(self.org_unit,
                          successor.get_sql_object().get_issuing_org_unit())

        ISuccessorTaskController(successor).set_predecessor('extra-au:1234')
        self.assertEquals(extra_ou,
                          successor.get_sql_object().get_issuing_org_unit())
Esempio n. 37
0
    def updateWidgets(self):
        if self.request.form.get('form.widgets.text', None) is None:
            if self.request.get('oguid', None) is None:
                oguid = ISuccessorTaskController(self.context).get_oguid()
                self.request.set('oguid', oguid)

            dm = getUtility(IWizardDataStorage)
            dmkey = 'accept:%s' % self.request.get('oguid')
            text = dm.get(dmkey, 'text')

            if text:
                self.request.set('form.widgets.text', text)

        super(ChooseMethodStepForm, self).updateWidgets()
        if self.context.task_type == 'forwarding_task_type':
            self.widgets.get('method').label = _(
                u'label_accept_forwarding_choose_method',
                default="Accept forwarding and ...")
Esempio n. 38
0
    def test_set_predecessor_resets_issuing_org_unit_to_predecessors_one(self):
        additional_admin_unit = create(Builder('admin_unit').id(u'additional'))
        additional = create(
            Builder('org_unit').having(
                admin_unit=additional_admin_unit).id(u'additional'))

        create(
            Builder('globalindex_task').having(int_id='1234',
                                               issuing_org_unit='additional',
                                               admin_unit_id='additional'))
        successor = create(Builder('task'))

        self.assertEquals(self.org_unit,
                          successor.get_sql_object().get_issuing_org_unit())

        ISuccessorTaskController(successor).set_predecessor('additional:1234')
        self.assertEquals(additional,
                          successor.get_sql_object().get_issuing_org_unit())
Esempio n. 39
0
    def handle_continue(self, action):
        data, errors = self.extractData()

        if not errors:
            oguid = ISuccessorTaskController(self.context).get_oguid()

            dm = getUtility(IWizardDataStorage)
            dmkey = 'close:%s' % oguid
            dm.update(dmkey, data)

            if len(data['documents']) == 0:
                self.close_task(data.get('text'))
                return self.request.RESPONSE.redirect(
                    self.context.absolute_url())

            else:
                admin_unit = self.context.get_responsible_admin_unit()
                dm.push_to_remote_client(dmkey, admin_unit.id())

                url = '/'.join(
                    (admin_unit.public_url,
                     '@@close-task-wizard_choose-dossier?oguid=%s' % (oguid)))
                return self.request.RESPONSE.redirect(url)
Esempio n. 40
0
    def handle_continue(self, action):
        data, errors = self.extractData()

        if not errors:
            oguid = ISuccessorTaskController(self.context).get_oguid()

            dm = getUtility(IWizardDataStorage)
            dmkey = 'close:%s' % oguid
            dm.update(dmkey, data)

            if len(data['documents']) == 0:
                url = '/'.join((self.context.absolute_url(),
                                '@@close-task-wizard_close?oguid=%s' % oguid))
                return self.request.RESPONSE.redirect(url)

            else:
                info = getUtility(IContactInformation)
                client = info.get_client_by_id(self.context.responsible_client)
                dm.push_to_remote_client(dmkey, client.client_id)

                url = '/'.join(
                    (client.public_url,
                     '@@close-task-wizard_choose-dossier?oguid=%s' % (oguid)))
                return self.request.RESPONSE.redirect(url)
Esempio n. 41
0
def accept_forwarding_with_successor(
    context, predecessor_oguid, response_text, dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = getUtility(ITaskQuery).get_task_by_oguid(predecessor_oguid)

    # get the inbox
    cat = getToolByName(context, 'portal_catalog')
    inboxes = cat(portal_type="opengever.inbox.inbox")

    if len(inboxes) == 0:
        raise Unauthorized()
    else:
        inbox = inboxes[0].getObject()

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = getUtility(ITransporter)
    if dossier:
        yearfolder = _get_yearfolder(inbox, )
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.client_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.client_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = u'inbox:%s' % get_client_id()

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor_forwarding.REQUEST.set('X-CREATING-SUCCESSOR', True)

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)
    with CustomInitialVersionMessage(
        _(u'version_message_accept_forwarding',
          default=u'Document copied from forwarding (forwarding accepted)'),
        context.REQUEST):
        intids_mapping = doc_transporter.copy_documents_from_remote_task(
            predecessor, successor_forwarding)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.client_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # lets create a new task - the successor task
        task = createContentInContainer(
            dossier, 'opengever.task.task', **fielddata)

        # copy documents and map the intids

        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_client_id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {'response_text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid(),
                    'transition': 'forwarding-transition-accept'}

    response = remote_request(predecessor.client_id,
                              '@@store_forwarding_in_yearfolder',
                              path=predecessor.physical_path,
                              data=request_data)

    if response.read().strip() != 'OK':
        raise Exception('Adding the response and changing the '
                        'workflow state on the predecessor forwarding '
                        'failed.')

    if dossier:
        # when a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding
Esempio n. 42
0
def accept_forwarding_with_successor(
    context, predecessor_oguid, response_text, dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    context.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = Transporter()
    inbox = get_current_inbox(context)
    if dossier:
        yearfolder = get_current_yearfolder(inbox=inbox)
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.admin_unit_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.admin_unit_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = get_current_org_unit().inbox().id()

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(
        u'version_message_accept_forwarding',
        default=u'Document copied from forwarding (forwarding accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor_forwarding, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Remove current responsible from predecessor and add issuer
    # and responsible to successor's watcher.
    center = notification_center()
    center.remove_task_responsible(Oguid.parse(predecessor_oguid),
                                   successor_forwarding.responsible)
    center.add_task_responsible(successor_forwarding,
                                successor_forwarding.responsible)
    center.add_task_issuer(successor_forwarding, successor_forwarding.issuer)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # Predefine the task_type to avoid tasks with an invalid task_type
        fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

        # lets create a new task - the successor task
        task = createContentInContainer(
            dossier, 'opengever.task.task', **fielddata)

        # copy documents and map the intids
        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_current_admin_unit().id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {'response_text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid(),
                    'transition': 'forwarding-transition-accept'}

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@store_forwarding_in_yearfolder',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor forwarding failed.')

    if dossier:
        # Update watchers for created successor forwarding and task
        center = notification_center()
        center.remove_task_responsible(successor_forwarding, task.responsible)
        center.add_task_responsible(task, task.responsible)

        # When a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding
Esempio n. 43
0
 def get_successor_tasks(self):
     """ Get the task from which this task was copied
     """
     controller = ISuccessorTaskController(self.context)
     return controller.get_successors()