def getRootPath(context, currentFolderOnly, topLevel, root):
    """Helper function to calculate the real root path."""
    context = aq_inner(context)
    if currentFolderOnly:
        folderish = getattr(aq_base(context), 'isPrincipiaFolderish', False)
        folderish &= not INonStructuralFolder.providedBy(context)
        parent = aq_parent(context)

        is_default_page = False
        browser_default = IBrowserDefault(parent, None)
        if browser_default is not None:
            browser_default_page = browser_default.getDefaultPage()
            is_default_page = (browser_default_page == context.getId())

        if not folderish or is_default_page:
            return '/'.join(parent.getPhysicalPath())
        else:
            return '/'.join(context.getPhysicalPath())

    rootPath = getNavigationRoot(context, relativeRoot=root)

    # Adjust for topLevel
    if topLevel > 0:
        contextPath = '/'.join(context.getPhysicalPath())
        if not contextPath.startswith(rootPath):
            return None
        contextSubPathElements = contextPath[len(rootPath) + 1:]
        if not contextSubPathElements:
            return None
        contextSubPathElements = contextSubPathElements.split('/')
        if len(contextSubPathElements) < topLevel:
            return None
        rootPath = '/'.join([rootPath] + contextSubPathElements[:topLevel])
    return rootPath
def getRootPath(context, currentFolderOnly, topLevel, root):
    """Helper function to calculate the real root path
    """
    context = aq_inner(context)
    if currentFolderOnly:
        folderish = getattr(aq_base(context), 'isPrincipiaFolderish', False) and not INonStructuralFolder.providedBy(context)
        parent = aq_parent(context)
        
        is_default_page = False
        browser_default = IBrowserDefault(parent, None)
        if browser_default is not None:
            is_default_page = (browser_default.getDefaultPage() == context.getId())
        
        if not folderish or is_default_page:
            return '/'.join(parent.getPhysicalPath())
        else:
            return '/'.join(context.getPhysicalPath())

    rootPath = getNavigationRoot(context, relativeRoot=root)

    # Adjust for topLevel
    if topLevel > 0:
        contextPath = '/'.join(context.getPhysicalPath())
        if not contextPath.startswith(rootPath):
            return None
        contextSubPathElements = contextPath[len(rootPath)+1:]
        if contextSubPathElements:
            contextSubPathElements = contextSubPathElements.split('/')
            if len(contextSubPathElements) < topLevel:
                return None
            rootPath = rootPath + '/' + '/'.join(contextSubPathElements[:topLevel])
        else:
            return None
    
    return rootPath
 def getIsPrincipiaFolderish(self):
     refObject = self.getAlias()
     if refObject is not None:
         return (refObject.isPrincipiaFolderish
                 and not INonStructuralFolder.providedBy(refObject))
     else:
         return False
Beispiel #4
0
 def is_structural_folder(self):
     folderish = self.is_folderish()
     context = aq_inner(self.context)
     if not folderish:
         return False
     elif INonStructuralFolder.providedBy(context):
         return False
     else:
         return folderish
Beispiel #5
0
 def is_structural_folder(self):
     folderish = self.is_folderish()
     context = aq_inner(self.context)
     if not folderish:
         return False
     elif INonStructuralFolder.providedBy(context):
         return False
     else:
         return folderish
Beispiel #6
0
    def isStructuralFolder(self, obj):
        """Checks if a given object is a "structural folder".

        That is, a folderish item which does not explicitly implement
        INonStructuralFolder to declare that it doesn't wish to be treated
        as a folder by the navtree, the tab generation etc.
        """
        return (obj.isPrincipiaFolderish
                and not INonStructuralFolder.providedBy(obj))
Beispiel #7
0
def enabled(self):
    
        context = aq_inner(self.context)

        # Fetch discussion registry
#        registry = queryUtility(IRegistry)
#        settings = registry.forInterface(IDiscussionSettings, check=False)
#
#        # Check if discussion is allowed globally
#        if not settings.globally_enabled:
#            return False

        # Always return False if object is a folder
        if (Iquestion.providedBy(context)):return True
        if (IFolderish.providedBy(context) and
            not INonStructuralFolder.providedBy(context)):
            return False

        def traverse_parents(context):
            # Run through the aq_chain of obj and check if discussion is
            # enabled in a parent folder.
            for obj in aq_chain(context):
                if not IPloneSiteRoot.providedBy(obj):
                    if (IFolderish.providedBy(obj) and
                        not INonStructuralFolder.providedBy(obj)):
                        flag = getattr(obj, 'allow_discussion', None)
                        if flag is not None:
                            return flag
            return None

        # If discussion is disabled for the object, bail out
        obj_flag = getattr(aq_base(context), 'allow_discussion', None)
        if obj_flag is False:
            return False

        # Check if traversal returned a folder with discussion_allowed set
        # to True or False.
        folder_allow_discussion = traverse_parents(context)

        if folder_allow_discussion:
            if not getattr(self, 'allow_discussion', None):
                return True
        else:
            if obj_flag:
                return True

        # Check if discussion is allowed on the content type
        portal_types = getToolByName(self, 'portal_types')
        document_fti = getattr(portal_types, context.portal_type)
        if not document_fti.getProperty('allow_discussion'):
            # If discussion is not allowed on the content type,
            # check if 'allow discussion' is overridden on the content object.
            if not obj_flag:
                return False

        return True
Beispiel #8
0
def is_folderish(obj):
    """Should this item be treated as a folder?

    Checks isPrincipiaFolderish, as well as the INonStructuralFolder
    interfaces.
    """
    # If the object explicitly states it doesn't want to be treated as a
    # structural folder, don't argue with it.
    folderish = bool(getattr(aq_base(obj), 'isPrincipiaFolderish', False))
    return folderish and not INonStructuralFolder.providedBy(obj)
 def traverse_parents(context):
     # Run through the aq_chain of obj and check if discussion is
     # enabled in a parent folder.
     for obj in aq_chain(context):
         if not IPloneSiteRoot.providedBy(obj):
             if IFolderish.providedBy(obj) and not INonStructuralFolder.providedBy(obj):
                 flag = getattr(obj, "allow_discussion", None)
                 if flag is not None:
                     return flag
     return None
Beispiel #10
0
 def isStructuralFolder(self, instance):
     context = instance
     folderish = bool(getattr(aq_base(context), 'isPrincipiaFolderish',
                              False))
     if not folderish:
         return False
     elif INonStructuralFolder.providedBy(context):
         return False
     else:
         return folderish
Beispiel #11
0
 def isStructuralFolder(self, instance):
     context = instance
     folderish = bool(
         getattr(aq_base(context), 'isPrincipiaFolderish', False))
     if not folderish:
         return False
     elif INonStructuralFolder.providedBy(context):
         return False
     else:
         return folderish
Beispiel #12
0
def is_folderish(obj):
    """Should this item be treated as a folder?

    Checks isPrincipiaFolderish, as well as the INonStructuralFolder
    interfaces.
    """
    # If the object explicitly states it doesn't want to be treated as a
    # structural folder, don't argue with it.
    folderish = bool(getattr(aq_base(obj), 'isPrincipiaFolderish', False))
    return folderish and not INonStructuralFolder.providedBy(obj)
Beispiel #13
0
 def enabled(self):
     uid = self._uid
     if uid == CONTENT_UID:
         obj = self._pobj
     else:
         obj = self._query_object(uid)
     if obj is not None and obj.isPrincipiaFolderish:
         if not INonStructuralFolder.providedBy(obj):
             return True
     return False
Beispiel #14
0
    def isStructuralFolder(self, obj):
        """Checks if a given object is a "structural folder".

        That is, a folderish item which does not explicitly implement
        INonStructuralFolder to declare that it doesn't wish to be treated
        as a folder by the navtree, the tab generation etc.
        """
        return (
            obj.isPrincipiaFolderish
            and not INonStructuralFolder.providedBy(obj)
        )
Beispiel #15
0
 def traverse_parents(context):
     # Run through the aq_chain of obj and check if discussion is
     # enabled in a parent folder.
     for obj in aq_chain(context):
         if not IPloneSiteRoot.providedBy(obj):
             if (IFolderish.providedBy(obj)
                     and not INonStructuralFolder.providedBy(obj)):
                 flag = getattr(obj, 'allow_discussion', None)
                 if flag is not None:
                     return flag
     return None
Beispiel #16
0
def is_folderish(obj, **kwargs):
    """Should this item be treated as a folder?

    Checks isPrincipiaFolderish, as well as the INonStructuralFolder
    interfaces.

      >>> from Products.CMFPlone.CatalogTool import is_folderish
      >>> from Products.CMFPlone.interfaces import INonStructuralFolder
      >>> from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder as z2INonStructuralFolder
      >>> from zope.interface import directlyProvidedBy, directlyProvides

    A Folder is folderish generally::
      >>> is_folderish(self.folder)
      True

    But if we make it an INonStructuralFolder it is not::
      >>> base_implements = directlyProvidedBy(self.folder)
      >>> directlyProvides(self.folder, INonStructuralFolder, directlyProvidedBy(self.folder))
      >>> is_folderish(self.folder)
      False
      
    Now we revert our interface change and apply the z2 no-folderish interface::
      >>> directlyProvides(self.folder, base_implements)
      >>> is_folderish(self.folder)
      True
      >>> z2base_implements = self.folder.__implements__
      >>> self.folder.__implements__ = z2base_implements + (z2INonStructuralFolder,)
      >>> is_folderish(self.folder)
      False

    We again revert the interface change and check to make sure that
    PrincipiaFolderish is respected::
      >>> self.folder.__implements__ = z2base_implements
      >>> is_folderish(self.folder)
      True
      >>> self.folder.isPrincipiaFolderish = False
      >>> is_folderish(self.folder)
      False

    """
    # If the object explicitly states it doesn't want to be treated as a
    # structural folder, don't argue with it.
    folderish = bool(getattr(aq_base(obj), 'isPrincipiaFolderish', False))
    if not folderish:
        return False
    elif INonStructuralFolder.providedBy(obj):
        return False
    elif z2INonStructuralFolder.isImplementedBy(obj):
        # BBB: for z2 interface compat
        return False
    else:
        return folderish
Beispiel #17
0
    def getPortlets(self, context, position="columnOne"):
        mtool = getToolByName(context, "portal_membership")
        portlets = []
        ids = []

        obj = context

        if not obj.isPrincipiaFolderish:
            obj = aq_parent(aq_inner(obj))

        current = obj
        allowedTypes = self.getPortletMetatypes()
        while mtool.checkPermission("View", current):
            folderObjects = current.getFolderContents(full_objects=True, contentFilter={"portal_type": allowedTypes})
            for o in folderObjects:
                # make sure o is of a proper portal_type
                # sometimes the filter doesn't work like with PloneLocalFolderNG
                if o.portal_type in allowedTypes:
                    ids.append(o.id)

                    if current is obj:
                        goOn = True
                    elif o.getShowinsubfolders():
                        goOn = True
                    elif hasINonStructuralFolder:
                        if INonStructuralFolder.providedBy(obj) and current is aq_parent(aq_inner(obj)):
                            goOn = True
                        else:
                            goOn = False
                    else:
                        goOn = False

                    if goOn:
                        if o.getPosition() == position:
                            if mtool.checkPermission("View", o):
                                if not o.id in [p.id for p in portlets]:
                                    portlets.append(o)

            if current == obj.portal_url.getPortalObject():
                break
            else:
                # get portlets on higher levels who have showinsubfolders set.
                current = aq_parent(aq_inner(current))

        # now filter out all objects that have getShow()=0
        portlets = [p for p in portlets if p.getShow()]

        return portlets
    def isStructuralFolder(self, obj):
        """Checks if a given object is a "structural folder".

        That is, a folderish item which does not explicitly implement
        INonStructuralFolder to declare that it doesn't wish to be treated
        as a folder by the navtree, the tab generation etc.

        >>> ptool = self.portal.plone_utils

        >>> ptool.isStructuralFolder(self.folder)
        True
        """
        if not obj.isPrincipiaFolderish:
            return False
        elif INonStructuralFolder.providedBy(obj):
            return False
        else:
            return True
Beispiel #19
0
    def isStructuralFolder(self, obj):
        """Checks if a given object is a "structural folder".

        That is, a folderish item which does not explicitly implement
        INonStructuralFolder to declare that it doesn't wish to be treated
        as a folder by the navtree, the tab generation etc.

        >>> ptool = self.portal.plone_utils

        >>> ptool.isStructuralFolder(self.folder)
        True
        """
        if not obj.isPrincipiaFolderish:
            return False
        elif INonStructuralFolder.providedBy(obj):
            return False
        else:
            return True
Beispiel #20
0
def getRootPath(context, currentFolderOnly, topLevel, root_path):
    """Helper function to calculate the real root path"""
    context = aq_inner(context)
    if currentFolderOnly:
        folderish = getattr(
            aq_base(context), "isPrincipiaFolderish",
            False) and not INonStructuralFolder.providedBy(context)
        parent = aq_parent(context)

        is_default_page = False
        browser_default = IBrowserDefault(parent, None)
        if browser_default is not None:
            is_default_page = browser_default.getDefaultPage(
            ) == context.getId()

        if not folderish or is_default_page:
            return "/".join(parent.getPhysicalPath())
        else:
            return "/".join(context.getPhysicalPath())

    # root = uuidToObject(root)
    root = get_root(context, root_path)

    if root is not None:
        rootPath = "/".join(root.getPhysicalPath())
    else:
        rootPath = getNavigationRoot(context)

    # Adjust for topLevel
    if topLevel > 0:
        contextPath = "/".join(context.getPhysicalPath())
        if not contextPath.startswith(rootPath):
            return
        contextSubPathElements = contextPath[len(rootPath) + 1:]
        if contextSubPathElements:
            contextSubPathElements = contextSubPathElements.split("/")
            if len(contextSubPathElements) < topLevel:
                return
            rootPath = rootPath + "/" + "/".join(
                contextSubPathElements[:topLevel])
        else:
            return

    return rootPath
def is_folderish(obj):
    """Should this item be treated as a folder?

    Checks isPrincipiaFolderish, as well as the INonStructuralFolder
    interfaces.

      >>> from Products.CMFPlone.CatalogTool import is_folderish
      >>> from Products.CMFPlone.interfaces import INonStructuralFolder
      >>> from zope.interface import directlyProvidedBy, directlyProvides

    A Folder is folderish generally::
      >>> is_folderish(self.folder)
      True

    But if we make it an INonStructuralFolder it is not::
      >>> base_implements = directlyProvidedBy(self.folder)
      >>> directlyProvides(self.folder, INonStructuralFolder,
      ...     directlyProvidedBy(self.folder))
      >>> is_folderish(self.folder)
      False

    Now we revert our interface change and check to make sure that
    PrincipiaFolderish is respected::
      >>> directlyProvides(self.folder, base_implements)
      >>> is_folderish(self.folder)
      True
      >>> self.folder.isPrincipiaFolderish = False
      >>> is_folderish(self.folder)
      False

    """
    # If the object explicitly states it doesn't want to be treated as a
    # structural folder, don't argue with it.
    folderish = bool(getattr(aq_base(obj), 'isPrincipiaFolderish', False))
    if not folderish:
        return False
    elif INonStructuralFolder.providedBy(obj):
        return False
    else:
        return folderish
    def _enabled_for_archetypes(self):
        """ Returns True if discussion is enabled for this conversation.

        This method checks five different settings in order to figure out if
        discussion is enable on a specific content object:

        1) Check if discussion is enabled globally in the plone.app.discussion
           registry/control panel.

        2) If the current content object is a folder, always return
           False, since we don't allow comments on a folder. This
           setting is used to allow/ disallow comments for all content
           objects inside a folder, not for the folder itself.

        3) Check if the allow_discussion boolean flag on the content object is
           set. If it is set to True or False, return the value. If it set to
           None, try further.

        4) Traverse to a folder with allow_discussion set to either True or
           False. If allow_discussion is not set (None), traverse further until
           we reach the PloneSiteRoot.

        5) Check if discussion is allowed for the content type.
        """
        context = aq_inner(self.context)

        # Fetch discussion registry
        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IDiscussionSettings, check=False)

        # Check if discussion is allowed globally
        if not settings.globally_enabled:
            return False

        # Always return False if object is a folder
        if IFolderish.providedBy(context) and not INonStructuralFolder.providedBy(context):
            return False

        def traverse_parents(context):
            # Run through the aq_chain of obj and check if discussion is
            # enabled in a parent folder.
            for obj in aq_chain(context):
                if not IPloneSiteRoot.providedBy(obj):
                    if IFolderish.providedBy(obj) and not INonStructuralFolder.providedBy(obj):
                        flag = getattr(obj, "allow_discussion", None)
                        if flag is not None:
                            return flag
            return None

        # If discussion is disabled for the object, bail out
        obj_flag = getattr(aq_base(context), "allow_discussion", None)
        if obj_flag is False:
            return False

        # Check if traversal returned a folder with discussion_allowed set
        # to True or False.
        folder_allow_discussion = traverse_parents(context)

        if folder_allow_discussion:
            if not getattr(self, "allow_discussion", None):
                return True
        else:
            if obj_flag:
                return True

        # Check if discussion is allowed on the content type
        portal_types = getToolByName(self, "portal_types")
        document_fti = getattr(portal_types, context.portal_type)
        if not document_fti.getProperty("allow_discussion"):
            # If discussion is not allowed on the content type,
            # check if 'allow discussion' is overridden on the content object.
            if not obj_flag:
                return False

        return True
Beispiel #23
0
    def _enabled_for_archetypes(self):
        """ Returns True if discussion is enabled for this conversation.

        This method checks five different settings in order to figure out if
        discussion is enable on a specific content object:

        1) Check if discussion is enabled globally in the plone.app.discussion
           registry/control panel.

        2) If the current content object is a folder, always return
           False, since we don't allow comments on a folder. This
           setting is used to allow/ disallow comments for all content
           objects inside a folder, not for the folder itself.

        3) Check if the allow_discussion boolean flag on the content object is
           set. If it is set to True or False, return the value. If it set to
           None, try further.

        4) Traverse to a folder with allow_discussion set to either True or
           False. If allow_discussion is not set (None), traverse further until
           we reach the PloneSiteRoot.

        5) Check if discussion is allowed for the content type.
        """
        context = aq_inner(self.context)

        # Fetch discussion registry
        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IDiscussionSettings, check=False)

        # Check if discussion is allowed globally
        if not settings.globally_enabled:
            return False

        # Always return False if object is a folder
        context_is_folderish = IFolderish.providedBy(context)
        context_is_structural = not INonStructuralFolder.providedBy(context)
        if (context_is_folderish and context_is_structural):
            return False

        def traverse_parents(context):
            # Run through the aq_chain of obj and check if discussion is
            # enabled in a parent folder.
            for obj in aq_chain(context):
                if not IPloneSiteRoot.providedBy(obj):
                    obj_is_folderish = IFolderish.providedBy(obj)
                    obj_is_stuctural = not INonStructuralFolder.providedBy(obj)
                    if (obj_is_folderish and obj_is_stuctural):
                        flag = getattr(obj, 'allow_discussion', None)
                        if flag is not None:
                            return flag
            return None

        # If discussion is disabled for the object, bail out
        obj_flag = getattr(aq_base(context), 'allow_discussion', None)
        if obj_flag is False:
            return False

        # Check if traversal returned a folder with discussion_allowed set
        # to True or False.
        folder_allow_discussion = traverse_parents(context)

        if folder_allow_discussion:
            if not getattr(self, 'allow_discussion', None):
                return True
        else:
            if obj_flag:
                return True

        # Check if discussion is allowed on the content type
        portal_types = getToolByName(self, 'portal_types')
        document_fti = getattr(portal_types, context.portal_type)
        if not document_fti.getProperty('allow_discussion'):
            # If discussion is not allowed on the content type,
            # check if 'allow discussion' is overridden on the content object.
            if not obj_flag:
                return False

        return True