def test_participations_are_copied_when_dossier_is_copied(self):
        dossier = create(Builder('dossier'))
        peter = create(
            Builder('person').having(firstname=u'peter', lastname=u'hans'))
        organization = create(Builder('organization').named('ACME'))
        org_role = create(
            Builder('org_role').having(person=peter,
                                       organization=organization,
                                       function=u'cheffe'))
        ogds_user = create(
            Builder('ogds_user').id('peter').having(
                firstname=u'Hans', lastname=u'Peter').as_contact_adapter())
        create(
            Builder('ogds_user_participation').for_dossier(
                dossier).for_ogds_user(ogds_user))
        create(
            Builder('contact_participation').having(
                contact=peter, dossier_oguid=Oguid.for_object(dossier)))
        create(
            Builder('contact_participation').having(
                contact=organization, dossier_oguid=Oguid.for_object(dossier)))
        create(
            Builder('org_role_participation').having(
                org_role=org_role, dossier_oguid=Oguid.for_object(dossier)))

        original_participations = Participation.query.by_dossier(dossier).all()

        copied_dossier = api.content.copy(source=dossier, target=self.portal)
        copied_participations = Participation.query.by_dossier(
            copied_dossier).all()
        self.assertEqual(4, len(copied_participations))
        intersecting_elements = set(original_participations).intersection(
            set(copied_participations))
        self.assertEqual(0, len(intersecting_elements))
    def test_closing_does_not_revoke_roles_on_task_if_revoke_permission_is_false(self, browser):
        self.login(self.dossier_responsible, browser=browser)
        self.set_workflow_state('task-state-tested-and-closed', self.subtask)
        self.set_workflow_state('task-state-resolved', self.task)
        self.task.revoke_permissions = False

        storage = RoleAssignmentManager(self.task).storage
        self.assertEqual(
            [{'cause': ASSIGNMENT_VIA_TASK,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task),
              'principal': 'kathi.barfuss'},
             {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task),
              'principal': 'fa_inbox_users'}], storage._storage())

        # close
        browser.open(self.task, view='tabbedview_view-overview')
        browser.click_on('task-transition-resolved-tested-and-closed')
        browser.fill({'Response': 'Done!'})
        browser.click_on('Save')

        self.assertEqual(
            [{'cause': ASSIGNMENT_VIA_TASK,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task),
              'principal': 'kathi.barfuss'},
             {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task),
              'principal': 'fa_inbox_users'}], storage._storage())
    def test_closing_does_not_revoke_roles_on_proposal_if_revoke_permission_is_false(self, browser):
        self.login(self.dossier_responsible, browser=browser)
        self.task.revoke_permissions = False

        intids = getUtility(IIntIds)
        relation = RelationValue(intids.getId(self.proposaldocument))
        ITask(self.task).relatedItems.append(relation)
        notify(ObjectModifiedEvent(self.task))

        expected_assignments = [{'cause': ASSIGNMENT_VIA_TASK,
                                 'roles': ['Reader', 'Editor'],
                                 'reference': Oguid.for_object(self.task),
                                 'principal': self.regular_user.id},
                                {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
                                 'roles': ['Reader', 'Editor'],
                                 'reference': Oguid.for_object(self.task),
                                 'principal': u'fa_inbox_users'}]

        document_storage = RoleAssignmentManager(self.proposaldocument).storage
        self.assertEqual(expected_assignments, document_storage._storage())

        proposal_storage = RoleAssignmentManager(self.proposal).storage
        self.assertEqual(expected_assignments, proposal_storage._storage())

        self.set_workflow_state('task-state-tested-and-closed', self.subtask)
        self.set_workflow_state('task-state-resolved', self.task)
        notify(ObjectModifiedEvent(self.task))

        browser.open(self.task, view='tabbedview_view-overview')
        browser.click_on('task-transition-resolved-tested-and-closed')
        browser.click_on('Save')

        self.assertEqual(expected_assignments, proposal_storage._storage())
        self.assertEqual(expected_assignments, document_storage._storage())
 def test_closing_a_task_revokes_responsible_roles_on_related_documents(self, browser):
     self.login(self.dossier_responsible, browser=browser)
     self.set_workflow_state('task-state-tested-and-closed', self.subtask)
     self.set_workflow_state('task-state-resolved', self.task)
     storage = RoleAssignmentManager(self.document).storage
     expected_oguids = [
         Oguid.for_object(task).id
         for task in (
             self.task, self.task, self.subtask, self.subtask,
             self.info_task, self.info_task, self.private_task,
             self.inbox_task)
     ]
     self.assertEqual(
         expected_oguids,
         [item.get('reference') for item in storage._storage()],
     )
     # close
     browser.open(self.task, view='tabbedview_view-overview')
     browser.click_on('task-transition-resolved-tested-and-closed')
     browser.fill({'Response': 'Done!'})
     browser.click_on('Save')
     expected_oguids = [
         Oguid.for_object(task).id
         for task in (self.subtask, self.subtask, self.info_task,
                      self.info_task, self.private_task, self.inbox_task)
     ]
     self.assertEqual(
         expected_oguids,
         [item.get('reference') for item in storage._storage()],
     )
Example #5
0
    def test_skip_task_does_not_revoke_roles_if_revoke_permission_is_false(
            self, browser):
        self.login(self.secretariat_user, browser=browser)
        self.seq_subtask_2.revoke_permissions = False

        storage = RoleAssignmentManager(self.seq_subtask_2).storage
        self.assertEqual([{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.seq_subtask_2),
            'principal': 'kathi.barfuss'
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.seq_subtask_2),
            'principal': 'fa_inbox_users'
        }], storage._storage())

        # skip
        browser.open(self.seq_subtask_2, view='tabbedview_view-overview')
        browser.click_on('task-transition-planned-skipped')
        browser.click_on('Save')

        self.assertEqual([{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.seq_subtask_2),
            'principal': 'kathi.barfuss'
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.seq_subtask_2),
            'principal': 'fa_inbox_users'
        }], storage._storage())
Example #6
0
 def test_closing_a_task_revokes_responsible_roles_on_related_documents(
         self, browser):
     self.login(self.dossier_responsible, browser=browser)
     self.set_workflow_state('task-state-tested-and-closed', self.subtask)
     self.set_workflow_state('task-state-resolved', self.task)
     storage = RoleAssignmentManager(self.document).storage
     expected_oguids = [
         Oguid.for_object(task).id
         for task in (self.task, self.task, self.subtask, self.subtask,
                      self.info_task, self.info_task, self.private_task,
                      self.inbox_task)
     ]
     self.assertEqual(
         expected_oguids,
         [item.get('reference') for item in storage._storage()],
     )
     # close
     browser.open(self.task, view='tabbedview_view-overview')
     browser.click_on('task-transition-resolved-tested-and-closed')
     browser.fill({'Response': 'Done!'})
     browser.click_on('Save')
     expected_oguids = [
         Oguid.for_object(task).id
         for task in (self.subtask, self.subtask, self.info_task,
                      self.info_task, self.private_task, self.inbox_task)
     ]
     self.assertEqual(
         expected_oguids,
         [item.get('reference') for item in storage._storage()],
     )
Example #7
0
    def test_closing_direct_execution_task_does_not_revoke_roles_if_revoke_permission_is_false(
            self, browser):
        self.login(self.regular_user, browser=browser)
        self.subtask.revoke_permissions = False
        self.subtask.task_type = 'direct-execution'
        self.subtask.sync()
        self.set_workflow_state('task-state-in-progress', self.subtask)

        # close
        browser.open(self.subtask, view='tabbedview_view-overview')
        browser.click_on('task-transition-in-progress-tested-and-closed')
        browser.click_on('Save')

        storage = RoleAssignmentManager(self.subtask).storage
        self.assertEqual([{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.subtask),
            'principal': self.regular_user.id
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.subtask),
            'principal': 'fa_inbox_users'
        }], storage._storage())
    def test_redirects_to_portal_when_current_user_has_no_longer_view_permission(
            self, browser):
        self.login(self.regular_user, browser=browser)

        api.content.disable_roles_acquisition(obj=self.dossier)
        self.assign_task(self.secretariat_user, u'Thats a job for you.')

        manager = RoleAssignmentManager(self.task)
        self.assertEqual([{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.task).id,
            'principal': 'jurgen.konig'
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.task).id,
            'principal': u'fa_inbox_users'
        }], manager.storage._storage())

        self.assertEqual(self.portal.absolute_url(), browser.url)
        self.assertEqual([
            'Task successfully reassigned. You are no longer permitted to '
            'access the task.'
        ], info_messages())
Example #9
0
    def test_closing_a_task_revokes_responsible_roles_on_task(self, browser):
        self.login(self.dossier_responsible, browser=browser)
        self.set_workflow_state('task-state-tested-and-closed', self.subtask)
        self.set_workflow_state('task-state-resolved', self.task)

        storage = RoleAssignmentManager(self.task).storage
        self.assertEqual([{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.task),
            'principal': 'kathi.barfuss'
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Editor'],
            'reference': Oguid.for_object(self.task),
            'principal': 'fa_inbox_users'
        }], storage._storage())

        # close
        browser.open(self.task, view='tabbedview_view-overview')
        browser.click_on('task-transition-resolved-tested-and-closed')
        browser.fill({'Response': 'Done!'})
        browser.click_on('Save')

        self.assertEqual([], storage._storage())
    def test_skip_task_does_not_revoke_roles_if_revoke_permission_is_false(self, browser):
        self.login(self.secretariat_user, browser=browser)
        self.seq_subtask_2.revoke_permissions = False

        storage = RoleAssignmentManager(self.seq_subtask_2).storage
        self.assertEqual(
            [{'cause': ASSIGNMENT_VIA_TASK,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.seq_subtask_2),
              'principal': 'kathi.barfuss'},
             {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.seq_subtask_2),
              'principal': 'fa_inbox_users'}], storage._storage())

        # skip
        browser.open(self.seq_subtask_2, view='tabbedview_view-overview')
        browser.click_on('task-transition-planned-skipped')
        browser.click_on('Save')

        self.assertEqual(
            [{'cause': ASSIGNMENT_VIA_TASK,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.seq_subtask_2),
              'principal': 'kathi.barfuss'},
             {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.seq_subtask_2),
              'principal': 'fa_inbox_users'}], storage._storage())
Example #11
0
    def test_revokes_permissions_on_proposal(self):
        self.login(self.dossier_responsible)

        intids = getUtility(IIntIds)
        relation = RelationValue(intids.getId(self.proposaldocument))
        ITask(self.subtask).relatedItems.append(relation)
        notify(ObjectModifiedEvent(self.subtask))

        self.set_workflow_state('task-state-tested-and-closed', self.subtask)

        expected_assignments = [{
            'cause': ASSIGNMENT_VIA_TASK,
            'roles': ['Reader', 'Editor'],
            'reference': Oguid.for_object(self.subtask),
            'principal': self.regular_user.id
        }, {
            'cause': ASSIGNMENT_VIA_TASK_AGENCY,
            'roles': ['Reader', 'Editor'],
            'reference': Oguid.for_object(self.subtask),
            'principal': u'fa_inbox_users'
        }]

        document_storage = RoleAssignmentManager(self.proposaldocument).storage
        self.assertEqual(expected_assignments, document_storage._storage())

        proposal_storage = RoleAssignmentManager(self.proposal).storage
        self.assertEqual(expected_assignments, proposal_storage._storage())

        RevokePermissions(self.subtask, self.request)()
        self.assertEqual([], proposal_storage._storage())
        self.assertEqual([], document_storage._storage())
    def test_record_activity_when_open_next_task(self):
        self.login(self.regular_user)

        # create subtask
        subtask2 = create(Builder('task')
                          .within(self.task)
                          .having(responsible_client='fa',
                                  responsible=self.regular_user.getId(),
                                  issuer=self.dossier_responsible.getId(),
                                  task_type='correction',
                                  deadline=date(2016, 11, 1))
                          .in_state('task-state-planned'))

        self.set_workflow_state('task-state-in-progress', self.subtask)
        alsoProvides(self.subtask, IFromSequentialTasktemplate)
        alsoProvides(subtask2, IFromSequentialTasktemplate)
        self.task.set_tasktemplate_order([self.subtask, subtask2])

        api.content.transition(
            obj=self.subtask, transition='task-transition-in-progress-resolved')

        self.assertEquals(
            'task-state-resolved', api.content.get_state(self.subtask))
        self.assertEquals(
            'task-state-open', api.content.get_state(subtask2))

        activities = Resource.query.get_by_oguid(
            Oguid.for_object(subtask2)).activities
        activity = activities[-1]
        self.assertEquals('task-added', activity.kind)
        self.assertEquals('Task opened', activity.label)
        self.assertEquals(u'New task opened by B\xe4rfuss K\xe4thi',
                          activity.summary)
        self.assertEquals(Oguid.for_object(subtask2), activity.resource.oguid)
Example #13
0
    def test_record_activity_when_open_next_task(self):
        self.login(self.regular_user)

        # create subtask
        subtask2 = create(
            Builder('task').within(self.task).having(
                responsible_client='fa',
                responsible=self.regular_user.getId(),
                issuer=self.dossier_responsible.getId(),
                task_type='correction',
                deadline=date(2016, 11, 1)).in_state('task-state-planned'))

        self.set_workflow_state('task-state-in-progress', self.subtask)
        alsoProvides(self.subtask, IFromSequentialTasktemplate)
        alsoProvides(subtask2, IFromSequentialTasktemplate)
        self.task.set_tasktemplate_order([self.subtask, subtask2])

        api.content.transition(
            obj=self.subtask,
            transition='task-transition-in-progress-resolved')

        self.assertEquals('task-state-resolved',
                          api.content.get_state(self.subtask))
        self.assertEquals('task-state-open', api.content.get_state(subtask2))

        activities = Resource.query.get_by_oguid(
            Oguid.for_object(subtask2)).activities
        activity = activities[-1]
        self.assertEquals('task-added', activity.kind)
        self.assertEquals('Task opened', activity.label)
        self.assertEquals(u'New task opened by B\xe4rfuss K\xe4thi',
                          activity.summary)
        self.assertEquals(Oguid.for_object(subtask2), activity.resource.oguid)
    def test_participations_are_copied_when_dossier_is_copied(self):
        dossier = create(Builder('dossier'))
        peter = create(Builder('person').having(
            firstname=u'peter', lastname=u'hans'))
        organization = create(Builder('organization').named('ACME'))
        org_role = create(Builder('org_role').having(
            person=peter, organization=organization, function=u'cheffe'))
        ogds_user = create(Builder('ogds_user')
                           .id('peter')
                           .having(firstname=u'Hans', lastname=u'Peter')
                           .as_contact_adapter())
        create(Builder('ogds_user_participation')
               .for_dossier(dossier)
               .for_ogds_user(ogds_user))
        create(Builder('contact_participation')
               .having(contact=peter, dossier_oguid=Oguid.for_object(dossier)))
        create(Builder('contact_participation')
               .having(contact=organization,
                       dossier_oguid=Oguid.for_object(dossier)))
        create(Builder('org_role_participation')
               .having(org_role=org_role,
                       dossier_oguid=Oguid.for_object(dossier)))

        original_participations = Participation.query.by_dossier(dossier).all()

        copied_dossier = api.content.copy(source=dossier, target=self.portal)
        copied_participations = Participation.query.by_dossier(copied_dossier).all()
        self.assertEqual(4, len(copied_participations))
        intersecting_elements = set(original_participations).intersection(
                                                    set(copied_participations))
        self.assertEqual(0, len(intersecting_elements))
Example #15
0
    def test_oguid_register_registers_intid(self):
        self.login(self.regular_user)

        copied_dossier = self.dossier._getCopy(self.leaf_repofolder)
        self.assertIsNone(Oguid.for_object(copied_dossier))

        oguid = Oguid.for_object(copied_dossier, register=True)
        self.assertIsNotNone(oguid)
        self.assertEqual(oguid, Oguid.for_object(copied_dossier))
Example #16
0
    def test_oguid_register_registers_intid(self):
        repo = create(Builder('repository'))
        dossier = create(Builder('dossier').within(repo))

        copied_dossier = dossier._getCopy(repo)
        self.assertIsNone(Oguid.for_object(copied_dossier))

        oguid = Oguid.for_object(copied_dossier, register=True)
        self.assertIsNotNone(oguid)
        self.assertEqual(oguid, Oguid.for_object(copied_dossier))
    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
    def test_active_committeee_vocabulary_list_only_active_committees(self):
        self.login(self.committee_responsible)
        factory = getUtility(
            IVocabularyFactory,
            name='opengever.meeting.ActiveCommitteeVocabulary')
        self.assertItemsEqual([
            Oguid.for_object(self.empty_committee).id,
            Oguid.for_object(self.committee).id
        ], [term.value for term in factory(context=None)])

        self.empty_committee.load_model().deactivate()
        self.assertItemsEqual([Oguid.for_object(self.committee).id],
                              [term.value for term in factory(context=None)])
    def assert_submitted_document_created(self, proposal, document,
                                       submitted_version=0):
        portal = api.portal.get()
        submitted_document_model = SubmittedDocument.query.get_by_source(
            proposal,
            document,
            )

        submitted_document = portal.restrictedTraverse(
            submitted_document_model.submitted_physical_path.encode('utf-8'),
            )

        self.assertIsNotNone(submitted_document_model)

        self.assertEqual(
            Oguid.for_object(submitted_document),
            submitted_document_model.submitted_oguid,
            )

        self.assertEqual(
            submitted_version,
            submitted_document_model.submitted_version,
            )

        self.assertEqual(
            proposal.load_model(),
            submitted_document_model.proposal,
            )
    def clear(self, cause, principal, reference, reindex=True):
        item = self.storage.get(principal, cause, Oguid.for_object(reference).id)
        if not item:
            return

        self.storage.clear(item)
        self._update_local_roles(reindex=reindex)
    def test_preserves_local_roles_from_invitation(self, browser):
        assignment_type = ASSIGNMENT_VIA_INVITATION
        assignment_class = RoleAssignment.registry[assignment_type]

        self.login(self.administrator, browser=browser)

        manager = RoleAssignmentManager(self.subdossier)
        manager.add_or_update_assignment(
            assignment_class(self.regular_user.id,
                             ['Reader', 'Editor', 'Contributor'],
                             self.workspace))
        manager = RoleAssignmentManager(self.subdossier)
        assignments = manager.get_assignments_by_cause(assignment_type)
        self.assertEqual(1, len(assignments))

        browser.open(self.dossier,
                     data=self.make_path_param(self.subdossier), view="copy_items")

        with self.observe_children(self. empty_repofolder) as children:
            browser.open(self.empty_repofolder)
            browser.click_on('Paste')

        self.assertEqual(1, len(children.get('added')))
        subdossier_copy = children.get('added').pop()
        manager = RoleAssignmentManager(subdossier_copy)
        assignments = manager.get_assignments_by_cause(assignment_type)

        self.assertEqual(1, len(assignments), "{} should get copied".format(assignment_class))
        assignment = assignments[0]
        expected_assignment = {'cause': assignment_type,
                               'roles': ['Reader', 'Editor', 'Contributor'],
                               'reference': Oguid.for_object(self.workspace).id,
                               'principal': self.regular_user.id}
        self.assertEqual(expected_assignment, assignment)
    def test_check_permissions_fails_with_nobody(self, browser):
        self.login(self.regular_user)
        url = ResolveOGUIDView.url_for(
            Oguid.for_object(self.task), get_current_admin_unit())

        with browser.expect_unauthorized():
            browser.open(url)
    def test_preserves_local_roles_from_invitation(self, browser):
        assignment_type = ASSIGNMENT_VIA_INVITATION
        assignment_class = RoleAssignment.registry[assignment_type]

        self.login(self.administrator, browser=browser)

        manager = RoleAssignmentManager(self.subdossier)
        manager.add_or_update_assignment(
            assignment_class(self.regular_user.id,
                             ['Reader', 'Editor', 'Contributor'],
                             self.workspace))
        manager = RoleAssignmentManager(self.subdossier)
        assignments = manager.get_assignments_by_cause(assignment_type)
        self.assertEqual(1, len(assignments))

        browser.open(self.dossier,
                     data=self.make_path_param(self.subdossier), view="copy_items")

        with self.observe_children(self. empty_repofolder) as children:
            browser.open(self.empty_repofolder)
            browser.click_on('Paste')

        self.assertEqual(1, len(children.get('added')))
        subdossier_copy = children.get('added').pop()
        manager = RoleAssignmentManager(subdossier_copy)
        assignments = manager.get_assignments_by_cause(assignment_type)

        self.assertEqual(1, len(assignments), "{} should get copied".format(assignment_class))
        assignment = assignments[0]
        expected_assignment = {'cause': assignment_type,
                               'roles': ['Reader', 'Editor', 'Contributor'],
                               'reference': Oguid.for_object(self.workspace).id,
                               'principal': self.regular_user.id}
        self.assertEqual(expected_assignment, assignment)
Example #24
0
def journal_entry_factory(context, action, title,
                          visible=True, comment='', actor=None,
                          documents=None):
    if actor is None:
        actor = api.user.get_current().getId()

    comment = comment == '' and get_change_note(getRequest(), '') or comment
    title = propper_string(title)
    action = propper_string(action)
    comment = propper_string(comment)

    action_entry = PersistentDict({'type': action,
                                   'title': title,
                                   'visible': visible})
    if documents:
        action_documents = PersistentList()
        for doc in documents:
            action_documents.append(PersistentDict(
                {'id': Oguid.for_object(doc).id, 'title': doc.title}))
        action_entry['documents'] = action_documents

    entry = {
        'obj': context,
        'action': action_entry,
        'actor': actor,
        'comment': comment}

    notify(JournalEntryEvent(**entry))
Example #25
0
    def test_proposal_can_be_added(self):
        proposal = create(Builder('proposal').within(self.dossier))
        self.assertEqual('proposal-1', proposal.getId())

        model = proposal.load_model()
        self.assertIsNotNone(model)
        self.assertEqual(Oguid.for_object(proposal), model.oguid)
Example #26
0
    def create_database_entry(self, meeting, document):
        excerpt = GeneratedExcerpt(
            oguid=Oguid.for_object(document),
            generated_version=document.get_current_version())

        meeting.excerpt_documents.append(excerpt)
        return excerpt
Example #27
0
    def create_database_entry(self, meeting, document):
        version = document.get_current_version_id(missing_as_zero=True)
        excerpt = GeneratedExcerpt(
            oguid=Oguid.for_object(document), generated_version=version)

        meeting.excerpt_documents.append(excerpt)
        return excerpt
Example #28
0
    def test_committee_can_be_added(self):
        committee = create(Builder('committee').within(self.container))
        self.assertEqual('committee-1', committee.getId())

        model = committee.load_model()
        self.assertIsNotNone(model)
        self.assertEqual(Oguid.for_object(committee), model.oguid)
    def test_proposal_can_be_added(self):
        proposal = create(Builder('proposal').within(self.dossier))
        self.assertEqual('proposal-1', proposal.getId())

        model = proposal.load_model()
        self.assertIsNotNone(model)
        self.assertEqual(Oguid.for_object(proposal), model.oguid)
Example #30
0
    def set_new_proposal_workflow_state(self, proposal):
        oguid = Oguid.for_object(proposal)

        row = self.execute(proposals_table.select().where(
            proposals_table.c.admin_unit_id == oguid.admin_unit_id).where(
                proposals_table.c.int_id == oguid.int_id)).fetchone()
        model_state = row.workflow_state

        state_before = self.wf_tool.getStatusOf(wf_id, proposal)
        new_state = sql_to_plone_state_mapping[model_state]

        if new_state == state_before:
            return

        # The status is changed the same way as by WorkflowChainUpdater.
        self.wf_tool.setStatusOf(
            wf_id, proposal, {
                'review_state': new_state,
                'action': 'systemupdate',
                'actor': 'system',
                'comments': '',
                'time': DateTime()
            })
        proposal.reindexObject(idxs=['review_state'])

        # If we switch away from or to `proposal-state-active` we must
        # reindex security.
        if (state_before == 'proposal-state-active'
                or new_state == 'proposal-state-active'):
            update_security_for(proposal, reindex_security=True)
Example #31
0
    def test_proposal_can_be_edited_in_browser(self, browser):
        self.login(self.dossier_responsible, browser)
        browser.visit(self.draft_proposal)
        editbar.contentview('Edit').click()
        self.assertEqual(u'Antrag f\xfcr Kreiselbau',
                         browser.find('Title').value)

        browser.fill({
            'Title': u'Another pr\xf6posal',
            'Attachments': [self.document]
        }).save()
        statusmessages.assert_no_error_messages()
        statusmessages.assert_message('Changes saved')

        proposal = browser.context
        browser.open(proposal, view='tabbedview_view-overview')
        self.assertEquals(
            [['Title', u'Another pr\xf6posal'],
             ['Committee', u'Kommission f\xfcr Verkehr'], ['Meeting', ''],
             ['Proposal document', u'Antrag f\xfcr Kreiselbau'],
             ['State', 'Pending'], ['Decision number', ''],
             ['Attachments', u'Vertr\xe4gsentwurf']],
            browser.css('table.listing').first.lists())

        self.assertEqual(1, len(proposal.relatedItems))
        self.assertEqual(self.document, proposal.relatedItems[0].to_object)
        self.assertEqual(u'Another pr\xf6posal', proposal.title)

        model = proposal.load_model()
        self.assertIsNotNone(model)
        self.assertEqual(Oguid.for_object(proposal), model.oguid)
        self.assertEqual(u'Another pr\xf6posal', proposal.title)
    def test_assign_to_dossier_stores_and_close_forwarding(self, browser):
        self.login(self.secretariat_user, browser=browser)

        url = '{}/@workflow/forwarding-transition-assign-to-dossier'.format(
            self.inbox_forwarding.absolute_url())

        dossier_uid = obj2brain(self.empty_dossier).UID
        data = {'dossier': dossier_uid}
        browser.open(url,
                     method='POST',
                     data=json.dumps(data),
                     headers=self.api_headers)

        self.assertEqual(200, browser.status_code)

        yearfolder = get_current_yearfolder(context=self.inbox)
        self.assertEqual(1, len(yearfolder.objectValues()))

        forwarding = yearfolder.objectValues()[0]
        self.assertEqual('forwarding-state-closed',
                         api.content.get_state(forwarding))

        response = IResponseContainer(forwarding).list()[-1]
        task = self.empty_dossier.objectValues()[-1]
        self.assertEqual('forwarding-transition-assign-to-dossier',
                         response.transition)
        self.assertEqual(Oguid.for_object(task).id, response.successor_oguid)
Example #33
0
    def test_proposal_can_be_created_in_browser_and_strips_whitespace(
            self, browser):
        self.login(self.dossier_responsible, browser)
        browser.open(self.dossier)
        factoriesmenu.add('Proposal')
        browser.fill({
            'Title': u'A pr\xf6posal',
            'Committee': u'Rechnungspr\xfcfungskommission',
            'Proposal template': u'Geb\xfchren',
            'Attachments': [self.document],
        }).save()
        statusmessages.assert_no_error_messages()
        statusmessages.assert_message('Item created')

        proposal = browser.context
        self.assertEqual(1, len(proposal.relatedItems))
        self.assertEqual(self.document, proposal.relatedItems[0].to_object)
        self.assertEqual(u'A pr\xf6posal', proposal.title)

        model = proposal.load_model()
        self.assertIsNotNone(model)
        self.assertEqual(u'A pr\xf6posal', model.title)
        self.assertIsNone(model.submitted_title)
        self.assertEqual(Oguid.for_object(proposal), model.oguid)
        self.assertEqual('robert.ziegler', model.creator)
        self.assertEqual(u'Vertr\xe4ge und Vereinbarungen',
                         model.repository_folder_title)
        self.assertEqual(u'en', model.language)

        self.assertTrue(
            set(['a', 'proposal'
                 ]).issubset(set(index_data_for(proposal)['SearchableText'])))
        self.assertEqual(u'Client1 1.1 / 1', model.dossier_reference_number)
Example #34
0
    def test_proposal_creation_from_docx_template(self, browser):
        self.login(self.meeting_user, browser)

        committee_oguid = Oguid.for_object(self.committee).id
        payload = {
            u'@type': u'opengever.meeting.proposal',
            u'title': u'Sanierung B\xe4rengraben 2016',
            u'proposal_document_type': 'existing',
            u'proposal_document': IUUID(self.document),
            u"committee_oguid": committee_oguid,
            u'issuer': self.meeting_user.getId(),
        }

        response = browser.open(self.dossier.absolute_url(),
                                data=json.dumps(payload),
                                method='POST',
                                headers=self.api_headers)

        self.assertEqual(201, response.status_code)

        new_object_id = str(response.json['id'])
        proposal = self.dossier.restrictedTraverse(new_object_id)
        self.assertEqual(u'Sanierung B\xe4rengraben 2016', proposal.title)
        self.assertEqual(self.meeting_user.getId(), proposal.issuer)

        proposal_doc = proposal.get_proposal_document()
        self.assertIsNotNone(proposal_doc)
        self.assertEqual(u'Sanierung B\xe4rengraben 2016', proposal_doc.title)
        self.assertEqual(u'Sanierung Baerengraben 2016.docx',
                         proposal_doc.get_filename())

        checksum = IBumblebeeDocument(proposal_doc).get_checksum()
        self.assertIsNotNone(checksum)
        self.assertEqual(
            IBumblebeeDocument(self.document).get_checksum(), checksum)
Example #35
0
    def test_check_permissions_fails_with_nobody(self, browser):
        self.login(self.regular_user)
        url = ResolveOGUIDView.url_for(Oguid.for_object(self.task),
                                       get_current_admin_unit())

        with browser.expect_unauthorized():
            browser.open(url)
Example #36
0
    def create_database_entry(self, meeting, document):
        excerpt = GeneratedExcerpt(
            oguid=Oguid.for_object(document),
            generated_version=document.get_current_version())

        meeting.excerpt_documents.append(excerpt)
        return excerpt
Example #37
0
    def by_source(self, document):
        """Return all submitted documents where document is on the source
        side.
        """

        oguid = Oguid.for_object(document)
        return self.filter(SubmittedDocument.oguid == oguid)
Example #38
0
    def test_oguid_for_object(self):
        self.login(self.regular_user)

        intids = getUtility(IIntIds)

        self.assertEqual('plone:{}'.format(intids.getId(self.dossier)),
                         Oguid.for_object(self.dossier))
Example #39
0
    def _get_oguid_for(self, item):
        """Helper which returns a oguid for a given item. If the item is
        already an oguid, this oguid is returned."""

        if not isinstance(item, Oguid):
            return Oguid.for_object(item)
        return item
    def test_assign_to_dossier_stores_and_close_forwarding(self, browser):
        self.login(self.secretariat_user, browser=browser)

        url = '{}/@workflow/forwarding-transition-assign-to-dossier'.format(
            self.inbox_forwarding.absolute_url())

        dossier_uid = obj2brain(self.empty_dossier).UID
        data = {'dossier': dossier_uid}
        browser.open(url, method='POST',
                     data=json.dumps(data), headers=self.api_headers)

        self.assertEqual(200, browser.status_code)

        yearfolder = get_current_yearfolder(context=self.inbox)
        self.assertEqual(1, len(yearfolder.objectValues()))

        forwarding = yearfolder.objectValues()[0]
        self.assertEqual(
            'forwarding-state-closed', api.content.get_state(forwarding))

        response = IResponseContainer(forwarding)[-1]
        task = self.empty_dossier.objectValues()[-1]
        self.assertEqual(
            'forwarding-transition-assign-to-dossier', response.transition)
        self.assertEqual(Oguid.for_object(task).id, response.successor_oguid)
Example #41
0
    def setUp(self):
        super(TestMarkAsRead, self).setUp()
        with self.login(self.regular_user):
            self.center = NotificationCenter()
            self.watcher = create(
                Builder('watcher').having(actorid=self.regular_user.id))
            oguid = Oguid.for_object(self.task)
            self.resource = create(
                Builder('resource').oguid(oguid.id).watchers([self.watcher]))

            # XXX - something is wonky with the builder for activities
            with freeze(FREEZE_TIME_FIRST):
                self.activity_1 = create(
                    Builder('activity').having(resource=self.resource,
                                               created=FREEZE_TIME_FIRST))
                create(
                    Builder('notification').id(1).having(
                        activity=self.activity_1,
                        userid=self.regular_user.id,
                    ))

            # XXX - something is wonky with the builder for activities
            with freeze(FREEZE_TIME_SECOND):
                self.activity_2 = create(
                    Builder('activity').having(resource=self.resource,
                                               created=FREEZE_TIME_SECOND))
                create(
                    Builder('notification').id(2).having(
                        activity=self.activity_2,
                        userid=self.regular_user.id,
                    ))

            self.notifications = self.center.get_users_notifications(
                self.regular_user.id)
Example #42
0
    def by_source(self, document):
        """Return all submitted documents where document is on the source
        side.
        """

        oguid = Oguid.for_object(document)
        return self.filter(SubmittedDocument.oguid == oguid)
Example #43
0
    def generate_excerpt(self, title):
        """Generate an excerpt from the agenda items document.

        Can either be an excerpt from the proposals document or an excerpt
        from the ad-hoc agenda items document.
        In both cases the excerpt is stored in the meeting dossier.
        """
        assert self.can_generate_excerpt()
        meeting_dossier = self.meeting.get_dossier()
        source_document = self.resolve_document()

        if not source_document:
            raise ValueError('The agenda item has no document.')

        if not api.user.get_current().checkPermission(
                'opengever.document: Add document', meeting_dossier):
            raise MissingMeetingDossierPermissions

        excerpt_document = CreateDocumentCommand(
            context=meeting_dossier,
            filename=source_document.file.filename,
            data=source_document.file.data,
            content_type=source_document.file.contentType,
            title=title).execute()

        if self.has_proposal:
            submitted_proposal = self.proposal.resolve_submitted_proposal()
            submitted_proposal.append_excerpt(excerpt_document)
        else:
            self.excerpts.append(Excerpt(
                excerpt_oguid=Oguid.for_object(excerpt_document)))

        return excerpt_document
Example #44
0
    def _get_oguid_for(self, item):
        """Helper which returns a oguid for a given item. If the item is
        already an oguid, this oguid is returned."""

        if not isinstance(item, Oguid):
            return Oguid.for_object(item)
        return item
    def test_adding_already_existing_favorite_returns_409_and_existing_representation(self, browser):
        self.login(self.administrator, browser=browser)

        create(Builder('favorite')
               .for_user(self.administrator)
               .for_object(self.document))

        oguid = Oguid.for_object(self.document)
        url = '{}/@favorites/{}'.format(
            self.portal.absolute_url(), self.administrator.getId())
        data = json.dumps({'oguid': oguid.id})

        with browser.expect_http_error(409):
            browser.open(url, data=data, method='POST',
                         headers={'Accept': 'application/json',
                                  'Content-Type': 'application/json'})

        self.assertEqual(
            {u'@id': u'http://nohost/plone/@favorites/nicole.kohler/1',
             u'portal_type': u'opengever.document.document',
             u'admin_unit': u'Hauptmandant',
             u'favorite_id': 1,
             u'icon_class': u'icon-docx',
             u'oguid': u'plone:1014073300',
             u'position': None,
             u'target_url': u'http://nohost/plone/resolve_oguid/plone:1014073300',
             u'title': u'Vertr\xe4gsentwurf',
             u'tooltip_url': u'http://nohost/plone/resolve_oguid/plone:1014073300/tooltip'},
            browser.json)

        self.assertEqual(1, Favorite.query.count())
Example #46
0
    def assert_submitted_document_created(self,
                                          proposal,
                                          document,
                                          submitted_version=0):
        portal = api.portal.get()
        submitted_document_model = SubmittedDocument.query.get_by_source(
            proposal,
            document,
        )

        submitted_document = portal.restrictedTraverse(
            submitted_document_model.submitted_physical_path.encode('utf-8'), )

        self.assertIsNotNone(submitted_document_model)

        self.assertEqual(
            Oguid.for_object(submitted_document),
            submitted_document_model.submitted_oguid,
        )

        self.assertEqual(
            submitted_version,
            submitted_document_model.submitted_version,
        )

        self.assertEqual(
            proposal.load_model(),
            submitted_document_model.proposal,
        )
    def test_responsible_has_reader_role_on_related_items_of_information_task(self):
        self.login(self.regular_user)

        # info_task is unidirectional by value
        manager = RoleAssignmentManager(self.document)
        assignment = manager.storage.get_by_reference(Oguid.for_object(self.info_task).id)[0]
        self.assertEqual(['Reader'], assignment.get('roles'))
Example #48
0
 def drop_existing(self, objs, userid):
     """It's possible, that the current user has already defined new style
     favorites. To prevent conflicts, we do not migrate already existing
     favorites.
     """
     current_favorites = FavoriteManager().list_all_repository_favorites(userid)
     oguids = [current_favorite.oguid for current_favorite in current_favorites]
     return [obj for obj in objs if Oguid.for_object(obj) not in oguids]
Example #49
0
    def _after_model_created(self, model_instance):
        IHistory(self).append_record(u'created')

        if self.predecessor_proposal is not None:
            predecessor = self.predecessor_proposal.to_object
            IHistory(predecessor).append_record(
                u'successor_created',
                successor_oguid=Oguid.for_object(self).id)
Example #50
0
    def sync_model(self, proposal_model=None):
        proposal_model = proposal_model or self.load_model()

        proposal_model.submitted_oguid = Oguid.for_object(self)
        proposal_model.submitted_physical_path = self.get_physical_path()
        proposal_model.submitted_admin_unit_id = get_current_admin_unit().id()
        proposal_model.submitted_title = self.title
        proposal_model.date_of_submission = self.date_of_submission
Example #51
0
    def test_revokes_permission_for_former_responsible(self, browser):
        self.login(self.regular_user, browser=browser)

        responsible = 'fa:{}'.format(self.secretariat_user.getId())
        self.assign_task(responsible, u'Thats a job for you.')

        manager = RoleAssignmentManager(self.task)
        self.assertEqual(
            [{'cause': ASSIGNMENT_VIA_TASK,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task).id,
              'principal': 'jurgen.konig'},
             {'cause': ASSIGNMENT_VIA_TASK_AGENCY,
              'roles': ['Editor'],
              'reference': Oguid.for_object(self.task).id,
              'principal': u'fa_inbox_users'}],
            manager.storage._storage())
Example #52
0
 def create_database_entry(self, meeting, document):
     if meeting.protocol_document is not None:
         raise ProtocolAlreadyGenerated()
     version = document.get_current_version_id(missing_as_zero=True)
     protocol_document = GeneratedProtocol(
         oguid=Oguid.for_object(document), generated_version=version)
     meeting.protocol_document = protocol_document
     return protocol_document
Example #53
0
    def test_oguid_for_object(self):
        intids = getUtility(IIntIds)

        obj = create(Builder('dossier'))
        int_id = intids.getId(obj)
        oguid = Oguid.for_object(obj)

        self.assertEqual('client1:{}'.format(int_id), oguid)
Example #54
0
    def create_database_entry(self, meeting, document):
        excerpt = GeneratedExcerpt(
            oguid=Oguid.for_object(document),
            generated_version=document.get_current_version())

        self.proposal.submitted_excerpt_document = excerpt

        return excerpt
Example #55
0
    def for_object(self, obj):
        self.arguments['oguid'] = Oguid.for_object(obj)
        self.arguments['title'] = obj.title
        self.arguments['portal_type'] = obj.portal_type
        self.arguments['icon_class'] = get_css_class(obj)
        self.arguments['plone_uid'] = IUUID(obj)

        return self