Repository: plone.app.content
Branch: refs/heads/master
Date: 2014-11-15T13:08:58+01:00
Author: Philip Bauer (pbauer) <bauer@starzel.de>
Commit: https://github.com/plone/plone.app.content/commit/f745a13e2d2dd89e2dfcf51cb5d00acc05b29c80

Allow folderish types as default_page if users cannot add content.

Files changed:
M CHANGES.rst
M plone/app/content/browser/selection.py
M plone/app/content/browser/templates/select_default_page.pt
M plone/app/content/tests/test_selectdefaultpage.py

diff --git a/CHANGES.rst b/CHANGES.rst
index cbf1332..8c18a0e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,7 +4,9 @@ Changelog
 3.0.2 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Allow folderish types as default_page as long as users cannot add content
+  to them.
+  [pbauer]
 
 
 3.0.1 (2014-10-23)
diff --git a/plone/app/content/browser/selection.py b/plone/app/content/browser/selection.py
index cdf8084..bc083ee 100644
--- a/plone/app/content/browser/selection.py
+++ b/plone/app/content/browser/selection.py
@@ -1,3 +1,4 @@
+from Acquisition import aq_inner
 from Products.CMFPlone import PloneMessageFactory as _
 from Products.statusmessages.interfaces import IStatusMessage
 from Products.CMFCore.utils import getToolByName
@@ -84,3 +85,37 @@ def __call__(self):
             self.request.response.redirect(self.context.absolute_url())
 
         return self.index()
+
+    def get_selectable_items(self):
+        """ Return brains in this container that can be used as default_pages
+        """
+        context = aq_inner(self.context)
+        portal_properties = getToolByName(context, 'portal_properties')
+        sp = portal_properties.site_properties
+        view_types = sp.getProperty('typesUseViewActionInListings', [])
+        default_page_types = sp.getProperty('default_page_types', [])
+        portal_types = getToolByName(self.context, 'portal_types')
+
+        results = []
+        for brain in context.getFolderContents():
+            portal_type = brain.portal_type
+            if portal_type in view_types:
+                # Skip files and images
+                continue
+
+            if portal_type in default_page_types:
+                # Allow types that are explicitly in default_page_types
+                results.append(brain)
+                continue
+
+            if brain.is_folderish:
+                fti = portal_types.get(portal_type)
+                if not fti:
+                    continue
+                if fti.filter_content_types and fti.allowed_content_types or \
+                        not fti.filter_content_types:
+                    # Disallow folderish types if you can't add any content.
+                    # To override you have to add type to default_page_types
+                    continue
+            results.append(brain)
+        return results
diff --git a/plone/app/content/browser/templates/select_default_page.pt b/plone/app/content/browser/templates/select_default_page.pt
index 26541d8..34c1032 100644
--- a/plone/app/content/browser/templates/select_default_page.pt
+++ b/plone/app/content/browser/templates/select_default_page.pt
@@ -26,11 +26,7 @@
 
             <input type="hidden" name="form.submitted" value="1"/>
 
-            <tal:items define="availableTypes site_properties/default_page_types | python:[];
-                               use_view_action site_properties/typesUseViewActionInListings|python:[];
-                               items python:[item for item in context.getFolderContents() if
-                                                (not item.is_folderish or item.portal_type in availableTypes) and
-                                                item.portal_type not in use_view_action];
+            <tal:items define="items view/get_selectable_items;
                                cur_page context/getDefaultPage|nothing;
                                ploneview nocall:context/@@plone">
             <tal:hasItems condition="items"
diff --git a/plone/app/content/tests/test_selectdefaultpage.py b/plone/app/content/tests/test_selectdefaultpage.py
index 1dceb67..ac465f2 100644
--- a/plone/app/content/tests/test_selectdefaultpage.py
+++ b/plone/app/content/tests/test_selectdefaultpage.py
@@ -71,6 +71,21 @@ def test_select_default_page_view(self):
         self.assertTrue('Select default page' in self.browser.contents)
         self.assertTrue('id="testdoc"' in self.browser.contents)
 
+    def test_select_default_page_view_with_folderish_type(self):
+        """Check if folderish types are available."""
+        folder = self.portal.testfolder
+        folder.invokeFactory(id=FOLDER['id'], type_name='Folder')
+        folder2 = getattr(folder, FOLDER['id'])
+        folder.setTitle(FOLDER['title'])
+        folder2.reindexObject()
+        folder_fti = self.portal.portal_types['Folder']
+        folder_fti.manage_changeProperties(
+            filter_content_types=True, allowed_content_types=[])
+        view = folder.restrictedTraverse('@@select_default_page')()
+
+        self.assertTrue('id="testdoc"' in view)
+        self.assertTrue('id="testfolder"' in view)
+
     def test_default_page_action_cancel(self):
         """Check the Cancel action."""
         folder = self.portal.testfolder