def test_textblock_with_workflow_does_not_belong_to_parent(self):
     wftool = getToolByName(self.portal, 'portal_workflow')
     wftool.setChainForPortalTypes(['ftw.simplelayout.TextBlock'],
                                   'plone_workflow')
     page = create(Builder('sl content page'))
     block = create(Builder('sl textblock').within(page))
     self.assertFalse(belongs_to_parent(block))
def handle_remove_event(context, event):
    """
    Before a object is remvoed the event handler crates a remove job.
    """
    # the event is notified for every subobject, but we only want to check
    # the top object which the users tries to delete
    if context is not event.object:
        return

    if belongs_to_parent(context):
        # Do not delete objects belonging to the parent,
        # they are deleted when the parent is published.
        return

    # Find the workflow object by walking up. We may be deleting a file
    # within a file-block within a page, where file and file-block have no
    # workflow and we check the page workflow.
    obj = context
    state = None

    while not IPloneSiteRoot.providedBy(obj):
        state = getMultiAdapter((obj, context.REQUEST), IPublisherContextState)
        if state.has_workflow():
            break
        else:
            obj = aq_parent(aq_inner(obj))

    if not state.has_workflow() or not state.has_publisher_config():
        # plone site reached without finding a workflow, therefore
        # the object was never published.
        return

    context.restrictedTraverse('@@publisher.delete')(no_response=True)
def add_move_job(obj, event):
    """
    This event handles move and rename jobs
    """

    if os.environ.get('disable-publisher-for-testing', None):
        return

    if belongs_to_parent(obj):
        # We are moving a content which is considered part of the parent.
        # A move of this content should not be published instantly, but when
        # the parent is published.
        return

    if obj == event.object:
        # do nohting, if we are in portal_factory or the item is just created
        if not event.oldName:
            return
        url_endswith = event.object.REQUEST.get('ACTUAL_URL') \
            .split('/')[-1:][0]
        # also include manage_pasteObjects for ZMI support
        if url_endswith not in [
                'folder_rename_form', 'folder_paste', 'manage_pasteObjects',
                'object_rename', '@@fc-rename', 'object_paste'
        ]:
            return
        # set event info on
        move_view = queryMultiAdapter((obj, obj.REQUEST),
                                      name="publisher.move")
        move_view(event, no_response=True)
 def test_file_with_workflow_in_listingblock_does_not_belong_to_parent(
         self):
     wftool = getToolByName(self.portal, 'portal_workflow')
     wftool.setChainForPortalTypes(['File'], 'plone_workflow')
     page = create(Builder('sl content page'))
     listingblock = create(Builder('sl listingblock').within(page))
     document = create(Builder('file').within(listingblock))
     self.assertFalse(belongs_to_parent(document))
 def test_file_in_listingblock_belongs_to_parent(self):
     page = create(Builder('sl content page'))
     listingblock = create(Builder('sl listingblock').within(page))
     document = create(Builder('file').within(listingblock))
     self.assertTrue(belongs_to_parent(document))
 def test_listingblock_belongs_to_parent(self):
     page = create(Builder('sl content page'))
     block = create(Builder('sl listingblock').within(page))
     self.assertTrue(belongs_to_parent(block))
 def test_content_page_does_not_belong_to_parent(self):
     page = create(Builder('sl content page').titled(u'The Page'))
     self.assertFalse(belongs_to_parent(page))
 def test_folder_does_not_belong_to_parent(self):
     self.set_workflow(Folder=None)
     self.assertFalse(belongs_to_parent(create(Builder('folder'))))
 def test_plone_site_does_not_belong_to_parent(self):
     self.assertFalse(belongs_to_parent(self.portal))