Ejemplo n.º 1
0
    def test_migrate_object_position(self):
        self.grant('Manager')
        container = create(Builder('folder').titled(u'Container'))
        one = create(Builder('folder').titled(u'One').within(container))
        two = create(Builder('folder').titled(u'Two').within(container))
        three = create(Builder('folder').titled(u'Three').within(container))

        self.assertEquals([0, 1, 2],
                          map(container.getObjectPosition,
                              ('one', 'two', 'three')))
        container.moveObjectsByDelta(['three'], -1)
        self.assertEquals([0, 2, 1],
                          map(container.getObjectPosition,
                              ('one', 'two', 'three')))

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Folder').migrate_object(container)
        InplaceMigrator('Folder').migrate_object(three)
        InplaceMigrator('Folder').migrate_object(two)
        InplaceMigrator('Folder').migrate_object(one)
        container = self.portal.get('container')

        self.assertEquals([0, 2, 1],
                          map(container.getObjectPosition,
                              ('one', 'two', 'three')))
Ejemplo n.º 2
0
    def __init__(self, ignore_fields=(), additional_steps=(), options=0,
                 field_mapping=None):
        if IMPORT_ERROR:
            raise IMPORT_ERROR

        # Old listing blocks may be migrated to new listing blocks or may
        # become gallery blocks when suitable.
        # https://github.com/4teamwork/izug.organisation/issues/890

        ignore_fields = DUBLIN_CORE_IGNORES + SL_BLOCK_DEFAULT_IGNORED_FIELDS + (
            'description',  # hidden thus unused
        ) + ignore_fields

        field_mapping = field_mapping or {}
        field_mapping.update({
            'showTitle': 'show_title',
            'sortOn': 'sort_on',
            'sortOrder': 'sort_order',
            'tableColumns': 'columns'})

        self.filelisting_migrator = InplaceMigrator(
            new_portal_type='ftw.simplelayout.FileListingBlock',
            ignore_fields=ignore_fields + ('slick_settings',),
            field_mapping=field_mapping,
            additional_steps=additional_steps,
            options=options,
        )

        self.gallery_migrator = InplaceMigrator(
            new_portal_type='ftw.simplelayout.GalleryBlock',
            ignore_fields=ignore_fields + (
                'slick_settings',
                'sortOn',
                'sortOrder',
                'tableColumns'),
            field_mapping=field_mapping,
            additional_steps=additional_steps,
            options=options,
        )

        self.sliderblock_migrator = InplaceMigrator(
            new_portal_type='ftw.sliderblock.SliderBlock',
            ignore_fields=ignore_fields + (
                'sortOn',
                'sortOrder',
                'tableColumns'),
            field_mapping={
                'showTitle': 'show_title',
                'crop_image': 'False',
                'slick_settings': 'slick_config'},
            additional_steps=additional_steps,
            options=options,
        )

        self.image_to_slider_pane_migrator = ImageToSliderPaneMigrator(
            ignore_fields=ignore_fields,
            field_mapping=field_mapping,
            options=options)
Ejemplo n.º 3
0
    def migrate_refegovservice(self):

        migrator = InplaceMigrator(
            new_portal_type='izug.refegovservice.refegovservice',
            ignore_fields=('allowDiscussion', 'relatedItems'),
        )

        for obj in self.objects({'portal_type': 'RefEgovService'},
                                'Migrate RefEgovService to dexterity type '
                                'izug.refegovservice.refegovservice'):
            migrator.migrate_object(obj)
Ejemplo n.º 4
0
    def test_migrate_constrain_types(self):
        self.grant('Manager')
        self.maxDiff = None

        folder = create(Builder('folder').titled(u'The Folder'))
        self.set_constraintypes_config(
            folder, {
                'mode': ENABLED,
                'locally allowed': ['Folder', 'Document', 'File'],
                'immediately addable': ['Folder', 'Document']
            })

        self.assertTrue(IBaseObject.providedBy(folder))
        self.assertFalse(IDexterityContent.providedBy(folder))
        self.assertDictEqual(
            {
                'mode': ENABLED,
                'locally allowed': {'Folder', 'Document', 'File'},
                'immediately addable': {'Folder', 'Document'}
            }, self.get_constraintypes_config(folder))

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Folder').migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertFalse(IBaseObject.providedBy(folder))
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertDictEqual(
            {
                'mode': ENABLED,
                'locally allowed': {'Folder', 'Document', 'File'},
                'immediately addable': {'Folder', 'Document'}
            }, self.get_constraintypes_config(folder))
Ejemplo n.º 5
0
    def test_migrate_ownership_no_IOwner(self):
        john = create(
            Builder('user').named('John', 'Doe').with_roles('Manager'))
        peter = create(
            Builder('user').named('Peter', 'Pan').with_roles('Manager'))

        login(self.portal, john.getId())
        folder = create(Builder('folder').titled(u'The Folder'))
        folder.changeOwnership(peter.getUser())

        self.assertTrue(IBaseObject.providedBy(folder))
        self.assertEqual('john.doe', folder.Creator())
        self.assertEqual('peter.pan', folder.getOwner().getId())

        self.grant('Manager')
        self.install_profile('plone.app.contenttypes:default')

        # The creators list behaves differently when the dublin core
        # behavior is used.
        self.portal.portal_types['Folder'].behaviors = tuple(
            name for name in self.portal.portal_types['Folder'].behaviors
            if not (name == 'plone.dublincore' or 'IDublinCore' in name
                    or name == 'plone.ownership' or 'IOwnership' in name))
        with self.login(SITE_OWNER_NAME):
            InplaceMigrator(
                'Folder',
                options=IGNORE_UNMAPPED_FIELDS).migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertEqual('john.doe', folder.Creator())
        self.assertEqual('peter.pan', folder.getOwner().getId())
Ejemplo n.º 6
0
    def test_IGNORE_UNMAPPED_FIELDS_flag(self):
        self.grant('Manager')
        folder = create(Builder('folder'))
        self.install_profile('plone.app.contenttypes:default')

        (InplaceMigrator('Folder',
                         options=DISABLE_FIELD_AUTOMAPPING
                         | IGNORE_UNMAPPED_FIELDS).migrate_object(folder))
Ejemplo n.º 7
0
    def test_migrate_dexterity_folder_to_dexterity(self):
        self.grant('Manager')
        self.install_profile('plone.app.contenttypes:default')

        creation_date = datetime(2015, 11, 29, 10, 45)
        modification_date = datetime(2016, 1, 2, 9, 30)
        effective_date = datetime(2016, 2, 2, 2, 30)
        expires_date = datetime(2016, 3, 3, 3, 30)

        with dx_content_builders_registered():
            with freeze(creation_date):
                folder = create(
                    Builder('folder').titled(u'The Folder').having(
                        description=u'The Description',
                        exclude_from_nav=True,
                        subjects=(u'One', u'Two'),
                        effective=effective_date,
                        expires=expires_date).in_state('pending'))

        with freeze(modification_date):
            folder.reindexObject()  # update modification date

        self.assertFalse(IBaseObject.providedBy(folder))
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertEqual(('', 'plone', 'the-folder'), folder.getPhysicalPath())
        self.assertEqual('The Folder', folder.Title())
        self.assertEqual('The Description', folder.Description())
        self.assertEqual(True, folder.exclude_from_nav)
        self.assertEqual(('One', 'Two'), folder.Subject())
        self.assertEqual(todt(creation_date), todt(folder.created()))
        self.assertEqual(todt(modification_date), todt(folder.modified()))
        self.assertEqual(todt(effective_date), todt(folder.effective()))
        self.assertEqual(todt(expires_date), todt(folder.expires()))
        self.assertEqual('pending', self.review_state(folder))

        old_catalog_indexdata = self.get_catalog_indexdata_for(folder)

        InplaceMigrator('Folder').migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertFalse(IBaseObject.providedBy(folder))
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertEqual(('', 'plone', 'the-folder'), folder.getPhysicalPath())
        self.assertEqual('The Folder', folder.Title())
        self.assertEqual('The Description', folder.Description())
        self.assertEqual(True, folder.exclude_from_nav)
        self.assertEqual(('One', 'Two'), folder.Subject())
        self.assertEqual(todt(creation_date), todt(folder.created()))
        self.assertEqual(todt(modification_date), todt(folder.modified()))
        self.assertEqual(todt(effective_date), todt(folder.effective()))
        self.assertEqual(todt(expires_date), todt(folder.expires()))
        self.assertEqual('pending', self.review_state(folder))

        self.maxDiff = None
        self.assertDictEqual(old_catalog_indexdata,
                             self.get_catalog_indexdata_for(folder))
Ejemplo n.º 8
0
    def test_field_mapping_overrides_auto_mapping(self):
        self.grant('Manager')
        folder = create(Builder('folder').titled(u'The Title'))
        self.install_profile('plone.app.contenttypes:default')

        InplaceMigrator('Folder', {
            'title': 'description'
        },
                        ignore_fields=['description']).migrate_object(folder)
        folder = self.portal.get(folder.getId())
        self.assertEquals(u'The Title', folder.Description())
Ejemplo n.º 9
0
    def test_IGNORE_DEFAULT_IGNORE_FIELDS_flag(self):
        self.grant('Manager')
        folder = create(Builder('folder'))
        self.install_profile('plone.app.contenttypes:default')

        with self.assertRaises(FieldsNotMappedError) as cm:
            (InplaceMigrator(
                'Folder',
                options=IGNORE_DEFAULT_IGNORE_FIELDS).migrate_object(folder))

        self.assertIn('location', cm.exception.not_mapped_fields)
Ejemplo n.º 10
0
    def test_DISABLE_FIELD_AUTOMAPPING_flag(self):
        """When disabling field automapping we expect unmaped fields.
        """

        self.grant('Manager')
        folder = create(Builder('folder'))
        self.install_profile('plone.app.contenttypes:default')

        with self.assertRaises(FieldsNotMappedError) as cm:
            (InplaceMigrator(
                'Folder',
                options=DISABLE_FIELD_AUTOMAPPING).migrate_object(folder))

        self.assertIn('title', cm.exception.not_mapped_fields)
Ejemplo n.º 11
0
    def test_migrate_empty_richtextfield_to_dexterity(self):
        self.grant('Manager')

        no_text_page = create(
            Builder('page').titled(u'No Text Page').having(
                text=u'').in_state('published'))

        self.assertFalse(IDexterityContent.providedBy(no_text_page))
        self.assertTrue(IBaseObject.providedBy(no_text_page))
        self.assertEqual(u'', no_text_page.getText())

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Document').migrate_object(no_text_page)

        no_text_page = self.portal.get('no-text-page')
        self.assertFalse(IBaseObject.providedBy(no_text_page))
        self.assertTrue(IDexterityContent.providedBy(no_text_page))
        self.assertNotIsInstance(no_text_page.text, RichTextValue)
Ejemplo n.º 12
0
    def test_migrate_relations(self):
        self.grant('Manager')

        foo = create(Builder('folder').titled(u'Foo'))
        bar = create(
            Builder('folder').titled(u'Bar').having(relatedItems=[foo]))

        self.assertEquals([foo], bar.getRelatedItems())
        self.assertEquals([bar], foo.getBackReferences())

        self.install_profile('plone.app.contenttypes:default')
        map(InplaceMigrator('Folder').migrate_object, (foo, bar))

        foo = self.portal.get('foo')
        bar = self.portal.get('bar')

        self.assertEquals([foo],
                          map(attrgetter('to_object'),
                              IRelatedItems(bar).relatedItems))
Ejemplo n.º 13
0
    def test_migrate_archetypes_file_to_dexterity(self):
        self.grant('Manager')

        thefile = create(
            Builder('file').titled(u'The File').attach_file_containing(
                '<doc>Content</doc>', name='data.xml'))

        self.assertTrue(IBaseObject.providedBy(thefile))
        self.assertFalse(IDexterityContent.providedBy(thefile))
        self.assertEqual('The File', thefile.Title())

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('File').migrate_object(thefile)

        thefile = self.portal.get('the-file')
        self.assertFalse(IBaseObject.providedBy(thefile))
        self.assertTrue(IDexterityContent.providedBy(thefile))
        self.assertEqual(('', 'plone', 'the-file'), thefile.getPhysicalPath())
        self.assertEqual('The File', thefile.Title())
        self.assertEqual('data.xml', thefile.file.filename)
        self.assertEqual('<doc>Content</doc>', thefile.file.data)
Ejemplo n.º 14
0
    def test_migrate_ownership(self):
        john = create(
            Builder('user').named('John', 'Doe').with_roles('Manager'))
        peter = create(
            Builder('user').named('Peter', 'Pan').with_roles('Manager'))

        login(self.portal, john.getId())
        folder = create(Builder('folder').titled(u'The Folder'))
        folder.changeOwnership(peter.getUser())

        self.assertTrue(IBaseObject.providedBy(folder))
        self.assertEquals('john.doe', folder.Creator())
        self.assertEquals('peter.pan', folder.getOwner().getId())

        self.grant('Manager')
        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Folder').migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertEquals('john.doe', folder.Creator())
        self.assertEquals('peter.pan', folder.getOwner().getId())
Ejemplo n.º 15
0
    def test_migrate_portlets(self):
        self.grant('Manager')

        folder = create(Builder('folder').titled(u'The Folder'))
        portlet = create(
            Builder('static portlet').within(folder).in_manager(
                'plone.rightcolumn'))

        self.assertEquals(
            {
                'plone.leftcolumn': [],
                'plone.rightcolumn': [portlet]
            }, self.get_portlets_for(folder))

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Folder').migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertEquals(
            {
                'plone.leftcolumn': [],
                'plone.rightcolumn': [portlet]
            }, self.get_portlets_for(folder))
Ejemplo n.º 16
0
    def test_migrate_archetypes_page_to_dexterity(self):
        self.grant('Manager')

        page = create(
            Builder('page').titled(u'The Page').having(
                text='<p>Some Text</p>').in_state('published'))

        self.assertTrue(IBaseObject.providedBy(page))
        self.assertFalse(IDexterityContent.providedBy(page))
        self.assertEqual('The Page', page.Title())
        self.assertEqual('<p>Some Text</p>', page.getText())
        self.assertEqual('published', self.review_state(page))

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Document').migrate_object(page)

        page = self.portal.get('the-page')
        self.assertFalse(IBaseObject.providedBy(page))
        self.assertTrue(IDexterityContent.providedBy(page))
        self.assertEqual(('', 'plone', 'the-page'), page.getPhysicalPath())
        self.assertEqual('The Page', page.Title())
        self.assertIsInstance(page.text, RichTextValue)
        self.assertEqual('<p>Some Text</p>', page.text.output)
        self.assertEqual('published', self.review_state(page))
Ejemplo n.º 17
0
    def test_BACKUP_AND_IGNORE_UNMAPPED_FIELDS_flag(self):
        self.grant('Manager')
        folder = create(
            Builder('folder').titled(u'The Folder').having(
                description='A very fancy folder.'))
        self.install_profile('plone.app.contenttypes:default')

        new_folder = (InplaceMigrator(
            'Folder',
            options=DISABLE_FIELD_AUTOMAPPING
            | BACKUP_AND_IGNORE_UNMAPPED_FIELDS).migrate_object(folder))

        self.assertEquals(
            {
                'nextPreviousEnabled': False,
                'description': u'A very fancy folder.',
                'contributors': (),
                'title': u'The Folder',
                'rights': u'',
                'language': u'en',
                'relatedItems': [],
                'creators': (u'test_user_1_', )
            },
            IAnnotations(new_folder).get(UNMAPPED_FIELDS_BACKUP_ANN_KEY, None))
Ejemplo n.º 18
0
class ListingBlockMigrator(object):

    def __init__(self, ignore_fields=(), additional_steps=(), options=0,
                 field_mapping=None):
        if IMPORT_ERROR:
            raise IMPORT_ERROR

        # Old listing blocks may be migrated to new listing blocks or may
        # become gallery blocks when suitable.
        # https://github.com/4teamwork/izug.organisation/issues/890

        ignore_fields = DUBLIN_CORE_IGNORES + SL_BLOCK_DEFAULT_IGNORED_FIELDS + (
            'description',  # hidden thus unused
        ) + ignore_fields

        field_mapping = field_mapping or {}
        field_mapping.update({
            'showTitle': 'show_title',
            'sortOn': 'sort_on',
            'sortOrder': 'sort_order',
            'tableColumns': 'columns'})

        self.filelisting_migrator = InplaceMigrator(
            new_portal_type='ftw.simplelayout.FileListingBlock',
            ignore_fields=ignore_fields + ('slick_settings',),
            field_mapping=field_mapping,
            additional_steps=additional_steps,
            options=options,
        )

        self.gallery_migrator = InplaceMigrator(
            new_portal_type='ftw.simplelayout.GalleryBlock',
            ignore_fields=ignore_fields + (
                'slick_settings',
                'sortOn',
                'sortOrder',
                'tableColumns'),
            field_mapping=field_mapping,
            additional_steps=additional_steps,
            options=options,
        )

        self.sliderblock_migrator = InplaceMigrator(
            new_portal_type='ftw.sliderblock.SliderBlock',
            ignore_fields=ignore_fields + (
                'sortOn',
                'sortOrder',
                'tableColumns'),
            field_mapping={
                'showTitle': 'show_title',
                'crop_image': 'False',
                'slick_settings': 'slick_config'},
            additional_steps=additional_steps,
            options=options,
        )

        self.image_to_slider_pane_migrator = ImageToSliderPaneMigrator(
            ignore_fields=ignore_fields,
            field_mapping=field_mapping,
            options=options)

    def query(self, path=None):
        query = {'portal_type': 'ListingBlock'}
        if path:
            query['path'] = path
        return query

    def migrate_object(self, old_object):
        view = IBlockConfig(old_object).get_viewname()
        if view not in (None, '', 'gallery', 'dummy', 'block_view', 'slider'):
            raise ValueError('ListingBlock: unexpected view {!r}'.format(view))

        children_types = set(map(attrgetter('portal_type'),
                                 old_object.objectValues()))

        if view == 'slider' and children_types == {'Image'}:
            map(self.image_to_slider_pane_migrator.migrate_object,
                old_object.objectValues()[:])
            self.sliderblock_migrator.migrate_object(old_object)

        elif not children_types or children_types == {'File'}:
            self.filelisting_migrator.migrate_object(old_object)

        elif children_types == {'Image'}:
            self.gallery_migrator.migrate_object(old_object)

        elif children_types == {'File', 'Image'}:
            # convert all "Image" children to "File"
            map(migrate_image_to_file,
                filter(lambda child: child.portal_type=='Image',
                       old_object.objectValues()))

            self.filelisting_migrator.migrate_object(old_object)

        else:
            raise ValueError('ListingBlock: unexpected children: {}'.format(
                children_types))
Ejemplo n.º 19
0
    def test_migrate_archetypes_folder_to_dexterity(self):
        self.grant('Manager')

        creation_date = datetime(2015, 11, 29, 10, 45)
        modification_date = datetime(2016, 1, 2, 9, 30)
        effective_date = datetime(2016, 2, 2, 2, 30)
        expires_date = datetime(2016, 3, 3, 3, 30)

        with freeze(creation_date):
            folder = create(
                Builder('folder').titled(u'The Folder').having(
                    description='The Description',
                    excludeFromNav=True,
                    subject='One\nTwo',
                    effectiveDate=DateTime(effective_date),
                    expirationDate=DateTime(expires_date)).in_state(
                        'published'))

        setattr(folder, '__ac_local_roles_block__', True)
        create(
            Builder('user').named('Hugo', 'Boss').with_roles(
                'Reader', 'Editor', on=self.portal))  # local roles!
        create(
            Builder('user').named('John', 'Doe').with_roles('Reader',
                                                            'Editor',
                                                            on=folder))

        folder._setProperty('search_label', 'HB', 'string')

        with freeze(modification_date):
            folder.reindexObject()  # update modification date

        self.assertTrue(IBaseObject.providedBy(folder))
        self.assertFalse(IDexterityContent.providedBy(folder))
        self.assertEqual(('', 'plone', 'the-folder'), folder.getPhysicalPath())
        self.assertEqual('The Folder', folder.Title())
        self.assertEqual('The Description', folder.Description())
        self.assertEqual(True, folder.exclude_from_nav())
        self.assertEqual(('One', 'Two'), folder.Subject())
        self.assertEqual(todt(creation_date), todt(folder.created()))
        self.assertEqual(todt(modification_date), todt(folder.modified()))
        self.assertEqual(todt(effective_date), todt(folder.effective()))
        self.assertEqual(todt(expires_date), todt(folder.expires()))
        self.assertEqual('HB', folder.getProperty('search_label', None))
        self.assertEqual('published', self.review_state(folder))
        self.assertEqual((('john.doe', ('Reader', 'Editor')), ('test_user_1_',
                                                               ('Owner', ))),
                         folder.get_local_roles())

        old_catalog_indexdata = self.get_catalog_indexdata_for(folder)

        self.install_profile('plone.app.contenttypes:default')
        InplaceMigrator('Folder').migrate_object(folder)

        folder = self.portal.get('the-folder')
        self.assertFalse(IBaseObject.providedBy(folder))
        self.assertTrue(IDexterityContent.providedBy(folder))
        self.assertEqual(('', 'plone', 'the-folder'), folder.getPhysicalPath())
        self.assertEqual('The Folder', folder.Title())
        self.assertEqual('The Description', folder.Description())
        self.assertEqual(True, folder.exclude_from_nav)
        self.assertEqual(('One', 'Two'), folder.Subject())
        self.assertEqual(todt(creation_date), todt(folder.created()))
        self.assertEqual(todt(modification_date), todt(folder.modified()))
        self.assertEqual(todt(effective_date), todt(folder.effective()))
        self.assertEqual(todt(expires_date), todt(folder.expires()))
        self.assertEqual('HB', folder.getProperty('search_label', None))
        self.assertEqual('published', self.review_state(folder))
        self.assertEqual((('john.doe', ('Reader', 'Editor')), ('test_user_1_',
                                                               ('Owner', ))),
                         folder.get_local_roles())

        self.maxDiff = None

        new_catalog_indexdata = self.get_catalog_indexdata_for(folder)
        # In Plone 4.3.7, the SearchableText changes here.
        del old_catalog_indexdata['SearchableText']
        del new_catalog_indexdata['SearchableText']

        self.assertDictEqual(old_catalog_indexdata, new_catalog_indexdata)