Exemple #1
0
    def test_download_version_after_a_change(self, browser):
        doc = create(
            Builder('document').attach_file_containing(
                u'text', name=u'file.pdf').within(self.dossier))
        initial_checksum = IBumblebeeDocument(doc).get_checksum()

        # We store these parameters as they were sent to bumblebee with /store
        params = {
            'token': download_token_for(doc),
            'uuid': IUUID(doc),
            'checksum': initial_checksum
        }

        # then the file changes, a new version is created.
        doc.file = NamedBlobFile(data='some other text', filename=u'foo.pdf')
        doc.setModificationDate(datetime.now())
        notify(ObjectEditedEvent(doc))
        transaction.commit()

        self.assertNotEqual(
            initial_checksum,
            IBumblebeeDocument(doc).get_checksum(),
            'Expected the checksum to have changed when object was updated.')

        # when accessing the previous version, the LRU may trigger a refresh
        # and may want to download the file again.
        browser.open(view='bumblebee_download', data=params)
        self.assertEqual('text', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))
Exemple #2
0
    def test_updates_checksum_and_queue_storing_after_docproperty_update(
            self, browser):
        api.portal.set_registry_record('create_doc_properties',
                                       interface=ITemplateFolderProperties,
                                       value=True)

        dossier = create(Builder('dossier'))
        document = create(
            Builder('document').within(dossier).checked_out().with_asset_file(
                'with_gever_properties.docx'))

        # update
        document.file = NamedBlobFile(
            data=assets.load(u'with_gever_properties_update.docx'),
            filename=u'with_gever_properties.docx')
        checksum_before = IBumblebeeDocument(document).update_checksum()

        browser.login().open(document)
        browser.click_on('without comment')

        self.assertNotEqual(
            checksum_before,
            IBumblebeeDocument(document).get_checksum(),
            'Document checksum not updated after docproperties update.')
        self.assertNotEqual(
            checksum_before,
            obj2brain(document).bumblebee_checksum,
            'Document checksum not updated after docproperties update.')
    def test_updates_checksum_after_docproperty_update(self):
        self.activate_feature('doc-properties')
        self.login(self.dossier_responsible)

        self.checkout_document(self.document)

        self.document.file = NamedBlobFile(
            data=assets.load(u'with_gever_properties_update.docx'),
            filename=u'with_gever_properties.docx',
        )

        checksum_before = IBumblebeeDocument(self.document).update_checksum()

        self.checkin_document(self.document)

        self.assertNotEqual(
            checksum_before,
            IBumblebeeDocument(self.document).get_checksum(),
            'Document checksum not updated after docproperties update.',
        )

        self.assertNotEqual(
            checksum_before,
            obj2brain(self.document).bumblebee_checksum,
            'Document checksum not updated after docproperties update.',
        )
Exemple #4
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)
Exemple #5
0
    def test_use_original_message_as_primary_field_if_available(self):
        mail_with_original_message = create(
            Builder('mail').with_message(
                MAIL_DATA).with_dummy_message().with_dummy_original_message())

        bumblebee_document = IBumblebeeDocument(mail_with_original_message)
        self.assertEqual('dummy.msg',
                         bumblebee_document.get_primary_field().filename)
Exemple #6
0
    def test_use_default_primary_field_without_original_message_available(
            self):
        mail_with_original_message = create(
            Builder('mail').with_message(MAIL_DATA).with_dummy_message())

        bumblebee_document = IBumblebeeDocument(mail_with_original_message)
        self.assertEqual('no-subject.eml',
                         bumblebee_document.get_primary_field().filename)
    def test_use_default_primary_field_without_original_message_available(self):
        mail_with_original_message = create(Builder('mail')
                                            .with_message(MAIL_DATA)
                                            .with_dummy_message())

        bumblebee_document = IBumblebeeDocument(mail_with_original_message)
        self.assertEqual(
            'no-subject.eml',
            bumblebee_document.get_primary_field().filename)
Exemple #8
0
 def test_deleting_after_extracting_updates_checksum(self, browser):
     browser.login().open(self.mail, view='extract_attachments')
     old_checksum = IBumblebeeDocument(self.mail).get_checksum()
     browser.fill({
         'attachments:list': ['1'],
         'delete_action': ['all']
     }).submit()
     new_checksum = IBumblebeeDocument(self.mail).get_checksum()
     self.assertNotEqual(old_checksum, new_checksum)
    def test_use_original_message_as_primary_field_if_available(self):
        mail_with_original_message = create(Builder('mail')
                                            .with_message(MAIL_DATA)
                                            .with_dummy_message()
                                            .with_dummy_original_message())

        bumblebee_document = IBumblebeeDocument(mail_with_original_message)
        self.assertEqual(
            'dummy.msg',
            bumblebee_document.get_primary_field().filename)
Exemple #10
0
 def test_deleting_after_extracting_does_not_update_checksum(self, browser):
     """ We use the original message for preview but deleting the attachments
     after extraction modifies the message and not the original_message, hence
     the checksum nor the preview will be modified.
     """
     browser.login().open(self.mail, view='extract_attachments')
     old_checksum = IBumblebeeDocument(self.mail).get_checksum()
     browser.fill({
         'attachments:list': ['1'],
         'delete_action': ['all']
     }).submit()
     new_checksum = IBumblebeeDocument(self.mail).get_checksum()
     self.assertEqual(old_checksum, new_checksum)
Exemple #11
0
    def test_update_checksum_on_reviving(self, browser):
        self.login(self.administrator, browser)

        browser.visit(self.document)
        self.document.file = NamedBlobFile(data='some other text',
                                           filename=u'foo.pdf')
        checksum_before_reviving = IBumblebeeDocument(
            self.document).get_checksum()
        browser.css('.actionMenuContent li').find(
            'Revive preview').first.click()
        checksum_after_reviving = IBumblebeeDocument(
            self.document).get_checksum()

        self.assertNotEqual(checksum_before_reviving, checksum_after_reviving)
    def test_rest_api(self, browser):
        self.login(self.regular_user, browser)

        payload = {
            u'@type': u'opengever.document.document',
            u'title': DOCUMENT_REQUIREDS['title'],
            u'file': {
                u'data': TestDocumentDefaults.SAMPLE_FILE.encode('base64'),
                u'encoding': u'base64',
                u'filename': u'b\xe4rengraben.txt',
                u'content-type': u'text/plain'},
        }
        with freeze(FROZEN_NOW):
            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'])
        doc = self.dossier.restrictedTraverse(new_object_id)

        # Ensure Bumblebee checksum got calculated correctly
        expected_checksum = sha256(self.SAMPLE_FILE).hexdigest()
        checksum = IBumblebeeDocument(doc).get_checksum()
        self.assertEqual(expected_checksum, checksum)

        persisted_values = get_persisted_values_for_obj(doc)
        expected = self.get_type_defaults()
        expected['file'] = doc.file

        self.assertDictEqual(expected, persisted_values)
    def test_z3c_add_form(self, browser):
        self.login(self.regular_user, browser)

        with freeze(FROZEN_NOW):
            with self.observe_children(self.dossier) as children:
                browser.open(self.dossier)
                factoriesmenu.add(u'Document')
                browser.fill({
                    u'Title': DOCUMENT_REQUIREDS['title'],
                    u'File': (
                        TestDocumentDefaults.SAMPLE_FILE,
                        'b\xc3\xa4rengraben.txt', 'text/plain')}).save()

        doc, = children.get('added')

        # Ensure Bumblebee checksum got calculated correctly
        expected_checksum = sha256(self.SAMPLE_FILE).hexdigest()
        checksum = IBumblebeeDocument(doc).get_checksum()
        self.assertEqual(expected_checksum, checksum)

        persisted_values = get_persisted_values_for_obj(doc)
        expected = self.get_z3c_form_defaults()
        expected['file'] = doc.file

        # XXX: Don't know why this happens
        expected['public_trial_statement'] = None

        self.assertDictEqual(expected, persisted_values)
    def test_rest_api(self, browser):
        self.login(self.regular_user, browser)

        payload = {
            u'@type': u'ftw.mail.mail',
            u'message': {
                u'data': TestMailDefaults.SAMPLE_MAIL.encode('base64'),
                u'encoding': u'base64',
                u'filename': u'msg.eml',
                u'content-type': u'message/rfc822'},
        }
        with freeze(FROZEN_NOW):
            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'])
        mail = self.dossier.restrictedTraverse(new_object_id)

        # Ensure Bumblebee checksum got calculated correctly
        expected_checksum = sha256(self.SAMPLE_MAIL).hexdigest()
        checksum = IBumblebeeDocument(mail).get_checksum()
        self.assertEqual(expected_checksum, checksum)

        persisted_values = get_persisted_values_for_obj(mail)
        expected = self.get_type_defaults()

        expected['message'] = mail._message

        self.assertDictEqual(expected, persisted_values)
    def test_z3c_add_form(self, browser):
        self.login(self.regular_user, browser)

        with freeze(FROZEN_NOW):
            # Mail is not addable via factories menu
            browser.open(self.dossier, view='++add++ftw.mail.mail')
            browser.fill({
                u'form.widgets.message': (TestMailDefaults.SAMPLE_MAIL,
                                          'msg.eml', 'message/rfc822')}).save()

        mail = browser.context

        # Ensure Bumblebee checksum got calculated correctly
        expected_checksum = sha256(self.SAMPLE_MAIL).hexdigest()
        checksum = IBumblebeeDocument(mail).get_checksum()
        self.assertEqual(expected_checksum, checksum)

        persisted_values = get_persisted_values_for_obj(mail)
        expected = self.get_z3c_form_defaults()

        expected['message'] = mail._message

        # XXX: Don't know why this happens
        expected['public_trial_statement'] = None

        self.assertDictEqual(expected, persisted_values)
    def test_mail_serialization_contains_bumblebee_checksum(self, browser):
        self.login(self.regular_user, browser)
        browser.open(self.mail_eml, headers=self.api_headers)
        self.assertEqual(browser.status_code, 200)

        checksum = IBumblebeeDocument(self.mail_eml).get_checksum()
        self.assertEqual(browser.json.get(u'bumblebee_checksum'), checksum)
    def test_bumblebee_checksum_is_calculated_for_opengever_docs(self):
        self.login(self.dossier_responsible)

        self.assertEquals(
            DOCX_CHECKSUM,
            IBumblebeeDocument(self.document).get_checksum(),
        )
Exemple #18
0
    def test_prevents_checked_out_document_checksum_update(self):
        document = create(
            Builder('document').attach_file_containing(
                bumblebee_asset('example.docx').bytes(),
                u'example.docx').checked_out())

        self.assertEquals(DOCX_CHECKSUM,
                          IBumblebeeDocument(document).get_checksum())

        document.update_file(filename=u'foo.txt',
                             content_type='text/plain',
                             data='foo')
        notify(ObjectModifiedEvent(document))

        self.assertEquals(DOCX_CHECKSUM,
                          IBumblebeeDocument(document).get_checksum())
Exemple #19
0
    def test_document_creation(self, browser):
        self.login(self.regular_user, browser)
        payload = {
            u'@type': u'opengever.document.document',
            u'title': u'Sanierung B\xe4rengraben 2016',
            u'file': {
                u'data': u'TG9yZW0gSXBzdW0uCg==',
                u'encoding': u'base64',
                u'filename': u'b\xe4rengraben.txt',
                u'content-type': u'text/plain'
            },
        }
        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'])
        doc = self.dossier.restrictedTraverse(new_object_id)
        self.assertEqual(u'Sanierung B\xe4rengraben 2016', doc.title)
        self.assertEqual(u'Sanierung Baerengraben 2016.txt', doc.file.filename)

        checksum = IBumblebeeDocument(doc).get_checksum()
        self.assertIsNotNone(checksum)
Exemple #20
0
    def test_download_last_version_for_checked_out_docs(self, browser):
        content = bumblebee_asset('example.docx').bytes()
        document = create(
            Builder('document').attach_file_containing(
                content, u'example.docx').checked_out())

        document.update_file(filename=u'foo.txt',
                             content_type='text/plain',
                             data='foo')
        notify(ObjectModifiedEvent(document))
        transaction.commit()

        # checksum has not been updated
        self.assertEqual(DOCX_CHECKSUM,
                         IBumblebeeDocument(document).get_checksum())

        # download first history version
        browser.open(view='bumblebee_download',
                     data={
                         'token': download_token_for(document),
                         'uuid': IUUID(document),
                         'checksum': DOCX_CHECKSUM
                     })
        self.assertEqual(content, browser.contents)
        self.assertEqual(
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            browser.headers.get('Content-Type'))
    def __call__(self):
        """Handles the reviving process.
        """
        if self.available():

            # Indicates that this context should not be converted if the
            # checksum didn't change. Even the force attribute respects this
            # marker-attribute.
            #
            # Because we really want to update the document, we just remove
            # this property.
            if hasattr(self.context, '_v_bumblebee_last_converted'):
                delattr(self.context, '_v_bumblebee_last_converted')

            # Forces a document-update. Means, regenerating the checksum
            # and queue storing in bumblebee.
            IBumblebeeDocument(self.context)._handle_update(force=True)

            api.portal.show_message(message=_(
                u'preview_revived',
                default=u'Preview revived and will be available soon'),
                                    request=self.request,
                                    type='info')
        else:
            api.portal.show_message(message=_(
                u'preview_revive_not_available',
                default=
                u'Reviving the preview is not available for this context.'),
                                    request=self.request,
                                    type='error')

        return self.request.RESPONSE.redirect(self.context.absolute_url())
Exemple #22
0
 def get_data_for_zip_export(self):
     meeting_data = {
         'title':
         safe_unicode(self.title),
         'start':
         safe_unicode(self.start.isoformat()),
         'end':
         safe_unicode(self.end and self.end.isoformat() or ''),
         'location':
         safe_unicode(self.location),
         'committee': {
             'oguid': safe_unicode(self.committee.oguid.id),
             'title': safe_unicode(self.committee.title),
         },
         'agenda_items':
         map(methodcaller('get_data_for_zip_export'), self.agenda_items),
     }
     if self.has_protocol_document():
         document = self.protocol_document.resolve_document()
         meeting_data.update({
             'protocol': {
                 'checksum': (IBumblebeeDocument(document).get_checksum()),
                 'file':
                 normalize_path(
                     safe_unicode('{}.docx'.format(document.Title()))),
                 'modified':
                 safe_unicode(get_localzone().localize(
                     document.modified().asdatetime().replace(
                         tzinfo=None)).isoformat()),
             }
         })
     return meeting_data
Exemple #23
0
    def test_bumblebee_checksum_updated_when_document_modified(self):
        self.login(self.dossier_responsible)

        pre_update_checksum = IBumblebeeDocument(self.document).get_checksum()

        DocPropertyWriter(
            self.document).update_doc_properties(only_existing=False)

        post_update_checksum = IBumblebeeDocument(self.document).get_checksum()
        self.assertEqual(
            post_update_checksum,
            IBumblebeeDocument(self.document).update_checksum(),
            "Cached checksum and freshly calculated checksums must match.")
        self.assertNotEqual(
            pre_update_checksum, post_update_checksum,
            "Expected bumblebee checksum to change when the document has been "
            "modified")
Exemple #24
0
    def find_version_obj_by_checksum(self, obj, checksum):
        """Don't access the document when it is checked out.

        In that case the checksum has not been updated yet and thus is
        equivalent with the checksum of the most recent version.

        """
        if not obj.is_checked_out() and \
                IBumblebeeDocument(obj).get_checksum() == checksum:
            return obj

        repository = api.portal.get_tool('portal_repository')
        for version in repository.getHistory(obj):
            if IBumblebeeDocument(version.object).get_checksum() == checksum:
                return version.object

        raise NotFound('Version not found by checksum.')
Exemple #25
0
 def update_bumblebee_mail_checksums(self):
     if not is_bumblebee_feature_enabled():
         return
     for obj in self.objects(
         {'object_provides': IOGMailMarker.__identifier__},
             'Recalculate checksum and rebuild visual preview for mails'):
         if IOGMail(obj).original_message:
             continue
         IBumblebeeDocument(obj).handle_modified()
Exemple #26
0
 def success_callback_fields(self, exporter, document):
     doc_in_job_id = exporter.zip_job._get_doc_in_job_id(document)
     return {
         'token': get_demand_callback_access_token(),
         'status': 'success',
         'document': IBumblebeeDocument(document).get_checksum(),
         'opaque_id': doc_in_job_id,
         'pdf': ('converted.pdf', 'the pdf', 'application/pdf'),
     }
Exemple #27
0
    def __call__(self):
        self.install_upgrade_profile()
        service = get_service_v3()

        msg = 'Reindex checksum for documents having one of the following ' \
              'file-extensions: {}.'.format(', '.join(self.additional_mimetypes))

        for obj in ProgressLogger(msg, self.objs_to_perform()):
            IBumblebeeDocument(obj).update_checksum()
            service.trigger_storing(obj, deferred=True)
    def test_prevents_checked_out_document_checksum_update(self):
        self.login(self.dossier_responsible)
        self.checkout_document(self.document)

        self.assertEquals(
            DOCX_CHECKSUM,
            IBumblebeeDocument(self.document).get_checksum(),
        )

        self.document.update_file(
            'foo',
            content_type='text/plain',
            filename=u'foo.txt',
        )

        IBumblebeeDocument(self.document).handle_modified()

        self.assertEquals(
            DOCX_CHECKSUM,
            IBumblebeeDocument(self.document).get_checksum(),
        )
Exemple #29
0
 def traverse_agenda_item_document(self, document, agenda_item):
     self.current_agenda_item_data['number'] = agenda_item.formatted_number
     self.current_agenda_item_data['number_raw'] = agenda_item.item_number
     self.current_agenda_item_data['proposal'] = {
         'checksum':
         IBumblebeeDocument(document).get_checksum(),
         'file':
         self.zipper.get_agenda_item_filename(document,
                                              agenda_item.formatted_number),
         'modified':
         format_modified(document.modified()),
     }
Exemple #30
0
    def __call__(self):
        self.install_upgrade_profile()
        catalog = api.portal.get_tool('portal_catalog')
        query = {'portal_type': 'opengever.meeting.sablontemplate'}
        msg = 'Add bumblebee-previews for sablontemplates.'

        for obj in self.objects(query, msg):
            IBumblebeeDocument(obj).update_checksum()
            catalog.reindexObject(obj, idxs=['object_provides'],
                                  update_metadata=False)

            if is_bumblebee_feature_enabled():
                get_service_v3().trigger_storing(obj, deferred=True)
Exemple #31
0
    def test_checksum_is_updated_before_storing_version(self, browser):
        content = bumblebee_asset('example.docx').bytes()
        document = create(Builder('document')
                          .within(self.dossier)
                          .attach_file_containing(
                              content,
                              u'example.docx')
                          .checked_out())

        document.update_file(filename=u'foo.txt',
                             content_type='text/plain',
                             data='foo')
        notify(ObjectModifiedEvent(document))
        transaction.commit()

        # checksum has not been updated
        self.assertEqual(
            DOCX_CHECKSUM, IBumblebeeDocument(document).get_checksum())

        manager = getMultiAdapter((document, self.portal.REQUEST),
                                  ICheckinCheckoutManager)
        manager.checkin()

        # checksum has been updated
        self.assertEqual(TXT_CHECKSUM,
                         IBumblebeeDocument(document).get_checksum())

        repository = api.portal.get_tool("portal_repository")
        history = repository.getHistoryMetadata(document)
        self.assertEqual(2, history.getLength(countPurged=False))

        version_0 = repository.retrieve(document, 0)
        self.assertEqual(DOCX_CHECKSUM,
                         IBumblebeeDocument(version_0.object).get_checksum())

        # document checksum should be updated before storing the version
        version_1 = repository.retrieve(document, 1)
        self.assertEqual(TXT_CHECKSUM,
                         IBumblebeeDocument(version_1.object).get_checksum())
Exemple #32
0
    def test_download_newest_version(self, browser):
        doc = create(
            Builder('document').attach_file_containing(
                u'The Content', name=u'file.pdf').within(self.dossier))

        browser.open(view='bumblebee_download',
                     data={
                         'token': download_token_for(doc),
                         'uuid': IUUID(doc),
                         'checksum': IBumblebeeDocument(doc).get_checksum()
                     })
        self.assertEqual('The Content', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))