Exemple #1
0
    def __iter__(self):
        portal = api.portal.get()
        try:
            pwtool = api.portal.get_tool("portal_placeful_workflow")
        except InvalidParameterError:
            pwtool = None

        for item in self.previous:
            if (pwtool and self.condition(item)
                    and '_workflow_policy_in' in item):
                ob = traverse(portal, item['_path'])

                # Init placeful workflow policy config when required
                if pwtool.getWorkflowPolicyConfig(ob) is None:
                    local_tool = ob.manage_addProduct["CMFPlacefulWorkflow"]
                    local_tool.manage_addWorkflowPolicyConfig()

                # Set the policy
                config = pwtool.getWorkflowPolicyConfig(ob)
                config.setPolicyIn(item.get('_workflow_policy_in', ''))
                config.setPolicyBelow(item.get('_workflow_policy_below', ''))

                # Update security
                updateRoleMappings(ob)
            yield item
    def __iter__(self):
        portal = api.portal.get()
        try:
            pwtool = api.portal.get_tool("portal_placeful_workflow")
        except InvalidParameterError:
            pwtool = None

        for item in self.previous:
            if (pwtool and self.condition(item)
                    and '_workflow_policy_in' in item):
                ob = traverse(portal, item['_path'])

                # Init placeful workflow policy config when required
                if pwtool.getWorkflowPolicyConfig(ob) is None:
                    local_tool = ob.manage_addProduct["CMFPlacefulWorkflow"]
                    local_tool.manage_addWorkflowPolicyConfig()

                # Set the policy
                config = pwtool.getWorkflowPolicyConfig(ob)
                config.setPolicyIn(item.get('_workflow_policy_in', ''))
                config.setPolicyBelow(item.get('_workflow_policy_below', ''))

                # Update security
                updateRoleMappings(ob)
            yield item
Exemple #3
0
    def __iter__(self):
        portal = api.portal.get()
        for item in self.previous:
            if self.condition(item):
                try:
                    context = traverse(portal,
                                       '/'.join(item['_path'].split('/')[:-1]))
                except KeyError:
                    yield item
                    continue

                if not context:
                    yield item
                    continue

                if all([
                        context.portal_type == 'Collection',
                        item['_type'] == 'Collection'
                ]):
                    path_parts = item['_path'].split('/')
                    new_path = ('/'.join(path_parts[:-2]) + '/' +
                                path_parts[-2] + '-' + path_parts[-1])
                    try:
                        item.replace_header('_path', new_path)
                    # in the case we have dict instead of Message
                    except AttributeError:
                        item['_path'] = new_path

            yield item
    def __iter__(self):
        portal = api.portal.get()
        for item in self.previous:
            if self.condition(item):
                try:
                    context = traverse(portal, 
                        '/'.join(item['_path'].split('/')[:-1]))
                except KeyError:
                    yield item
                    continue

                if not context:
                    yield item
                    continue

                if all([context.portal_type == 'Collection', 
                        item['_type'] == 'Collection']):
                    path_parts = item['_path'].split('/')
                    new_path = ('/'.join(path_parts[:-2]) + '/' + 
                                path_parts[-2] + '-' + path_parts[-1])
                    try:
                        item.replace_header('_path', new_path)
                    # in the case we have dict instead of Message
                    except AttributeError:
                        item['_path'] = new_path
                 
            yield item
def folders(item, path_key_matcher, new_path_key, new_type_key, folder_type,
            cache, seen):
    keys = item.keys()
    path_key = path_key_matcher(*keys)[0]

    if not path_key:  # not enough info
        return

    new_path_key = new_path_key or path_key

    path = item[path_key]
    elements = path.strip('/').rsplit('/', 1)
    container, id_ = (len(elements) == 1 and ('', elements[0]) or elements)

    # This may be a new container
    if container not in seen:

        container_path_items = list(pathsplit(container))
        if container_path_items:

            checked_elements = []

            # Check each possible parent folder
            obj = api.portal.get()
            for element in container_path_items:
                checked_elements.append(element)
                current_path = '/'.join(checked_elements)

                if current_path and current_path not in seen:

                    if element and traverse(obj, element) is None:
                        # We don't have this path - yield to create
                        # a skeleton folder
                        yield {
                            new_path_key: '/' + current_path,
                            new_type_key: folder_type
                        }
                    if cache:
                        seen.add(current_path)

                obj = traverse(obj, element)

    if cache:
        seen.add('{0:s}/{1:s}'.format(
            container,
            id_,
        ))
Exemple #6
0
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             ob.__ac_local_roles__ = item['_local_roles']
             ob.__ac_local_roles_block__ = item['_block_inherit']
         yield item
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item) and isinstance(item, Message):
             ob = traverse(portal, item['_path'])
             if ob is not portal:
                 demarshall(ob, item)
         yield item
Exemple #8
0
 def __iter__(self):
     portal = api.portal.get()
     indexes = api.portal.get_tool('portal_catalog').indexes()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             ob.reindexObject(idxs=indexes)
             ob.reindexObjectSecurity()
         yield item
 def __iter__(self):
     portal = api.portal.get()
     wftool = getToolByName(portal, 'portal_workflow')
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             ob.workflow_history = item['_workflow_history']
             for wf in wftool.getWorkflowsFor(ob):
                 wf.updateRoleMappingsFor(ob)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     wftool = getToolByName(portal, 'portal_workflow')
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             ob.workflow_history = item['_workflow_history']
             for wf in wftool.getWorkflowsFor(ob):
                 wf.updateRoleMappingsFor(ob)
         yield item
def folders(item, path_key_matcher, new_path_key, new_type_key, folder_type,
            cache, seen):
    keys = item.keys()
    path_key = path_key_matcher(*keys)[0]

    if not path_key:  # not enough info
        return

    new_path_key = new_path_key or path_key

    path = item[path_key]
    elements = path.strip('/').rsplit('/', 1)
    container, id_ = (len(elements) == 1
                      and ('', elements[0]) or elements)

    # This may be a new container
    if container not in seen:

        container_path_items = list(pathsplit(container))
        if container_path_items:

            checked_elements = []

            # Check each possible parent folder
            obj = api.portal.get()
            for element in container_path_items:
                checked_elements.append(element)
                current_path = '/'.join(checked_elements)

                if current_path and current_path not in seen:

                    if element and traverse(obj, element) is None:
                        # We don't have this path - yield to create
                        # a skeleton folder
                        yield {new_path_key: '/' + current_path,
                               new_type_key: folder_type}
                    if cache:
                        seen.add(current_path)

                obj = traverse(obj, element)

    if cache:
        seen.add('{0:s}/{1:s}'.format(container, id_, ))
Exemple #12
0
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             uuid_ = IUUID(ob, None)
             if uuid is not None:
                 item['_uuid'] = uuid_
             elif hasattr(Acquisition.aq_base(ob), 'UID'):
                 item['_uuid'] = Acquisition.aq_base(ob).UID()
             if not item.get('_uuid'):
                 item['_uuid'] = str(uuid.uuid4()).replace('-', '')
         yield item
def constructInstance(context,
                      item,
                      type_key_matcher,
                      path_key_matcher,
                      purge=False):

    keys = item.keys()
    type_key = type_key_matcher(*keys)[0]
    path_key = path_key_matcher(*keys)[0]

    if not (type_key and path_key):  # not enough info
        return

    type_, path = item[type_key], str(item[path_key])
    portal_path = '/'.join(api.portal.get().getPhysicalPath())

    if path == '/' or path.rstrip(posixpath.sep) == portal_path:
        container, id_ = posixpath.split(portal_path)
        obj = api.portal.get()
    else:
        container, id_ = posixpath.split(path.strip(posixpath.sep))
        container = posixpath.sep + container  # abs path
        obj = traverse(context, posixpath.join(container, id_))

    if obj is None:
        parent = traverse(context, container)
        if parent is None and container == portal_path:
            parent = api.portal.get()
        assert parent is not None, ('Container %s does not exist for item %s' %
                                    (container, path))
        obj = api.content.create(parent, type=type_, id=id_)
        cleanup(obj)  # always purge new objects

    item[path_key] = '/'.join(obj.getPhysicalPath())[len(portal_path):]

    if purge and obj.objectIds():
        cleanup(obj)

    return obj
Exemple #14
0
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             if 'modification_date' in item:
                 ob.setModificationDate(item['modification_date'])
             if 'creation_date' in item:
                 try:
                     ob.setCreationDate(item['creation_date'])
                 except AttributeError:
                     # dexterity content does not have setCreationDate
                     ob.creation_date = item['creation_date']
         yield item
def constructInstance(item, type_key_matcher, path_key_matcher,
                      required, empty=True):
    portal = api.portal.get()
    types_tool = api.portal.get_tool('portal_types')

    keys = item.keys()
    type_key = type_key_matcher(*keys)[0]
    path_key = path_key_matcher(*keys)[0]

    if not (type_key and path_key):  # not enough info
        return

    type_, path = item[type_key], item[path_key]

    fti = types_tool.getTypeInfo(type_)
    if fti is None:  # not an existing type
        return

    path = path.encode('ASCII')
    container, id_ = posixpath.split(path.strip('/'))

    if not id_:  # site root should exist
        return

    context = traverse(portal, container, None)
    if context is None:
        error = 'Container %s does not exist for item %s' % (
            container, path)
        if required:
            raise KeyError(error)
        logger.warn(error)
        return

    # noinspection PyUnresolvedeferences
    exists = getattr(Acquisition.aq_base(context), id_, None)
    if getattr(exists, 'id', None) == id_:
        return

    obj = _constructInstance(fti, context, id_)

    # For CMF <= 2.1 (aka Plone 3)
    if hasattr(fti, '_finishConstruction'):
        # noinspection PyProtectedMember
        obj = fti._finishConstruction(obj)

    if obj.getId() != id_:
        item[path_key] = posixpath.join(container, obj.getId())

    if empty and obj.objectIds():
        cleanup(obj)
Exemple #16
0
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             props = item['_properties']
             for prop in props:
                 key, value, type_ = prop
                 if key == 'title':
                     continue
                 if key in ob.propertyIds():
                     ob.manage_changeProperties(**{key: value})
                     # what to do if type is different?
                 else:
                     ob.manage_addProperty(key, value, type_)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item):
             ob = traverse(portal, item['_path'])
             props = item['_properties']
             for prop in props:
                 key, value, type_ = prop
                 if key == 'title':
                     continue
                 if key in ob.propertyIds():
                     ob.manage_changeProperties(**{key: value})
                     # what to do if type is different?
                 else:
                     ob.manage_addProperty(key, value, type_)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     key = self.options.get('key', '_gopip')
     for item in self.previous:
         position = item.get(key)
         if self.condition(item) and position is not None:
             try:
                 ob = traverse(portal, item['_path'])
             except KeyError:
                 pass
             if ob:
                 id_ = ob.getId()
                 parent = Acquisition.aq_parent(ob)
                 if hasattr(Acquisition.aq_base(parent),
                            'moveObjectToPosition'):
                     parent.moveObjectToPosition(
                         id_, position, suppress_events=False)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     key = self.options.get('key', '_type')
     folder_type = self.options.get('folder-type', 'Folder')
     for item in self.previous:
         if self.condition(item):
             try:
                 ob = traverse(portal, item['_path'])
                 portal_type = item[key]
             except KeyError:
                 pass
             else:
                 # Skip folder_type, because Folders-blueprint
                 # would cause all folderish-types to be b0rked
                 if ob is not portal and portal_type != folder_type:
                     ob.portal_type = portal_type
                     ensure_correct_class(ob)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     key = self.options.get('key', '_type')
     folder_type = self.options.get('folder-type', 'Folder')
     for item in self.previous:
         if self.condition(item):
             try:
                 ob = traverse(portal, item['_path'])
                 portal_type = item[key]
             except KeyError:
                 pass
             else:
                 # Skip folder_type, because Folders-blueprint
                 # would cause all folderish-types to be b0rked
                 if ob is not portal and portal_type != folder_type:
                     ob.portal_type = portal_type
                     ensure_correct_class(ob)
         yield item
 def __iter__(self):
     portal = api.portal.get()
     key = self.options.get('key', '_gopip')
     for item in self.previous:
         position = item.get(key)
         if self.condition(item) and position is not None:
             try:
                 ob = traverse(portal, item['_path'])
             except KeyError:
                 pass
             if ob:
                 id_ = ob.getId()
                 parent = Acquisition.aq_parent(ob)
                 if hasattr(Acquisition.aq_base(parent),
                            'moveObjectToPosition'):
                     parent.moveObjectToPosition(id_,
                                                 position,
                                                 suppress_events=False)
         yield item
Exemple #22
0
def patch_set_portlets_xml(xml, prefix=None):
    portal = api.portal.get()
    portal_path = '/'.join(portal.getPhysicalPath())
    if prefix:
        try:
            prefix_target = traverse(portal, prefix)
            prefix = '/'.join(prefix_target.getPhysicalPath())
        except (AttributeError, KeyError):
            prefix = None

    if prefix is not None and prefix.startswith(portal_path):
        xml = xml.replace(' key="/',
                          ' key="' + prefix[len(portal_path):] + '/')

    # This must be a bug in p.a.portlets where it exports assignments, which it
    # cannot import, empty tag cannot be interpreted into an integer
    xml = xml.replace('<property name="limit"/>',
                      '<property name="limit">0</property>')

    return xml
Exemple #23
0
 def __iter__(self):
     portal = api.portal.get()
     for item in self.previous:
         if self.condition(item) and '_uuid' in item:
             set_uuid(traverse(portal, item['_path']), item['_uuid'])
         yield item