Example #1
0
    def test_subtask_response(self):
        """When a subtask is added it should automaticly
        add a response on maintask"""

        intids = getUtility(IIntIds)
        maintask = create_task(self.portal, title='maintask')
        subtask = create_task(maintask, title='subtask')
        responses = IResponseContainer(maintask)
        self.assertEquals(
            responses[-1].added_object.to_id, intids.getId(subtask))
        self.assertEquals(len(responses), 2)

        # all different remote requests should not
        # generate an response
        maintask.REQUEST.environ['X_OGDS_AC'] = 'hugo.boss'
        create_task(maintask, title='subtask')
        self.assertEquals(len(IResponseContainer(maintask)), 2)

        maintask.REQUEST.environ['X_OGDS_AC'] = None
        maintask.REQUEST.environ['X_OGDS_CID'] = 'client_a'
        create_task(maintask, title='subtask')
        self.assertEquals(len(IResponseContainer(maintask)), 2)

        maintask.REQUEST.environ['X_OGDS_CID'] = None
        maintask.REQUEST.set('X-CREATING-SUCCESSOR', True)
        create_task(maintask, title='subtask')
        self.assertEquals(len(IResponseContainer(maintask)), 2)
    def test_creating_and_extraction(self):

        class DummyResponse(object):
            def getStatus(self):
                return 200

        class DummyRequest(dict):
            def __init__(self):
                self.response = DummyResponse()

        remote_task = self.providing_stub(
            [ITask, IAttributeAnnotatable])
        request = DummyRequest()
        context = self.providing_stub(
            [ITask, IAttributeAnnotatable])

        self.replay()

        response = Response(u'Sample text')
        response.creator = u'hugo.boss'
        response.date = DateTime("02.07.2010")

        response.add_change(
            'review_state', 'State', 'before-state', 'after-state')
        response.add_change(
            'responsible', 'Responsible', 'hugo.boss', 'james.bond')

        container = IResponseContainer(remote_task)
        container.add(response)

        # extract
        request.intids_mapping = {}
        data = ExtractResponses(remote_task, request)()

        # receive
        request['responses'] = data
        ReceiveResponses(context, request)()

        # check if the response is correctly synced
        self.assertTrue(len(IResponseContainer(context)) == 1)
        synced_response = IResponseContainer(context)[0]
        self.assertEquals(synced_response.text, response.text)
        self.assertEquals(synced_response.creator, response.creator)
        self.assertEquals(synced_response.date, response.date)
        # changes
        self.assertEquals(
            synced_response.changes,
            [
                {u'after': u'after-state',
                 u'id': u'review_state',
                 u'name': u'State',
                 u'before': u'before-state'},
                {u'after': u'james.bond',
                 u'id': u'responsible',
                 u'name': u'Responsible',
                 u'before': u'hugo.boss'}])
Example #3
0
    def test_reassign_remote_view(self):

        task = self.providing_stub([ITask, IAttributeAnnotatable])
        self.expect(task.Type()).result('opengever.task.task')
        self.expect(task.responsible).result('old_responsible')
        task.responsible = 'hugo.boss'

        # worfklow_tool
        wft = self.stub()
        self.mock_tool(wft, 'portal_workflow')

        with self.mocker.order():
            wft.getInfoFor(task, 'review_state').result(
                'task-state-resolved')
            wft.getInfoFor(task, 'review_state').result(
                'task-state-in-progress')

        wft.doActionFor(task, u'task-transition-reassign')
        wft.getTitleForStateOnType(
            ANY, 'opengever.task.task').result('Resolved')

        user = SimpleUser('hanspeter', '', ('manage', ), [])
        newSecurityManager(self.create_dummy(), user)

        # reassign request
        reassign_request = self.stub_request(
            interfaces=[IInternalOpengeverRequestLayer, ],
            stub_response=False)
        getter = self.stub()
        self.expect(reassign_request.get).result(getter)
        self.expect(getter('text')).result(u'Simpletext')
        self.expect(getter('responsible')).result('hugo.boss')
        self.expect(getter('responsible_client')).result('client1')
        self.expect(getter('transition')).result(
            u'task-transition-reassign')

        # reassign respone
        response = self.stub_response(request=reassign_request)
        self.expect(response.setHeader("Content-type", "text/plain"))

        # an ObjectModifiedEvent should be notified to update the local roles
        handler = self.stub()
        self.mock_handler(handler, [IObjectModifiedEvent])
        self.expect(handler(ANY)).result(True)

        self.replay()

        # REASSIGN TRANSITION
        # first request
        view = SyncTaskWorkflowStateReceiveView(task, reassign_request)
        view()

        self.assertEquals(IResponseContainer(task)[0].text, u'Simpletext')
        self.assertEquals(len(IResponseContainer(task)), 1)
Example #4
0
    def test_remote_view(self):
        task = self.providing_stub([ITask, IAttributeAnnotatable])
        self.expect(task.Type()).result('opengever.task.task')

        # worfklow_tool
        wft = self.stub()
        self.mock_tool(wft, 'portal_workflow')

        with self.mocker.order():
            wft.getInfoFor(task, 'review_state').result(
                'task-state-resolved')
            wft.getInfoFor(task, 'review_state').result(
                'task-state-in-progress')

        wft.doActionFor(task, u'task-transition-resolved-in-progress')
        wft.getTitleForStateOnType(
            ANY, 'opengever.task.task').result('Resolved')

        user = SimpleUser('hanspeter', '', ('manage', ), [])
        newSecurityManager(self.create_dummy(), user)

        # request
        request = self.stub_request(
            interfaces=[IInternalOpengeverRequestLayer, ],
            stub_response=False)
        getter = self.stub()
        self.expect(request.get).result(getter)
        self.expect(getter('text')).result(u'Simpletext')
        self.expect(getter('responsible')).result(None)
        self.expect(getter('responsible_client')).result(None)
        self.expect(getter('transition')).result(
            u'task-transition-resolved-in-progress')

        #response
        response = self.stub_response(request=request)
        self.expect(response.setHeader("Content-type", "text/plain"))

        self.replay()

        # NORMAL TRANSITION
        # first request
        view = SyncTaskWorkflowStateReceiveView(task, request)
        view()

        # second request should do nothing
        view = SyncTaskWorkflowStateReceiveView(task, request)
        view()

        self.assertEquals(len(IResponseContainer(task)), 1)
        self.assertEquals(IResponseContainer(task)[0].text, u'Simpletext')
        self.assertEquals(len(IResponseContainer(task)[0].changes), 1)
        self.assertEquals(IResponseContainer(task)[0].creator, 'hanspeter')
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()
Example #6
0
    def create_responses(self, data):
        container = IResponseContainer(self.context)

        for resp_data in data:
            response = Response('')

            for key, value in resp_data.items():
                if value:
                    value = self._decode(value)
                setattr(response, key, value)

            container.add(response)

        modified(self.context)
Example #7
0
    def create_responses(self, data):
        container = IResponseContainer(self.context)

        for resp_data in data:
            response = Response('')

            for key, value in resp_data.items():
                if value:
                    value = self._decode(value)
                setattr(response, key, value)

            container.add(response)

        modified(self.context)
    def test_responsible_change_is_visible_in_the_response(self, browser):
        self.login(self.regular_user, browser)

        ITask(self.task).responsible = u'team:1'
        self.task.get_sql_object().responsible = u'team:1'
        self.set_workflow_state('task-state-open', self.task)

        browser.open(self.task, view='tabbedview_view-overview')
        browser.click_on('task-transition-open-in-progress')
        browser.fill({'Response': u'Das \xfcbernehme ich!'})
        browser.click_on('Save')

        response = IResponseContainer(self.task)[-1]
        expected = [{'before': u'team:1',
                     'after': 'kathi.barfuss',
                     'id': 'responsible',
                     'name': u'label_responsible'},
                    {'before': 'task-state-open',
                     'after': 'task-state-in-progress',
                     'id': 'review_state',
                     'name': u'Issue state'}]

        self.assertEquals(
            expected, [dict(change) for change in response.changes])

        browser.open(self.task, view='tabbedview_view-overview')
        self.assertEquals(
            u'Accepted by B\xe4rfuss K\xe4thi (kathi.barfuss), responsible '
            u'changed from Projekt \xdcberbaung Dorfmatte (Finanzamt) to '
            u'B\xe4rfuss K\xe4thi (kathi.barfuss).',
            browser.css('.answer h3').text[0])
Example #9
0
    def test_syncing_response_changes(self):
        add_simple_response(
            self.task,
            text=u'Neu zugewiesen',
            field_changes=[(ITask['responsible'], 'peter.mueller'),
                           (ITask['responsible_client'], 'client2')],
            transition='task-transition-reassign',
        )

        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        self.assertEquals([{
            u'after': u'peter.mueller',
            u'id': u'responsible',
            u'name': u'label_responsible',
            u'before': u'hugo.boss'
        }, {
            u'after': u'client2',
            u'id': u'responsible_client',
            u'name': u'label_resonsible_client',
            u'before': u'client1'
        }],
                          IResponseContainer(copy)[1].changes)
Example #10
0
    def extract_responses(self, intids_mapping=None):
        if intids_mapping is None:
            intids_mapping = {}

        self.intids_mapping = intids_mapping

        data = []
        for resp in IResponseContainer(self.context):
            resp_data = {}

            for key in IPersistentResponse.names():
                attr = IPersistentResponse[key]
                if type(attr) == Attribute:
                    val = getattr(resp, key, None)
                    try:
                        val = self._encode(val)
                    except ValueError:
                        # the intid in the relation value is not listed
                        # in the mapping - so we skip it.
                        pass
                    else:
                        resp_data[key] = val
            data.append(resp_data)

        return json.dumps(data)
Example #11
0
    def test_adds_corresponding_answer(self):
        self.login(self.dossier_responsible)
        change_task_workflow_state(
            self.subtask, 'task-transition-resolved-tested-and-closed')

        self.assertEqual('task-transition-resolved-tested-and-closed',
                         IResponseContainer(self.subtask)[-1].transition)
Example #12
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']"))
Example #13
0
    def test_adding_a_subtask_add_response_on_main_task(self):
        intids = getUtility(IIntIds)
        maintask = create(Builder('task').titled('maintask'))
        subtask = create(Builder('task').within(maintask).titled('maintask'))

        response = IResponseContainer(maintask)[-1]
        self.assertEquals(intids.getId(subtask), response.added_object.to_id)
        self.assertEquals('transition-add-subtask', response.transition)
Example #14
0
 def make_responses_persistent(self, task):
     responses = IResponseContainer(task)
     for response in responses:
         if response.changes:
             changes = [
                 PersistentMapping(change) for change in response.changes
             ]
             response.changes = PersistentList(changes)
Example #15
0
    def test_adding_a_document_add_response_on_main_task(self):
        intids = getUtility(IIntIds)
        maintask = create(Builder('task').titled('maintask'))
        document = create(
            Builder('document').within(maintask).titled('Letter to Peter'))

        response = IResponseContainer(maintask)[-1]
        self.assertEquals(intids.getId(document), response.added_object.to_id)
        self.assertEquals('transition-add-document', response.transition)
Example #16
0
    def test_adding_a_subtask_via_remote_request_does_not_add_response_to_main_task(self):
        maintask = create(Builder('task').titled('maintask'))

        # all different remote requests should not
        # generate an response
        maintask.REQUEST.environ['X_OGDS_AC'] = 'hugo.boss'
        create(Builder('task').within(maintask).titled('subtask'))
        self.assertEquals(0, len(IResponseContainer(maintask)))

        maintask.REQUEST.environ['X_OGDS_AC'] = None
        maintask.REQUEST.environ['X_OGDS_AUID'] = 'client1'
        create(Builder('task').within(maintask).titled('subtask'))
        self.assertEquals(0, len(IResponseContainer(maintask)))

        maintask.REQUEST.environ['X_OGDS_AUID'] = None
        maintask.REQUEST.set('X-CREATING-SUCCESSOR', True)
        create(Builder('task').within(maintask).titled('subtask'))
        self.assertEquals(0, len(IResponseContainer(maintask)))
Example #17
0
    def test_test_and_closed_sync(self):
        """The responsible value None is given in string (remote_request)
        the responsible should not be set."""

        task = self.providing_stub([ITask, IAttributeAnnotatable])
        self.expect(task.Type()).result('opengever.task.task')

        # request
        request = self.stub_request(
            interfaces=[IInternalOpengeverRequestLayer, ],
            stub_response=False)
        getter = self.stub()
        self.expect(request.get).result(getter)
        self.expect(getter('text')).result(u'Closing text')
        self.expect(getter('responsible')).result('None')
        self.expect(getter('responsible_client')).result('None')
        self.expect(getter('transition')).result(
            u'task-transition-tested-and-closed')

        #response
        response = self.stub_response(request=request)
        self.expect(response.setHeader("Content-type", "text/plain"))

        # worfklow_tool
        wft = self.stub()
        self.mock_tool(wft, 'portal_workflow')

        with self.mocker.order():
            wft.getInfoFor(task, 'review_state').result(
                'task-state-in-progress')
            wft.getInfoFor(task, 'review_state').result(
                'task-state-tested-and-closed')

        wft.doActionFor(task, u'task-transition-tested-and-closed')
        wft.getTitleForStateOnType(
            ANY, 'opengever.task.task').result('Closed')

        self.replay()

        view = SyncTaskWorkflowStateReceiveView(task, request)
        view()

        self.assertEquals(IResponseContainer(task)[0].text, u'Closing text')
        self.assertEquals(len(IResponseContainer(task)), 1)
    def test_add_response_appends_a_new_response_obj_to_the_context_response_container(
            self):
        dossier = create(Builder('dossier'))
        task = create(Builder('task').within(dossier))

        response_container = IResponseContainer(task)

        self.assertEqual(0, len(response_container))
        ICommentResponseHandler(task).add_response("My response")
        self.assertEqual(1, len(response_container))
Example #19
0
    def test_adds_an_corresponding_response(self, browser):
        self.assign_task('James', 'james.bond', 'Please make that for me.')

        response = IResponseContainer(self.task)[-1]

        self.assertEquals(
            [{'after': u'james.bond', 'id': 'responsible',
             'name': u'label_responsible', 'before': 'test_user_1_'}],
            response.changes)
        self.assertEquals('Please make that for me.', response.text)
Example #20
0
    def test_add_form(self):
        data = {'form.widgets.transition': 'task-transition-open-in-progress'}
        self.browser.open('%s/addresponse' % self.task.absolute_url(),
                          data=urllib.urlencode(data))

        self.assertEquals('Test task 1: task-transition-open-in-progress',
                          self.browser.locate(".documentFirstHeading").text)

        self.browser.fill_in("form.widgets.text", value="peter")
        self.browser.click("form.buttons.save")
        self.assertEquals(len(IResponseContainer(self.task)), 1)
Example #21
0
    def test_send_responses(self):
        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        responses = IResponseContainer(copy)
        self.assertEquals(1, len(responses))
        self.assertEquals('task-transition-open-in-progress',
                          responses[0].transition)
        self.assertEquals(u'Ich \xfcbernehme diese Aufgabe', responses[0].text)
        self.assertEquals(TEST_USER_ID, responses[0].creator)
Example #22
0
def reassign_team_tasks(task, event):
    if event.action != 'task-transition-open-in-progress':
        return

    if task.is_team_task:
        old_responsible = ITask(task).responsible
        ITask(task).responsible = api.user.get_current().getId()
        IResponseContainer(task)[-1].add_change(
            'responsible', _(u"label_responsible", default=u"Responsible"),
            old_responsible,
            ITask(task).responsible)
Example #23
0
    def test_add_form_with_related_items(self):
        self.browser.open('%s/addresponse' % self.task.absolute_url())

        self.browser.fill_in("form.widgets.relatedItems.widgets.query",
                             value=u"Doc 1")
        self.browser.click("form.widgets.relatedItems.buttons.search")
        self.browser.check("Doc 1")
        self.browser.click("form.buttons.save")

        self.assertEquals(len(IResponseContainer(self.task)), 1)
        self.assertEquals(self.task.relatedItems[0].to_object, self.doc1)
Example #24
0
    def test_migrates_plone_task_responsible_after(self):
        task = create(Builder('task'))

        response = Response('')
        response.add_change('responsible', 'foo', 'peter', 'HANS.MUSTER')
        IResponseContainer(task).add(response)

        PloneTasksMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        self.assertEquals('hans.muster', response.changes[-1]['after'])
Example #25
0
    def test_migrates_plone_task_response_creator(self):
        task = create(Builder('task'))

        response = Response('')
        response.creator = 'HANS.MUSTER'
        IResponseContainer(task).add(response)

        PloneTasksMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        self.assertEquals('hans.muster', response.creator)
    def test_comment_is_synced_to_successor(self):
        predecessor = create(Builder('task'))
        successor = create(Builder('task').successor_from(predecessor))

        activate_request_layer(self.portal.REQUEST,
                               IInternalOpengeverRequestLayer)

        response_container = IResponseContainer(successor)

        self.assertEqual(0, len(response_container))
        ICommentResponseHandler(predecessor).add_response("My response")
        self.assertEqual(1, len(response_container))
Example #27
0
    def test_null_fallback(self, browser):
        # add null response
        null_response = Response(None)
        IResponseContainer(self.task).add(null_response)
        transaction.commit()

        browser.login()
        self.visit_overview(browser)

        self.assertEqual('answer null-transition',
                         browser.css('div.answer')[0].get('class'))
        self.assertEqual('', self.get_latest_answer(browser))
    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))
Example #29
0
    def test_adds_an_corresponding_response(self, browser):
        self.login(self.regular_user, browser=browser)

        responsible = 'fa:{}'.format(self.secretariat_user.getId())
        self.assign_task(responsible, u'Please make that for me.')

        response = IResponseContainer(self.task)[-1]
        self.assertEquals([{
            'after': self.secretariat_user.getId(),
            'id': 'responsible',
            'name': u'label_responsible',
            'before': self.regular_user.getId()
        }], response.changes)
        self.assertEquals('Please make that for me.', response.text)
    def test_do_not_add_the_same_response_twice_but_return_ok_anyway(self):
        task = create(Builder('task').in_state('task-state-in-progress'))

        self.prepare_request(task,
                             text=u'Response text!',
                             transition='base-response')

        receiver = BaseResponseSyncerReceiver(task, self.request)

        self.assertEquals('OK', receiver())
        self.assertEquals('OK', receiver())

        response_container = IResponseContainer(task)
        self.assertEqual(1, len(response_container),
                         "Should not add the same response twice")
    def test_adds_a_response_to_the_given_context(self):
        task = create(Builder('task'))

        self.prepare_request(task,
                             text=u'Response text',
                             transition='base-response')

        BaseResponseSyncerReceiver(task, self.request)()

        response_container = IResponseContainer(task)
        self.assertEqual(1, len(response_container))

        response = response_container[0]

        self.assertEqual('Response text', response.text)
        self.assertEqual('base-response', response.transition)
Example #32
0
    def test_deadline_change_synchronisation(self):
        IDeadlineModifier(self.task).modify_deadline(
            date(2016, 03, 29), u'Frist wurde verschoben.',
            u'task-transition-modify-deadline')

        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        self.assertEquals([{
            u'after': date(2016, 03, 29),
            u'id': u'deadline',
            u'name': u'label_deadline',
            u'before': date(2016, 03, 27)
        }],
                          IResponseContainer(copy)[1].changes)
Example #33
0
    def test_response_and_response_changes_are_persistent(self, browser):
        self.login(self.dossier_responsible, browser=browser)

        browser.open(self.task)
        browser.click_on('task-transition-modify-deadline')
        browser.fill({
            'Response': u'Nicht mehr so dringend ...',
            'New Deadline': '1.1.2017'
        })
        browser.click_on('Save')

        response = IResponseContainer(self.task)[-1]

        self.assertIsInstance(response, Persistent)
        self.assertIsInstance(response.changes, PersistentList)
        self.assertIsInstance(response.changes[0], PersistentMapping)
    def test_assign_add_corresonding_response(self):
        self.assign_forwarding('client2', 'Fake Response')

        response = IResponseContainer(self.forwarding)[-1]

        responsible_change = {'id': 'responsible',
                              'name': u'label_responsible',
                              'before': u'inbox:client1',
                              'after': u'inbox:client2'}

        responsible_client_change = {'id': 'responsible_client',
                                     'name': u'label_resonsible_client',
                                     'before': u'client1',
                                     'after': u'client2'}

        self.assertEquals([responsible_change, responsible_client_change],
                          response.changes)
Example #35
0
 def test_addresponse(self):
     t1 = create(Builder('task').titled('Task 1'))
     res = Response("")
     container = IResponseContainer(t1)
     container.add(res)
     self.failUnless(res in container)
Example #36
0
    def handleSubmit(self, action):
        data, errors = self.extractData()
        if errors:
            errorMessage = '<ul>'
            for error in errors:
                if errorMessage.find(error.message):
                    errorMessage += '<li>' + error.message + '</li>'
            errorMessage += '</ul>'
            self.status = errorMessage
            return None

        else:
            new_response = Response(data.get('text'))
            #define responseTyp
            responseCreator = new_response.creator
            task = aq_inner(self.context)

            if responseCreator == '(anonymous)':
                new_response.type = 'additional'
            if responseCreator == task.Creator():
                new_response.type = 'clarification'

            if data.get('transition', None):
                new_response.transition = data.get('transition', None)

            #if util.getManagersVocab.getTerm(responseCreator):
            #   new_response.type =  'reply'
            #check transition
            if data.get('transition', None) in (
                'task-transition-open-resolved',
                'task-transition-in-progress-resolved'):

                completion_date = datetime.date.today()

            else:
                completion_date = None

            #check other fields
            options = [
                # (task.deadline, data.get('deadline'), 'deadline',
                #  _('deadline')),
                (task.date_of_completion, completion_date,
                 'date_of_completion', _('date_of_completion'))]
            for task_field, resp_field, option, title in options:
                if resp_field and task_field != resp_field:
                    new_response.add_change(option,
                                            title,
                                            task_field,
                                            resp_field)
                    task.__setattr__(option, resp_field)

            # save relatedItems on task
            related_ids = []
            if getattr(task, 'relatedItems'):
                related_ids = [item.to_id for item in task.relatedItems]

            relatedItems = data.get('relatedItems') or []
            intids = getUtility(IIntIds)
            for item in relatedItems:
                to_id = intids.getId(item)
                # relation allready exists
                item._v__is_relation = True
                if to_id not in related_ids:
                    if getattr(task, 'relatedItems'):
                        task.relatedItems.append(RelationValue(to_id))
                    else:
                        setattr(task, 'relatedItems', [RelationValue(to_id)])

                new_response.add_change('relatedItems',
                                        _(u'label_related_items',
                                          default=u"Related Items"),
                                        '',
                                        linked(item, item.Title()))

            # change workflow state of task
            if data.get('transition'):
                wftool = getToolByName(self.context, 'portal_workflow')
                before = wftool.getInfoFor(self.context, 'review_state')
                if data.get('transition') != before:
                    before = wftool.getTitleForStateOnType(before, task.Type())
                    wftool.doActionFor(self.context, data.get('transition'))
                    after = wftool.getInfoFor(self.context, 'review_state')
                    after = wftool.getTitleForStateOnType(after, task.Type())
                    new_response.add_change('review_state', _(u'Issue state'),
                                            before, after)

            container = IResponseContainer(self.context)
            container.add(new_response)

            notify(ObjectModifiedEvent(self.context))

            if data.get('transition'):
                syncer = getMultiAdapter((self.context, self.request),
                                         IWorkflowStateSyncer)
                syncer.change_remote_tasks_workflow_state(
                    data.get('transition'), text=data.get('text'))

            copy_related_documents_view = self.context.restrictedTraverse(
                '@@copy-related-documents-to-inbox')
            if copy_related_documents_view.available():
                url = os.path.join(self.context.absolute_url(),
                                   '@@copy-related-documents-to-inbox')
            else:
                url = self.context.absolute_url()
            self.request.RESPONSE.redirect(url)
            return new_response
Example #37
0
 def test_addresponse(self):
     t1 = create_task(self.portal, title='Task 1')
     res = Response("")
     container = IResponseContainer(t1)
     container.add(res)
     self.failUnless(res in container)