Пример #1
0
 def test_version_prefixed_title_rename_with_migration(self):
     """ Test the version id of all versions changes to match
         new prefix after performing migration
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     assert IVersionControl(link).versionId == 'LNK-1'
     vobjs.title = 'LINK'
     link2_id = self.folder.invokeFactory("Link", 'l2')
     link2 = self.folder[link2_id]
     # after tool object title is modified new version id will
     # use the new title
     assert IVersionControl(link2).versionId == 'LINK-2'
     # previous versions keep their prefix and number
     assert IVersionControl(link).versionId == 'LNK-1'
     migration_view = link.restrictedTraverse('@@migrateVersions')
     migration_view(prefix='LINK')
     # assert that now all of the links use the new LINK prefix
     # after running the migration script
     assert IVersionControl(link).versionId == 'LINK-1'
     assert IVersionControl(link2).versionId == 'LINK-2'
Пример #2
0
def spec_assign_version(context, new_version):
    """Assign a specific version id to an object

    We override the same method from eea.versions. We want to
    be able to reassign version for children Assessments to be
    at the same version as the children Assessments of the target
    Specification version.

    Also, we want to assign the new version to all specification
    that had the old version.
    """

    #assign new version to context
    base_assign_version(context, new_version)

    #search for specifications with the old version and assign new version
    other_assessments = []  #optimization: children assessments from other specs
    versions = [o for o in IGetVersions(context).versions()
                           if o.meta_type == "Specification"]
    for o in versions:
        IVersionControl(o).setVersionId(new_version)
        o.reindexObject()
        other_assessments.extend(o.objectValues("Assessment"))

    #reassign version ids to context assessments + assessments
    #from related specifications
    vid = get_assessment_vid_for_spec_vid(context, new_version)
    for asmt in (list(context.objectValues('Assessment')) +
                 list(other_assessments)):
        IVersionControl(asmt).setVersionId(vid)
        asmt.reindexObject()
Пример #3
0
def getVersionIdForIndex(obj):
    """indexes versionid
    """
    try:
        ver = IVersionControl(obj)
        return ver.getVersionId()
    except (TypeError, ValueError):  #ComponentLookupError,
        # The catalog expects AttributeErrors when a value can't be found
        raise AttributeError
Пример #4
0
def getVersionIdForIndex(obj):
    """indexes versionid
    """
    try:
        ver = IVersionControl(obj)
        return ver.getVersionId()
    except (TypeError, ValueError): #ComponentLookupError,
        # The catalog expects AttributeErrors when a value can't be found
        raise AttributeError
Пример #5
0
    def __call__(self, *args, **kwargs):
        if not IVersionControl:
            return self._redirect("eea.versions NOT installed", "warn")

        try:
            version = IVersionControl(self.context)
            return self.fixVersion(version.getVersionId())
        except Exception as err:
            logger.exception(err)
            return self._redirect("Couldn't synchronize older versions", "warn")
Пример #6
0
    def test_version_assigned_with_versions(self):
        """ Test assign on a version which will assign a new entered value
            on the given version. Notice that the older versions will keep
            the initial value
        """
        current_id = IVersionControl(self.doc).versionId
        doc2 = create_version(self.doc)
        assert IVersionControl(self.doc).versionId == current_id

        assign_version(doc2, 'NEWVersion')
        assert IVersionControl(doc2).versionId != current_id
Пример #7
0
    def __call__(self, *args, **kwargs):
        if not IVersionControl:
            return self._redirect("eea.versions NOT installed", "warn")

        try:
            version = IVersionControl(self.context)
            return self.fixVersion(version.getVersionId())
        except Exception as err:
            logger.exception(err)
            return self._redirect("Couldn't synchronize older versions",
                                  "warn")
Пример #8
0
 def test_version_prefixed_first_version_id(self):
     """ Test the version id of a version contains the same version id
         as the object it derived from
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     link_version = create_version(link)
     assert IVersionControl(link_version).versionId == \
            IVersionControl(link).versionId
Пример #9
0
 def test_version_prefixed_second_id(self):
     """ Test the version id of a second object contains prefix-2 chars
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     link2_id = self.folder.invokeFactory("Link", 'l2')
     link2 = self.folder[link2_id]
     assert IVersionControl(link).versionId != \
            IVersionControl(link2).versionId
Пример #10
0
 def test_version_prefixed_title_rename_with_translations_migration(self):
     """ Test the version id of all versions changes to match
         new prefix after performing migration and when having translations
     """
     if not has_lingua_plone:
         assert True
         return
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     assert IVersionControl(link).versionId == 'LNK-1'
     vobjs.title = 'LINK'
     link2_id = self.folder.invokeFactory("Link", 'l2')
     link2 = self.folder[link2_id]
     trans_lang = str(link.languages()[-1])
     trans_lang2 = str(link.languages()[-2])
     trans = link.addTranslation(trans_lang)
     trans2 = link.addTranslation(trans_lang2)
     # after tool object title is modified new version id will
     # use the new title
     assert IVersionControl(link2).versionId == 'LINK-2'
     # previous versions keep their prefix and number
     assert IVersionControl(link).versionId == 'LNK-1'
     migration_view = link.restrictedTraverse('@@migrateVersions')
     migration_view(prefix='LINK')
     # assert that now all of the links use the new LINK prefix
     # after running the migration script
     assert IVersionControl(link).versionId == 'LINK-1'
     assert IVersionControl(link2).versionId == 'LINK-2'
     assert IVersionControl(trans).versionId == 'LINK-1-' + trans_lang
     assert IVersionControl(trans2).versionId == 'LINK-1-' + trans_lang2
Пример #11
0
def assign_version(context, new_version):
    """ Assign a specific version id to an object
    """

    # Verify if there are more objects under this version
    cat = getToolByName(context, 'portal_catalog')
    brains = cat.searchResults({'getversionid': new_version,
                                'show_inactive': True})
    if brains and not IVersionEnhanced.providedBy(context):
        alsoProvides(context, IVersionEnhanced)
    if len(brains) == 1:
        target_ob = brains[0].getObject()
        if not IVersionEnhanced.providedBy(target_ob):
            alsoProvides(target_ob, IVersionEnhanced)

    # Set new version ID
    verparent = IVersionControl(context)
    verparent.setVersionId(new_version)
    context.reindexObject()
Пример #12
0
 def test_version_prefixed_title_rename(self):
     """ Test the version id of a new object changes to match
         new prefix
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     assert IVersionControl(link).versionId == 'LNK-1'
     vobjs.title = 'LINK'
     link2_id = self.folder.invokeFactory("Link", 'l2')
     link2 = self.folder[link2_id]
     # after tool object title is modified new version id will
     # use the new title
     assert IVersionControl(link2).versionId == 'LINK-2'
     # previous versions keep their prefix and number
     assert IVersionControl(link).versionId == 'LNK-1'
Пример #13
0
 def test_version_prefixed_revoked(self):
     """ Test the version id set to prefix-2 chars after version revoke
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     revoke_version(link)
     assert IVersionControl(link).versionId == 'LNK-2'
Пример #14
0
def assign_version(context, new_version):
    """ Assign a specific version id to an object
    """

    # Verify if there are more objects under this version
    cat = getToolByName(context, 'portal_catalog')
    brains = cat.searchResults({
        'getVersionId': new_version,
        'show_inactive': True
    })
    if brains and not IVersionEnhanced.providedBy(context):
        alsoProvides(context, IVersionEnhanced)
    if len(brains) == 1:
        target_ob = brains[0].getObject()
        if not IVersionEnhanced.providedBy(target_ob):
            alsoProvides(target_ob, IVersionEnhanced)

    # Set new version ID
    verparent = IVersionControl(context)
    verparent.setVersionId(new_version)
    context.reindexObject(idxs=['getVersionId'])
Пример #15
0
 def test_version_prefixed_for_interface_portal_type(self):
     """ Test the version id of a first object contains prefix-1 chars
         if content type uses an interface not just a portal_type
     """
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_interface = \
         'Products.ATContentTypes.interfaces.link.IATLink'
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     assert IVersionControl(link).versionId == 'LNK-1'
Пример #16
0
 def test_version_prefixed_with_language(self):
     """ Test the version id of a version contains prefix plus language id
         if prefix_with_language is set on version object
     """
     if not has_lingua_plone:
         assert True
         return
     pvtool = getToolByName(self.portal, 'portal_eea_versions')
     vobjs = PortalType(id='LNK')
     vobjs.title = 'LNK'
     vobjs.search_type = 'Link'
     vobjs.prefix_with_language = True
     pvtool[vobjs.getId()] = vobjs
     link_id = self.folder.invokeFactory("Link", 'l1')
     link = self.folder[link_id]
     link_lang = link.getLanguage()
     assert IVersionControl(link).versionId == 'LNK-1-' + link_lang
Пример #17
0
    def __init__(self, context):
        """ Constructor
        """
        request = getattr(context, 'REQUEST', None)
        state = getMultiAdapter((context, request), name='plone_context_state')
        # #91514 fix for folders with a default view set, when creating a
        # version, we need the folder, not the page
        self.context = context
        if state.is_default_page():
            parent = aq_parent(context)
            if IVersionEnhanced.providedBy(parent):
                self.context = parent

        self.versionId = IVersionControl(self.context).versionId

        failsafe = lambda obj: "Unknown"
        self.state_title_getter = queryMultiAdapter(
            (self.context, request), name=u'getWorkflowStateTitle') or failsafe
Пример #18
0
    def test_version_prefixed_translated_content(self):
        """ Test the version id of a translation contains the same version id
            as the object it derived from plus language id
        """
        if not has_lingua_plone:
            assert True
            return
        pvtool = getToolByName(self.portal, 'portal_eea_versions')
        vobjs = PortalType(id='LNK')
        vobjs.title = 'LNK'
        vobjs.search_type = 'Link'
        pvtool[vobjs.getId()] = vobjs
        link_id = self.folder.invokeFactory("Link", 'l1')
        link = self.folder[link_id]
        ITranslationFactory(self.folder)

        trans_lang = str(link.languages()[-1])
        translation = link.addTranslation(trans_lang)
        assert IVersionControl(translation).versionId == 'LNK-1-' + trans_lang
Пример #19
0
 def test_version_revoked(self):
     """ Test revoke on a version which will assign a new random value
     """
     current_id = IVersionControl(self.doc).versionId
     revoke_version(self.doc)
     assert current_id != IVersionControl(self.doc).versionId
Пример #20
0
    def factory_Assessment(self):
        """factory"""
        type_name = 'Assessment'

        create = self.REQUEST.form.get('create_in_latest_spec')
        if create == 'true':
            latest = IGetVersions(self).latest_version()
            if latest.UID() != self.UID():
                return latest.factory_Assessment()

        #drop with error if no PolicyQuestions are created
        if not self.objectValues('PolicyQuestion'):
            raise ValueError("You need to create first a Policy Question")

        #create a version if we already have an Assessment
        assessments = self.objectValues(type_name)
        if assessments:
            #NOTE: we assume the latest object is the last one
            original = assessments[-1]
            ast = createVersion(original)
            return {
                'obj': ast,
                'subview': '@@edit_aggregated',
                'direct_edit': True
            }

        #we want to make this assessment a version of a previous assessment
        #if this Specification is already versioned, so we try get a versionId

        version_id = None
        spec_versions = IGetVersions(self).versions()
        for spec in spec_versions:
            asts = spec.objectValues("Assessment")
            if asts:
                original = asts[0]
                version_id = IVersionControl(original).versionId
                break

        #if there are no other assessments in this version set we look for
        #other IndicatorFactSheet objects with same indicator code to
        #get the versionId
        if not version_id:
            brains = []
            codes = self.get_codes()
            cat = getToolByName(self, 'portal_catalog')
            for code in codes[1::2]:
                brains = cat.searchResults({
                    'portal_type': 'IndicatorFactSheet',
                    'get_codes': code
                })
                if brains:
                    break
            if brains:
                version_id = IVersionControl(brains[0].getObject()).versionId

        #create a new Assessment from scratch
        #id = self.generateUniqueId(type_name)
        aid = make_id('assessment', self.objectIds())
        new_id = self.invokeFactory(type_name=type_name,
                                    id=aid,
                                    base_impl=True,
                                    title=self.translate(
                                        msgid='label-newly-created-type',
                                        domain='indicators',
                                        default="Newly created ${type_name}",
                                        mapping={'type_name': type_name},
                                    ))
        ast = self[new_id]

        if version_id:
            IVersionControl(ast).setVersionId(version_id)

        #create assessment parts for each policy question
        for pq in self.objectValues("PolicyQuestion"):
            aid = ast.invokeFactory(
                type_name="AssessmentPart",
                id=ast.generateUniqueId("AssessmentPart"),
            )
            ap = ast[aid]
            ap.setRelatedItems(pq)
            try:
                ap.reindexObject()
            except AttributeError:
                log("#ZZZ: this happens when executed from test")

        ast.reindexObject()
        notify(ObjectInitializedEvent(ast))
        return {
            'obj': ast,
            'subview': '@@edit_aggregated',
            'direct_edit': True
        }
Пример #21
0
def migrate_version(brains, vobj, count, **kwargs):
    """ migrate_versions given brains and prefix
    """
    increment = True
    no_versions = []
    prefix = str(vobj.title)
    parent = None
    datasets = kwargs.get('datasets')
    if datasets:
        site = getSite()
        parent = site.get('eea_permalink_objects')
        if not parent:
            parent_id = site.invokeFactory('Folder', 'eea_permalink_objects')
            parent = site[parent_id]

    for brain in brains:
        obj = brain.getObject()
        if not obj:
            continue
        adapter = queryAdapter(obj, IGetVersions)
        if not adapter:
            no_versions.append(obj.absolute_url())
            continue

        versions = adapter.versions()
        latest_version = versions[-1]
        for obj in versions:
            verparent = IVersionControl(obj)
            verparent_id = verparent.versionId
            if prefix not in verparent_id:
                version_id = "{0}-{1}".format(prefix, count)
                orig_id = version_id
                if vobj.prefix_with_language:
                    version_id = version_id + '-' + obj.getLanguage()
                if getattr(obj, 'getTranslations', None):
                    translations = obj.getTranslations()
                    if len(translations) > 1:
                        canonical = obj.getCanonical()
                        if vobj.prefix_with_language:
                            version_id = orig_id + '-' + \
                                canonical.getLanguage()
                        IVersionControl(canonical).setVersionId(version_id)
                        canonical.reindexObject(idxs=['getVersionId'])
                        for trans_tuple in translations.items():
                            translation = trans_tuple[1][0]
                            if translation != canonical:
                                version_id = orig_id + '-' + trans_tuple[0]
                                IVersionControl(translation).setVersionId(
                                    version_id)
                                translation.reindexObject(
                                    idxs=['getVersionId'])
                    else:
                        if datasets and obj is latest_version:
                            vid = IGetVersions(obj).versionId
                            zmi_addPermalinkMapping(parent, vid, version_id)
                        verparent.setVersionId(version_id)
                        obj.reindexObject(idxs=['getVersionId'])
                else:
                    verparent.setVersionId(version_id)
                    obj.reindexObject(idxs=['getVersionId'])
                increment = True
                logger.info('%s ==> %s --> %s', obj.absolute_url(1),
                            verparent_id, version_id)
            else:
                increment = False
        if increment:
            count += 1
            if count % 50 == 0:
                transaction.commit()
    logger.info("MIGRATION DONE")
    return count
Пример #22
0
def move_soer_content(context):
    """ Move relevant soer content under /soer
    """
    ctool = getToolByName(context, 'portal_catalog')

    soer_2015 = context.restrictedTraverse("/www/SITE/soer-2015")
    soer_2020 = context.restrictedTraverse("/www/SITE/soer-2020")
    soer = context.restrictedTraverse("/www/SITE/soer")

    paths = ["/www/SITE/soer"]
    vers_dict = {}
    for path in paths:
        brains = ctool.searchResults(path=path, Language="all")

        for brain in brains:
            obj = brain.getObject()
            try:
                control = IVersionControl(obj)
            except:
                continue
            version_id = control.getVersionId() or None

            if obj.id in ['soer-2015', 'soer-2020'
                          ] and obj.portal_type == 'Folder':
                logger.info('UPDATING FOLDER %s' % obj.absolute_url())
                vers_dict.update({obj.id.split('-')[-1]: version_id})
            else:
                vers_dict.update({obj.id: version_id})

    content.move(soer_2015, soer, '2015')
    content.move(soer_2020, soer, '2020')
    soer_2020_intro = context.restrictedTraverse("/www/SITE/soer/2020/intro")
    content.copy(soer_2020_intro, soer)

    # set default page
    soer.default_page = 'intro'
    soer._p_changed = True
    soer.reindexObject()

    paths = ["/www/SITE/soer"]
    for path in paths:
        brains = ctool.searchResults(path=path, Language="all")

        for brain in brains:
            obj = brain.getObject()
            try:
                control = IVersionControl(obj)
            except:
                continue

            version_id = control.getVersionId() or None
            if vers_dict.get(obj.id, None):
                if vers_dict.get(obj.id, None) == version_id:
                    logger.info('GOOD OBJECT %s' % obj.absolute_url())
                else:
                    logger.info('BAD OBJECT %s' % obj.absolute_url())
                    control.setVersionId(vers_dict.get(obj.id))
                    obj._p_changed = True
                    obj.reindexObject()
                    transaction.commit()

    logger.info('Finished moving soer content ... DONE')
    return 'Done moving'
Пример #23
0
def revoke_version(context):
    """ Assigns a new random id to context, make it split from it version group
    """
    IVersionControl(context).setVersionId(new_version_id(context))
Пример #24
0
 def __call__(self):
     if not IVersionEnhanced.providedBy(self.context):
         return False
     return IVersionControl(self.context).can_version()
Пример #25
0
 def test_version_random_id(self):
     """ Test the random version id of the object is 10 chars
     """
     new_version = create_version(self.doc)
     assert len(IVersionControl(new_version).versionId) == 10
Пример #26
0
def migrate_version(brains, vobj, count, **kwargs):
    """ migrate_versions given brains and prefix
    """
    increment = True
    no_versions = []
    prefix = str(vobj.title)
    parent = None
    datasets = kwargs.get('datasets')
    if datasets:
        site = getSite()
        parent = site.get('eea_permalink_objects')
        if not parent:
            parent_id = site.invokeFactory('Folder', 'eea_permalink_objects')
            parent = site[parent_id]

    for brain in brains:
        obj = brain.getObject()
        if not obj:
            continue
        adapter = queryAdapter(obj, IGetVersions)
        if not adapter:
            no_versions.append(obj.absolute_url())
            continue

        versions = adapter.versions()
        latest_version = versions[-1]
        for obj in versions:
            verparent = IVersionControl(obj)
            verparent_id = verparent.versionId
            if prefix not in verparent_id:
                version_id = "{0}-{1}".format(prefix, count)
                orig_id = version_id
                if vobj.prefix_with_language:
                    version_id = version_id + '-' + obj.getLanguage()
                if getattr(obj, 'getTranslations', None):
                    translations = obj.getTranslations()
                    if len(translations) > 1:
                        canonical = obj.getCanonical()
                        if vobj.prefix_with_language:
                            version_id = orig_id + '-' + canonical.getLanguage()
                        IVersionControl(canonical).setVersionId(version_id)
                        canonical.reindexObject(idxs=['getVersionId'])
                        for trans_tuple in translations.items():
                            translation = trans_tuple[1][0]
                            if translation != canonical:
                                version_id = orig_id + '-' + trans_tuple[0]
                                IVersionControl(translation).setVersionId(
                                    version_id)
                                translation.reindexObject(idxs=['getVersionId'])
                    else:
                        if datasets and obj is latest_version:
                            vid = IGetVersions(obj).versionId
                            zmi_addPermalinkMapping(parent, vid, version_id)
                        verparent.setVersionId(version_id)
                        obj.reindexObject(idxs=['getVersionId'])
                else:
                    verparent.setVersionId(version_id)
                    obj.reindexObject(idxs=['getVersionId'])
                increment = True
                logger.info('%s ==> %s --> %s',
                    obj.absolute_url(1), verparent_id, version_id)
            else:
                increment = False
        if increment:
            count += 1
            if count % 50 == 0:
                transaction.commit()
    logger.info("MIGRATION DONE")
    return count
Пример #27
0
 def test_version_assigned(self):
     """ Test assign on a version which will assign a new entered value
     """
     assign_version(self.doc, 'NEWVersion')
     assert IVersionControl(self.doc).versionId == 'NEWVersion'