def setUp(self):
        super(TestAllUsersInboxesAndTeamsSourceForWorkspace, self).setUp()
        self.login(self.administrator)
        self.org_unit2 = create(Builder('org_unit')
                                .id('unit2')
                                .having(title=u'Finanzdirektion',
                                        admin_unit=get_current_admin_unit())
                                .with_default_groups())

        self.john = create(Builder('ogds_user')
                           .id('john')
                           .having(firstname=u'John', lastname=u'Doe')
                           .assign_to_org_units([get_current_org_unit()]))
        self.hugo = create(Builder('ogds_user')
                           .id('hugo')
                           .having(firstname=u'Hugo', lastname=u'Boss')
                           .assign_to_org_units([get_current_org_unit()]))
        self.hans = create(Builder('ogds_user')
                           .id('hans')
                           .having(firstname=u'Hans', lastname=u'Peter')
                           .assign_to_org_units([get_current_org_unit(),
                                                 self.org_unit2]))
        self.reto = create(Builder('ogds_user')
                           .id('reto')
                           .having(firstname=u'Reto', lastname=u'Rageto')
                           .assign_to_org_units([self.org_unit2]))
 def test_sql_task_is_created_on_plone_object_creation(self):
     self.assertEqual(1, Session.query(Task).count())
     task = Session.query(Task).one()
     self.assertEqual(get_current_org_unit().id(), task.assigned_org_unit)
     self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
     self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
     self.assertEqual(u'Mach mau!', task.title)
     self.assertEqual(self.user.userid, task.issuer)
     self.assertEqual(self.user.userid, task.responsible)
     self.assertEqual(u'dossier > subdossier > Mach mau!',
                      task.breadcrumb_title)
     self.assertEqual(u'task-state-open', task.review_state)
     self.assertEqual(u'dossier-1/dossier-2/task-1', task.physical_path)
     self.assertIsNotNone(task.icon)
     self.assertEqual(task.deadline, date(2010, 1, 1))
     self.assertIsNotNone(task.modified)
     self.assertEqual('direct-execution', task.task_type)
     self.assertFalse(task.is_subtask)
     self.assertEqual(1, task.sequence_number)
     self.assertEqual('Client1 / 1.1', task.reference_number)
     self.assertEqual('dossier', task.containing_dossier)
     self.assertEqual('subdossier', task.containing_subdossier)
     self.assertEqual(2, task.dossier_sequence_number)
     self.assertEqual('Lorem ipsum dolor sit amet, consectetur', task.text)
     self.assertSequenceEqual([TEST_USER_ID], task.principals)
     self.assertIsNone(task.predecessor)
    def setUp(self):
        super(TestAllUsersInboxesAndTeamsSourceForWorkspace, self).setUp()
        self.login(self.administrator)
        self.org_unit2 = create(
            Builder('org_unit').id('unit2').having(
                title=u'Finanzdirektion',
                admin_unit=get_current_admin_unit()).with_default_groups())

        self.john = create(
            Builder('ogds_user').id('john').having(
                firstname=u'John',
                lastname=u'Doe').assign_to_org_units([get_current_org_unit()]))
        self.hugo = create(
            Builder('ogds_user').id('hugo').having(
                firstname=u'Hugo',
                lastname=u'Boss').assign_to_org_units([get_current_org_unit()
                                                       ]))
        self.hans = create(
            Builder('ogds_user').id('hans').having(
                firstname=u'Hans', lastname=u'Peter').assign_to_org_units(
                    [get_current_org_unit(), self.org_unit2]))
        self.reto = create(
            Builder('ogds_user').id('reto').having(
                firstname=u'Reto',
                lastname=u'Rageto').assign_to_org_units([self.org_unit2]))
    def test_sql_task_is_updated_on_plone_object_update(self):
        self.login(self.regular_user)
        self.task.responsible_client = 'rk'
        self.task.title = u'G\xf6pf, iz mach mau'
        notify(ObjectModifiedEvent(self.task))

        self.assertEqual(15, Session.query(Task).count())
        task = Session.query(Task).filter(
            Task.title == u'G\xf6pf, iz mach mau').one()

        self.assertEqual('rk', task.assigned_org_unit)
        expected_breadcrumbs = (
            u'Ordnungssystem'
            u' > 1. F\xfchrung'
            u' > 1.1. Vertr\xe4ge und Vereinbarungen'
            u' > Vertr\xe4ge mit der kantonalen Finanzverwaltung'
            u' > G\xf6pf, iz mach mau'
        )  # Do not add commas here - this is a string!
        self.assertEqual(expected_breadcrumbs, task.breadcrumb_title)
        self.assertEqual(u'G\xf6pf, iz mach mau', task.title)

        self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
        self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
        self.assertEqual(self.dossier_responsible.getId(), task.issuer)
        self.assertEqual(self.regular_user.getId(), task.responsible)
        self.assertEqual('task-state-in-progress', task.review_state)
        self.assertEqual(
            'ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/task-1',
            task.physical_path)
        self.assertIsNotNone(task.icon)
        self.assertEqual(task.deadline, date(2016, 11, 1))
        self.assertIsNotNone(task.modified)
        self.assertEqual('correction', task.task_type)
        self.assertFalse(task.is_subtask)
        self.assertEqual(1, task.sequence_number)
        self.assertEqual('Client1 1.1 / 1', task.reference_number)
        self.assertEqual(u'Vertr\xe4ge mit der kantonalen Finanzverwaltung',
                         task.containing_dossier)
        self.assertEqual('', task.containing_subdossier)
        self.assertEqual(1, task.dossier_sequence_number)
        self.assertIsNone(task.text)
        expected_principals = [
            get_current_org_unit().users_group.id(),
            self.regular_user.getId(),
            get_current_org_unit().inbox_group.id(), u'rk_inbox_users'
        ]
        self.assertItemsEqual(expected_principals, task.principals)
        self.assertIsNone(task.predecessor)
    def test_search_for_users(self, browser):
        self.login(self.workspace_admin, browser=browser)

        for number in range(20):
            create(Builder('ogds_user')
                   .assign_to_org_units([get_current_org_unit()])
                   .having(firstname='Hans-{}'.format(str(number)),
                           lastname='Muster')
                   .id('hans.muster{}'.format(str(number))))

        browser.open(self.workspace.absolute_url() + '/manage-participants/search',
                     data={'q': 'beatrice'})

        self.assertEquals(
            {u'total_count': 1,
             u'pagination': {u'more': False},
             u'page': 1,
             u'results': [
                 {u'text': u'Schr\xf6dinger B\xe9atrice (beatrice.schrodinger)',
                  u'_resultId': u'beatrice.schrodinger',
                  u'id': u'beatrice.schrodinger'}]},
            browser.json)

        browser.open(self.workspace.absolute_url() + '/manage-participants/search',
                     data={'q': 'hans'})

        self.assertEquals(21, browser.json['total_count'])
        self.assertEquals({u'more': True}, browser.json['pagination'])
        self.assertEquals(1, browser.json['page'])
        self.assertEquals(20, len(browser.json['results']))
Example #6
0
    def test_search_for_users(self, browser):
        self.login(self.workspace_admin, browser=browser)

        # beatrice.schrodinger is already a workspace member and cannot be invited
        self.assertEqual('beatrice.schrodinger', self.workspace_member.id)
        browser.open(self.workspace.absolute_url() + '/manage-participants/search',
                     data={'q': 'beatrice'})
        self.assertEquals(0, browser.json['total_count'])

        browser.open(self.workspace.absolute_url() + '/manage-participants/search',
                     data={'q': 'kathi'})
        self.assertEquals(
            {u'total_count': 1,
             u'pagination': {u'more': False},
             u'page': 1,
             u'results': [{u'_resultId': u'kathi.barfuss',
                           u'id': u'kathi.barfuss',
                           u'text': u'B\xe4rfuss K\xe4thi (kathi.barfuss)'}]},
            browser.json)

        for number in range(20):
            create(Builder('ogds_user')
                   .assign_to_org_units([get_current_org_unit()])
                   .having(firstname='Kathi-{}'.format(str(number)),
                           lastname='Muster')
                   .id('hans.muster{}'.format(str(number))))

        browser.open(self.workspace.absolute_url() + '/manage-participants/search',
                     data={'q': 'kathi'})

        self.assertEquals(21, browser.json['total_count'])
        self.assertEquals({u'more': True}, browser.json['pagination'])
        self.assertEquals(1, browser.json['page'])
        self.assertEquals(20, len(browser.json['results']))
    def get_task_rows(self):
        """Returns a dict of task-rows (tuples of cells) of all open tasks on
        the current client:

        incoming -- open tasks assigned to the current client
        outgoing -- open tasks assigned to another client
        """

        org_unit_id = get_current_org_unit().id()

        incoming_query = Session().query(Task)
        incoming_query = incoming_query.filter(
            Task.assigned_org_unit == org_unit_id)
        incoming_query = self._extend_task_query(incoming_query)

        incoming = []
        for task in incoming_query.all():
            incoming.append(self.get_row_for_item(
                            task,
                            display_issuing_org_unit=True))

        outgoing_query = Session().query(Task)
        outgoing_query = outgoing_query.filter(
            Task.issuing_org_unit == org_unit_id)
        outgoing_query = self._extend_task_query(outgoing_query)

        outgoing = []
        for task in outgoing_query.all():
            outgoing.append(self.get_row_for_item(
                task, display_assigned_org_unit=True))

        return {'incoming': incoming,
                'outgoing': outgoing}
Example #8
0
    def is_user_allowed_to_view_additional_tabs(self):
        """The additional tabs Alltasks and AllIssuedTasks are only shown
        to adminsitrators and users of the current inbox group."""

        inbox = get_current_org_unit().inbox()
        current_user = ogds_service().fetch_current_user()
        return current_user in inbox.assigned_users() or self._is_user_admin()
Example #9
0
    def is_user_allowed_to_view_additional_tabs(self):
        """The additional tabs Alltasks and AllIssuedTasks are only shown
        to adminsitrators and users of the current inbox group."""

        inbox = get_current_org_unit().inbox()
        current_user = ogds_service().fetch_current_user()
        return current_user in inbox.assigned_users() or self._is_user_admin()
    def create_successor_task(self, dossier):
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(self.context)
            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)

        # 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(self.context, task)

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

        return task
Example #11
0
    def create_main_task(self, templatefolder, selected_templates):
        highest_deadline = max(
            [template.deadline for template in selected_templates])

        data = dict(
            title=templatefolder.title,
            issuer=self.replace_interactive_user('current_user'),
            responsible=self.replace_interactive_user('current_user'),
            responsible_client=get_current_org_unit().id(),
            task_type='direct-execution',
            deadline=date.today() +
            timedelta(highest_deadline + MAIN_TASK_DEADLINE_DELTA),
        )

        main_task = createContent('opengever.task.task', **data)
        notify(ObjectCreatedEvent(main_task))
        main_task = addContentToContainer(
            self.context, main_task, checkConstraints=True)

        self.mark_as_generated_from_tasktemplate(main_task)

        # set the main_task in to the in progress state
        api.content.transition(obj=main_task,
                               transition='task-transition-open-in-progress')

        return main_task
Example #12
0
    def create_main_task(self, templatefolder, selected_templates):
        highest_deadline = max(
            [template.deadline for template in selected_templates])

        deadline_timedelta = api.portal.get_registry_record(
            'deadline_timedelta', interface=ITaskSettings)

        data = dict(
            title=templatefolder.title,
            issuer=self.replace_interactive_user('current_user'),
            responsible=self.replace_interactive_user('current_user'),
            responsible_client=get_current_org_unit().id(),
            task_type='direct-execution',
            deadline=date.today() +
            timedelta(highest_deadline + deadline_timedelta),
        )

        main_task = createContent('opengever.task.task', **data)
        notify(ObjectCreatedEvent(main_task))
        main_task = addContentToContainer(self.context,
                                          main_task,
                                          checkConstraints=True)

        self.mark_as_generated_from_tasktemplate(main_task)

        # set the main_task in to the in progress state
        api.content.transition(obj=main_task,
                               transition='task-transition-open-in-progress')

        return main_task
    def fill(self, users, auto_org_unit=True):
        """Fill the AsyncKeywordWidget, auto.

        Mostly copied over from
        ``ftw.keywordwidget.tests.widget.AsyncKeywordWidget``.

        Can take a ``MemberData``, ``str`` or ``unicode`` object as an input.

        Having a colon in a string or a unicode input is considered a manual
        override for the org unit, or a non-user input, like a team, a foreign
        org unit or an inbox.

        Cases where a user without an admin unit is required, like search,
        are handled via ``auto_org_unit=True``.
        """
        if isinstance(users, (MemberData, str, unicode)):
            users = [users]

        if not all(
                isinstance(user, (MemberData, str, unicode))
                for user in users):
            raise ValueError(
                "You can only pass in MemberData objects or user ID strings.")

        if auto_org_unit:
            org_unit = get_current_org_unit().id()
        else:
            org_unit = None

        users = tuple(self.user_to_string(user, org_unit) for user in users)
        super(OpengeverResponsibleUsersAsyncKeywordWidget, self).fill(users)
    def test_sql_task_is_created_on_plone_object_creation(self):
        self.login(self.regular_user)
        self.assertEqual(15, Session.query(Task).count())

        # self.private_task
        task = Session.query(Task).filter(
            Task.title == u'Diskr\xe4te Dinge').one()
        self.assertEqual(get_current_org_unit().id(), task.assigned_org_unit)
        self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
        self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
        self.assertEqual(u'Diskr\xe4te Dinge', task.title)
        self.assertEqual(self.dossier_responsible.getId(), task.issuer)
        self.assertTrue(task.is_private)
        self.assertEqual(self.regular_user.getId(), task.responsible)
        expected_breadcrumbs = (
            u'Ordnungssystem'
            u' > 1. F\xfchrung'
            u' > 1.1. Vertr\xe4ge und Vereinbarungen'
            u' > Vertr\xe4ge mit der kantonalen Finanzverwaltung'
            u' > Diskr\xe4te Dinge'
        )  # Do not add commas here - this is a string!
        self.assertEqual(expected_breadcrumbs, task.breadcrumb_title)
        self.assertEqual('task-state-in-progress', task.review_state)
        self.assertEqual(
            'ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/task-12',
            task.physical_path)
        self.assertIsNotNone(task.icon)
        self.assertEqual(task.deadline, date(2020, 1, 1))
        self.assertIsNotNone(task.modified)
        self.assertEqual('direct-execution', task.task_type)
        self.assertFalse(task.is_subtask)
        self.assertEqual(12, task.sequence_number)
        self.assertEqual('Client1 1.1 / 1', task.reference_number)
        self.assertEqual(
            u'Vertr\xe4ge mit der kantonalen Finanzverwaltung',
            task.containing_dossier,
        )
        self.assertEqual('', task.containing_subdossier)
        self.assertEqual(1, task.dossier_sequence_number)
        self.assertEqual(u'L\xf6rem ipsum dolor sit amet, consectetur',
                         task.text)
        expected_principals = [
            get_current_org_unit().users_group.id(),
            self.regular_user.getId()
        ]
        self.assertItemsEqual(expected_principals, task.principals)
        self.assertIsNone(task.predecessor)
    def test_is_responsible_checks_inbox_members_if_issuer_is_a_inbox(self):
        self.login(self.regular_user)
        self.task.responsible = get_current_org_unit().inbox().id()
        self.task.get_sql_object().sync_with(self.task)
        self.assertFalse(get_checker(self.task).current_user.is_responsible)

        self.login(self.secretariat_user)
        self.assertTrue(get_checker(self.task).current_user.is_responsible)
    def test_sql_task_is_updated_on_plone_object_update(self):
        self.login(self.regular_user)
        self.task.responsible_client = 'rk'
        self.task.title = u'G\xf6pf, iz mach mau'
        notify(ObjectModifiedEvent(self.task))

        self.assertEqual(15, Session.query(Task).count())
        task = Session.query(Task).filter(
            Task.title == u'G\xf6pf, iz mach mau').one()

        self.assertEqual('rk', task.assigned_org_unit)
        expected_breadcrumbs = (
            u'Ordnungssystem'
            u' > 1. F\xfchrung'
            u' > 1.1. Vertr\xe4ge und Vereinbarungen'
            u' > Vertr\xe4ge mit der kantonalen Finanzverwaltung'
            u' > G\xf6pf, iz mach mau'
        )  # Do not add commas here - this is a string!
        self.assertEqual(expected_breadcrumbs, task.breadcrumb_title)
        self.assertEqual(u'G\xf6pf, iz mach mau', task.title)

        self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
        self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
        self.assertEqual(self.dossier_responsible.getId(), task.issuer)
        self.assertEqual(self.regular_user.getId(), task.responsible)
        self.assertEqual('task-state-in-progress', task.review_state)
        self.assertEqual(
            'ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/task-1',
            task.physical_path)
        self.assertIsNotNone(task.icon)
        self.assertEqual(task.deadline, date(2016, 11, 1))
        self.assertIsNotNone(task.modified)
        self.assertEqual('correction', task.task_type)
        self.assertFalse(task.is_subtask)
        self.assertEqual(1, task.sequence_number)
        self.assertEqual('Client1 1.1 / 1', task.reference_number)
        self.assertEqual(
            u'Vertr\xe4ge mit der kantonalen Finanzverwaltung', task.containing_dossier)
        self.assertEqual('', task.containing_subdossier)
        self.assertEqual(1, task.dossier_sequence_number)
        self.assertIsNone(task.text)
        expected_principals = [
            get_current_org_unit().users_group.id(), self.regular_user.getId(),
            get_current_org_unit().inbox_group.id(), u'rk_inbox_users']
        self.assertItemsEqual(expected_principals, task.principals)
        self.assertIsNone(task.predecessor)
    def get_render_arguments(self):
        self.layout.show_organisation = True
        self.layout.use_package('longtable')

        args = self.get_task_rows()
        args['client'] = get_current_org_unit().label()

        return args
    def test_is_responsible_checks_inbox_members_if_issuer_is_a_inbox(self):
        self.login(self.regular_user)
        self.task.responsible = get_current_org_unit().inbox().id()
        self.task.get_sql_object().sync_with(self.task)
        self.assertFalse(get_checker(self.task).current_user.is_responsible)

        self.login(self.secretariat_user)
        self.assertTrue(get_checker(self.task).current_user.is_responsible)
    def update(self):
        """Store default value for relatedItems in the request.

        The added objects will later be moved inside the forwarding.
        """
        paths = self.request.get('paths', [])

        search_endpoint = (
            '++widget++form.widgets.responsible/search'
            in self.request.get('ACTUAL_URL', '')
            )

        if not (
                search_endpoint
                or paths
                or self.request.form.get('form.widgets.relatedItems', [])
            ):
            # add status message and redirect current window back to inbox
            # but ONLY if we're not in a z3cform_inline_validation.
            IStatusMessage(self.request).addStatusMessage(
                _(
                    u'error_no_document_selected',
                    u'Error: Please select at least one document to forward.',
                    ),
                type=u'error',
                )

            redir_url = self.request.get(
                'orig_template',
                self.context.absolute_url(),
                )

            self.request.RESPONSE.redirect(redir_url)

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

        # put default value for issuer into request
        if not self.request.get('form.widgets.issuer', None):
            self.request.set(
                'form.widgets.issuer',
                get_current_org_unit().inbox().id(),
                )

        # put the default responsible into the request
        if not self.request.get('form.widgets.responsible_client', None):
            org_unit = (
                get_ou_selector(ignore_anonymous=True).get_current_unit()
                )

            self.request.set('form.widgets.responsible_client', org_unit.id())

            self.request.set(
                'form.widgets.responsible',
                [org_unit.inbox().id()],
                )

        super(ForwardingAddForm, self).update()
    def test_sql_task_is_created_on_plone_object_creation(self):
        self.login(self.regular_user)
        self.assertEqual(15, Session.query(Task).count())

        # self.private_task
        task = Session.query(Task).filter(
            Task.title == u'Diskr\xe4te Dinge').one()
        self.assertEqual(get_current_org_unit().id(), task.assigned_org_unit)
        self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
        self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
        self.assertEqual(u'Diskr\xe4te Dinge', task.title)
        self.assertEqual(self.dossier_responsible.getId(), task.issuer)
        self.assertTrue(task.is_private)
        self.assertEqual(self.regular_user.getId(), task.responsible)
        expected_breadcrumbs = (
            u'Ordnungssystem'
            u' > 1. F\xfchrung'
            u' > 1.1. Vertr\xe4ge und Vereinbarungen'
            u' > Vertr\xe4ge mit der kantonalen Finanzverwaltung'
            u' > Diskr\xe4te Dinge'
        )  # Do not add commas here - this is a string!
        self.assertEqual(expected_breadcrumbs, task.breadcrumb_title)
        self.assertEqual('task-state-in-progress', task.review_state)
        self.assertEqual(
            'ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/task-12',
            task.physical_path)
        self.assertIsNotNone(task.icon)
        self.assertEqual(task.deadline, date(2020, 1, 1))
        self.assertIsNotNone(task.modified)
        self.assertEqual('direct-execution', task.task_type)
        self.assertFalse(task.is_subtask)
        self.assertEqual(12, task.sequence_number)
        self.assertEqual('Client1 1.1 / 1', task.reference_number)
        self.assertEqual(
            u'Vertr\xe4ge mit der kantonalen Finanzverwaltung',
            task.containing_dossier,
        )
        self.assertEqual('', task.containing_subdossier)
        self.assertEqual(1, task.dossier_sequence_number)
        self.assertEqual(
            u'L\xf6rem ipsum dolor sit amet, consectetur', task.text)
        expected_principals = [
            get_current_org_unit().users_group.id(), self.regular_user.getId()]
        self.assertItemsEqual(expected_principals, task.principals)
        self.assertIsNone(task.predecessor)
Example #21
0
    def issued_tasks(self):
        """Returns the 5 last modified open task which are issued
        by the current org unit's inbox.
        """
        current_inbox_id = get_current_org_unit().inbox().id()
        query = Task.query.users_issued_tasks(current_inbox_id)
        query = query.filter(Task.review_state.in_(OPEN_TASK_STATES))
        query = query.order_by(desc(Task.modified))

        return query.limit(5).all()
Example #22
0
    def issued_tasks(self):
        """Returns the 5 last modified open task which are issued
        by the current org unit's inbox.
        """
        current_inbox_id = get_current_org_unit().inbox().id()
        query = Task.query.users_issued_tasks(current_inbox_id)
        query = query.filter(Task.review_state.in_(OPEN_TASK_STATES))
        query = query.order_by(desc(Task.modified))

        return query.limit(5).all()
Example #23
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
Example #24
0
    def get_responsible_client(self, template, responsible):
        if template.responsible_client == 'interactive_users':
            current_org_unit = get_current_org_unit()
            responsible_org_units = ogds_service().assigned_org_units(responsible)

            if current_org_unit in responsible_org_units or \
               not responsible_org_units:
                return current_org_unit.id()
            else:
                return responsible_org_units[0].id()

        return template.responsible_client
Example #25
0
    def get_responsible_client(self, template, responsible):
        if template.responsible_client == INTERACTIVE_USERS:
            current_org_unit = get_current_org_unit()
            responsible_org_units = ogds_service().assigned_org_units(responsible)

            if current_org_unit in responsible_org_units or \
               not responsible_org_units:
                return current_org_unit.id()
            else:
                return responsible_org_units[0].id()

        return template.responsible_client
Example #26
0
    def get_responsible_client(self, template, responsible):
        if template.responsible_client == 'interactive_users':
            current_org_unit = get_current_org_unit()
            responsible_org_units = ogds_service().assigned_org_units(responsible)

            if current_org_unit in responsible_org_units or \
               not responsible_org_units:
                return current_org_unit.id()
            else:
                return responsible_org_units[0].id()

        return template.responsible_client
Example #27
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
Example #28
0
    def __init__(self, obj, event):
        self.obj = obj
        self.event = event

        if not self.is_uninstalling_plone():
            self.admin_unit_id = get_current_admin_unit().id()
            self.current_org_unit_id = get_current_org_unit().id()
            self.sequence_number = self.obj.get_sequence_number()
            self.assigned_org_unit = obj.responsible_client
            self.obj_id = self.get_object_id()
            self.task_query = Session.query(Task).filter_by(
                admin_unit_id=self.admin_unit_id, int_id=self.obj_id)
    def disable_additional_org_units(self, org_unit_ids=None):
        if org_unit_ids is None:
            org_unit_ids = ('rk',)

        current_ou = get_current_org_unit()
        if current_ou in org_unit_ids:
            raise ValueError

        for ou_id in org_unit_ids:
            ou = OrgUnit.get(ou_id)
            create_session().delete(ou)

        current_ou._chosen_strategy = None
    def disable_additional_org_units(self, org_unit_ids=None):
        if org_unit_ids is None:
            org_unit_ids = ('rk',)

        current_ou = get_current_org_unit()
        if current_ou in org_unit_ids:
            raise ValueError

        for ou_id in org_unit_ids:
            ou = OrgUnit.get(ou_id)
            create_session().delete(ou)

        current_ou._chosen_strategy = None
    def updateWidgets(self):
        super(AdvancedSearchForm, self).updateWidgets()

        self.context.REQUEST.set('client', get_current_org_unit().id())
        searchableText = self.widgets["searchableText"]
        searchableText.value = self.request.get('SearchableText')

        for k, v in self.field_mapping().items():
            for name in v:
                if self.widgets.get(name, None):
                    self.widgets.get(name, None).addClass(k)

        self.set_object_provides_field_description()
    def updateWidgets(self):
        super(AdvancedSearchForm, self).updateWidgets()

        self.context.REQUEST.set('client', get_current_org_unit().id())
        searchableText = self.widgets["searchableText"]
        searchableText.value = self.request.get('SearchableText')

        for k, v in self.field_mapping().items():
            for name in v:
                if self.widgets.get(name, None):
                    self.widgets.get(name, None).addClass(k)

        self.set_object_provides_field_description()
Example #33
0
    def render(self):
        current_inbox = self.context.get_current_inbox()

        if current_inbox:
            return self.request.RESPONSE.redirect(current_inbox.absolute_url())
        else:
            msg = _(
                u'current_inbox_not_available',
                u'Your not allowed to access the inbox of ${current_org_unit}.',
                mapping={'current_org_unit': get_current_org_unit().label()})

            IStatusMessage(self.request).addStatusMessage(msg, type='warning')

        return super(InboxContainerView, self).render()
Example #34
0
    def render(self):
        current_inbox = self.context.get_current_inbox()

        if current_inbox:
            return self.request.RESPONSE.redirect(current_inbox.absolute_url())
        else:
            msg = _(
                u'current_inbox_not_available',
                u'Your not allowed to access the inbox of ${current_org_unit}.',
                mapping={'current_org_unit': get_current_org_unit().label()})

            IStatusMessage(self.request).addStatusMessage(msg, type='warning')

        return super(InboxContainerView, self).render()
    def test_sharing_view_uses_group_title_attribute_if_exists(self, browser):
        self.login(self.manager, browser)

        inbox_group = get_current_org_unit().inbox_group
        inbox_group.title = u'The inbox group title'
        api.group.grant_roles(
            groupname=inbox_group.id(), obj=self.dossier, roles=['Publisher'])

        browser.open(self.dossier, view='@@sharing')
        self.assertEqual(
            ['Logged-in users',
             'The inbox group title (fa_inbox_users)',
             'fa_users'],
            browser.css('#user-group-sharing-settings tr a').text)
    def create_main_task(self):
        data = dict(title=self.context.title,
                    issuer=api.user.get_current().getId(),
                    responsible=api.user.get_current().getId(),
                    responsible_client=get_current_org_unit().id(),
                    task_type='direct-execution',
                    deadline=self.get_main_task_deadline())

        main_task = self.add_task(self.dossier, data)

        # set the main_task in to the in progress state
        api.content.transition(obj=main_task,
                               transition='task-transition-open-in-progress')

        return main_task
Example #37
0
    def replace_interactive_actors(self, template):
        """The current systems knows two interactive users:

        `responsible`: the reponsible of the main dossier.
        `current_user`: the currently logged in user.
        """
        if template.responsible_client == INTERACTIVE_USERS:
            if template.responsible == 'responsible':
                principal = IDossier(self.context.get_main_dossier()).responsible
            elif template.responsible == 'current_user':
                principal = api.user.get_current().getId()

            return get_current_org_unit().id(), principal

        return template.responsible_client, template.responsible
Example #38
0
    def insert_org_units_group_id(self):
        """Insert the current org-unit's group_id for all committees.

        Bye default we use the users group. This choice is somewhat arbitrary,
        but id does not really matter since meeting is not in production when
        this upgrade is executed.

        """
        proposal_table = table("committees",
                               column("id"),
                               column("group_id"))
        group_id = get_current_org_unit().users_group.groupid

        self.execute(
            proposal_table.update().values(group_id=group_id))
Example #39
0
    def update(self):
        """put default value for relatedItems into request - the added
           objects will later be moved insed the forwarding
        """
        paths = self.request.get('paths', [])

        if not (paths or
                self.request.form.get('form.widgets.relatedItems', [])
        or '@@autocomplete-search' in self.request.get('ACTUAL_URL', '')):
            # add status message and redirect current window back to inbox
            # but ONLY if we're not in a z3cform_inline_validation or
            # autocomplete-search request!
            IStatusMessage(self.request).addStatusMessage(
                _(u'error_no_document_selected',
                  u'Error: Please select at least one document to forward'),
                type='error')
            redir_url = self.request.get('orig_template',
                                         self.context.absolute_url())
            self.request.RESPONSE.redirect(redir_url)

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

        # put default value for issuer into request
        if not self.request.get('form.widgets.issuer', None):
            self.request.set('form.widgets.issuer',
                             get_current_org_unit().inbox().id())

        # put the default responsible into the request
        if not self.request.get('form.widgets.responsible_client', None):
            org_unit = get_current_org_unit()
            self.request.set('form.widgets.responsible_client', org_unit.id())
            self.request.set('form.widgets.responsible',
                             [org_unit.inbox().id()])

        super(ForwardingAddForm, self).update()
Example #40
0
    def replace_interactive_actors(self, template):
        """The current systems knows two interactive users:

        `responsible`: the reponsible of the main dossier.
        `current_user`: the currently logged in user.
        """
        if template.responsible_client == INTERACTIVE_USERS:
            if template.responsible == 'responsible':
                principal = IDossier(
                    self.context.get_main_dossier()).responsible
            elif template.responsible == 'current_user':
                principal = api.user.get_current().getId()

            return get_current_org_unit().id(), principal

        return template.responsible_client, template.responsible
Example #41
0
    def get_sql_task(self):
        admin_unit_id = get_current_admin_unit().id()
        current_org_unit_id = get_current_org_unit().id()
        sequence_number = self.obj.get_sequence_number()
        assigned_org_unit = self.obj.responsible_client

        task = Session.query(Task).filter_by(
            admin_unit_id=admin_unit_id, int_id=self.obj_id).first()
        if task is None:
            task = Task(self.obj_id, admin_unit_id,
                        issuing_org_unit=current_org_unit_id,
                        assigned_org_unit=assigned_org_unit,
                        sequence_number=sequence_number,
                        created=self.obj.created().asdatetime())
            Session.add(task)
        return task
Example #42
0
    def get_sql_task(self):
        admin_unit_id = get_current_admin_unit().id()
        current_org_unit_id = get_current_org_unit().id()
        sequence_number = self.obj.get_sequence_number()
        assigned_org_unit = self.obj.responsible_client

        task = Session.query(Task).filter_by(
            admin_unit_id=admin_unit_id, int_id=self.obj_id).first()
        if task is None:
            task = Task(self.obj_id, admin_unit_id,
                        issuing_org_unit=current_org_unit_id,
                        assigned_org_unit=assigned_org_unit,
                        sequence_number=sequence_number,
                        created=self.obj.created().asdatetime())
            Session.add(task)
        return task
    def create_main_task(self):
        data = dict(
            title=self.context.title,
            issuer=api.user.get_current().getId(),
            responsible=api.user.get_current().getId(),
            responsible_client=get_current_org_unit().id(),
            task_type='direct-execution',
            deadline=self.get_main_task_deadline())

        main_task = self.add_task(self.dossier, data)

        # set the main_task in to the in progress state
        api.content.transition(obj=main_task,
                               transition='task-transition-open-in-progress')

        return main_task
Example #44
0
    def _extend_task_query(self, query):
        """Extends a globalindex task query.
        """

        # sort by deadline
        query = query.order_by(asc(Task.deadline))

        # list only open tasks
        query = query.filter(Task.review_state.in_(OPEN_TASK_STATES))

        # If a task has a successor task, list only one of them.
        # List only the one which is assigned to this client.
        query = query.filter(
            or_(and_(Task.predecessor == None, Task.successors == None),
                Task.admin_unit_id == get_current_org_unit().id()))

        return query
Example #45
0
    def render(self):
        # set responsible
        org_unit = get_current_org_unit()
        self.context.responsible_client = org_unit.id()
        self.context.responsible = org_unit.inbox().id()

        # create a response in the task
        add_simple_response(
            self.context,
            field_changes=(
                (ITask['responsible'], self.context.responsible),
                (ITask['responsible_client'],
                 self.context.responsible_client),),
            transition=u'forwarding-transition-refuse')

        notify(ObjectModifiedEvent(self.context))

        return self.request.RESPONSE.redirect('.')
    def _extend_task_query(self, query):
        """Extends a globalindex task query.
        """

        # sort by deadline
        query = query.order_by(asc(Task.deadline))

        # list only open tasks
        query = query.filter(Task.review_state.in_(OPEN_TASK_STATES))

        # If a task has a successor task, list only one of them.
        # List only the one which is assigned to this client.
        query = query.filter(
            or_(
                and_(Task.predecessor == None, Task.successors == None),
                Task.admin_unit_id == get_current_org_unit().id()))

        return query
Example #47
0
    def test_delegate_to_inbox(self, browser):
        self.login(self.secretariat_user, browser)

        browser.open(self.task,
                     view='@@task_transition_controller',
                     data={'transition': 'task-transition-delegate'})

        form = browser.find_form_by_field('Responsibles')
        form.find_widget('Responsibles').fill(
            ['inbox:{}'.format(get_current_org_unit().id())])
        browser.css('#form-buttons-save').first.click()  # can't use submit()

        form = browser.find_form_by_field('Issuer')
        form.find_widget('Issuer').fill(self.dossier_responsible.getId())

        browser.css('#form-buttons-save').first.click()  # can't use submit()

        self.assertEqual(['1 subtasks were create.'],
                         statusmessages.info_messages())
    def setUp(self):
        super(TestTaskSQLSyncer, self).setUp()

        self.dossier = create(Builder('dossier')
                              .titled(u'dossier'))
        self.subdossier = create(Builder('dossier')
                                 .titled(u'subdossier')
                                 .within(self.dossier))
        self.task = create(
            Builder('task')
            .having(title=u'Mach mau!',
                    issuer=self.user.userid,
                    task_type='direct-execution',
                    responsible_client=get_current_org_unit().id(),
                    responsible=self.user.userid,
                    deadline=date(2010, 1, 1),
                    text='Lorem ipsum dolor sit amet, consectetur')
            .within(self.subdossier)
        )
Example #49
0
    def __call__(self):
        # set responsible
        org_unit = get_current_org_unit()
        self.context.responsible_client = org_unit.id()
        self.context.responsible = org_unit.inbox().id()

        # create a response in the task
        add_simple_response(self.context,
                            field_changes=(
                                (ITask['responsible'],
                                 self.context.responsible),
                                (ITask['responsible_client'],
                                 self.context.responsible_client),
                            ),
                            transition=u'forwarding-transition-refuse')

        notify(ObjectModifiedEvent(self.context))

        return self.request.RESPONSE.redirect('.')
Example #50
0
    def test_delegate_to_inbox(self, browser):
        self.login(self.secretariat_user, browser)

        browser.open(self.task,
                     view='@@task_transition_controller',
                     data={'transition': 'task-transition-delegate'})

        form = browser.find_form_by_field('Responsibles')
        form.find_widget('Responsibles').fill(
            ['inbox:{}'.format(get_current_org_unit().id())])
        browser.css('#form-buttons-save').first.click()  # can't use submit()

        form = browser.find_form_by_field('Issuer')
        form.find_widget('Issuer').fill(self.dossier_responsible.getId())

        browser.css('#form-buttons-save').first.click()  # can't use submit()

        self.assertEqual(['1 subtasks were create.'],
                         statusmessages.info_messages())
Example #51
0
    def key_value_provider(self):
        # Reset hidden_terms every time cache key changed
        self.hidden_terms = []
        selected_unit = ogds_service().fetch_org_unit(self.get_client())
        if selected_unit:
            # check if it the current client is selected then add all users
            if selected_unit.id() == get_current_org_unit().id():
                for user in selected_unit.assigned_users():
                    if not user.active:
                        self.hidden_terms.append(user.userid)
                    yield (user.userid, user.label())

            # add all inactive users to the hidden terms
            for user in ogds_service().inactive_users():
                if user.userid not in self.hidden_terms:
                    self.hidden_terms.append(user.userid)

            # client inbox
            inbox_actor = Actor.inbox(selected_unit.inbox().id(),
                                      org_unit=selected_unit)
            yield (selected_unit.inbox().id(), inbox_actor.get_label())
    def test_search_for_users(self, browser):
        self.login(self.workspace_admin, browser=browser)

        for number in range(20):
            create(
                Builder('ogds_user').assign_to_org_units([
                    get_current_org_unit()
                ]).having(firstname='Hans-{}'.format(str(number)),
                          lastname='Muster').id('hans.muster{}'.format(
                              str(number))))

        browser.open(self.workspace.absolute_url() +
                     '/manage-participants/search',
                     data={'q': 'beatrice'})

        self.assertEquals(
            {
                u'total_count':
                1,
                u'pagination': {
                    u'more': False
                },
                u'page':
                1,
                u'results': [{
                    u'text':
                    u'Schr\xf6dinger B\xe9atrice (beatrice.schrodinger)',
                    u'_resultId': u'beatrice.schrodinger',
                    u'id': u'beatrice.schrodinger'
                }]
            }, browser.json)

        browser.open(self.workspace.absolute_url() +
                     '/manage-participants/search',
                     data={'q': 'hans'})

        self.assertEquals(21, browser.json['total_count'])
        self.assertEquals({u'more': True}, browser.json['pagination'])
        self.assertEquals(1, browser.json['page'])
        self.assertEquals(20, len(browser.json['results']))
def is_open_task_report_allowed():
    inbox = get_current_org_unit().inbox()
    return ogds_service().fetch_current_user() in inbox.assigned_users()