diff --git a/CHANGES.rst b/CHANGES.rst
index 9efe6f8..0ddb000 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,7 +4,8 @@ Changelog
5.0.10 (unreleased)
-------------------
-- Nothing changed yet.
+- Add a profile to limit addables on site root
+ [lucabel]
5.0.9 (2024-04-12)
diff --git a/src/design/plone/policy/configure.zcml b/src/design/plone/policy/configure.zcml
index 1d36e86..f3fea94 100644
--- a/src/design/plone/policy/configure.zcml
+++ b/src/design/plone/policy/configure.zcml
@@ -10,6 +10,7 @@
+
@@ -21,7 +22,6 @@
directory="profiles/default"
post_handler=".setuphandlers.post_install"
/>
-
+
+
+
+
+
+
diff --git a/src/design/plone/policy/limit_root_addables/profiles/default/types/Plone_Site.xml b/src/design/plone/policy/limit_root_addables/profiles/default/types/Plone_Site.xml
new file mode 100644
index 0000000..4f74be3
--- /dev/null
+++ b/src/design/plone/policy/limit_root_addables/profiles/default/types/Plone_Site.xml
@@ -0,0 +1,12 @@
+
+
diff --git a/src/design/plone/policy/limit_root_addables/setuphandlers.py b/src/design/plone/policy/limit_root_addables/setuphandlers.py
new file mode 100644
index 0000000..67c99c6
--- /dev/null
+++ b/src/design/plone/policy/limit_root_addables/setuphandlers.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from Products.CMFPlone.interfaces import INonInstallable
+from zope.interface import implementer
+
+
+@implementer(INonInstallable)
+class HiddenProfiles(object):
+ def getNonInstallableProfiles(self):
+ """Hide uninstall profile from site-creation and quickinstaller."""
+ return [
+ "design.plone.policy.limit_root_addable:uninstall",
+ ]
+
+
+def post_install(context):
+ """Post install script"""
+ # Do something at the end of the installation of this package.
+
+
+def uninstall(context):
+ """Uninstall script"""
+ # Do something at the end of the uninstallation of this package.
+ plonesite = context.portal_types["Plone Site"]
+ plonesite.filter_content_types = False
+ plonesite.allowed_content_types = ()
diff --git a/src/design/plone/policy/testing.py b/src/design/plone/policy/testing.py
index 340ead9..d5644dc 100644
--- a/src/design/plone/policy/testing.py
+++ b/src/design/plone/policy/testing.py
@@ -1,14 +1,4 @@
# -*- coding: utf-8 -*-
-from design.plone.contenttypes.testing import DesignPloneContenttypesLayer
-from design.plone.contenttypes.testing import DesignPloneContenttypesRestApiLayer
-from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
-from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
-from plone.app.testing import applyProfile
-from plone.app.testing import FunctionalTesting
-from plone.app.testing import IntegrationTesting
-from plone.testing import z2
-from zope.globalrequest import setRequest
-
import collective.feedback
import collective.MockMailHost
import collective.taxonomy
@@ -16,10 +6,10 @@
import collective.volto.dropdownmenu
import collective.volto.formsupport
import collective.volto.secondarymenu
+import collective.volto.slimheader
import collective.volto.socialsettings
import collective.volto.subfooter
import collective.volto.subsites
-import collective.volto.slimheader
import collective.z3cform.datagridfield
import design.plone.contenttypes
import design.plone.policy
@@ -28,6 +18,15 @@
import redturtle.faq
import redturtle.voltoplugin.editablefooter
import souper.plone
+from design.plone.contenttypes.testing import (
+ DesignPloneContenttypesLayer,
+ DesignPloneContenttypesRestApiLayer,
+)
+from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
+from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
+from plone.app.testing import FunctionalTesting, IntegrationTesting, applyProfile
+from plone.testing import z2
+from zope.globalrequest import setRequest
class FauxRequest(dict):
@@ -91,6 +90,31 @@ def setUpPloneSite(self, portal):
)
+class DesignPlonePolicyLimitRootAddablesLayer(DesignPlonePolicyLayer):
+ def setUpZope(self, app, configurationContext):
+ # Load any other ZCML that is required for your tests.
+ # The z3c.autoinclude feature is disabled in the Plone fixture base
+ # layer.
+
+ super().setUpZope(app, configurationContext)
+ self.loadZCML(package=design.plone.policy)
+
+ def setUpPloneSite(self, portal):
+ super().setUpPloneSite(portal)
+ request = portal.REQUEST
+ setRequest(request)
+ import pdb
+
+ pdb.set_trace()
+ applyProfile(portal, "design.plone.policy.limit_root_addables:default")
+
+
+DESIGN_PLONE_POLICY_LIMIT_ROOT_ADDABLES_INTEGRATION_TESTING = IntegrationTesting(
+ bases=(DESIGN_PLONE_POLICY_INTEGRATION_TESTING,),
+ name="DesignPlonePolicyLimitRootAddablesLayer:IntegrationTesting",
+)
+
+
class DesignPlonePolicyRestApiLayer(DesignPloneContenttypesRestApiLayer):
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
diff --git a/src/design/plone/policy/tests/test_initial_structure.py b/src/design/plone/policy/tests/test_initial_structure.py
index 11f6ffa..dd1a96d 100644
--- a/src/design/plone/policy/tests/test_initial_structure.py
+++ b/src/design/plone/policy/tests/test_initial_structure.py
@@ -49,7 +49,7 @@ def test_first_level_created(self):
for child in self.portal.listFolderContents():
if child.id == "leggi-le-faq":
self.assertEqual(child.portal_type, "FaqFolder")
- elif child.id == "dichiarazione-di-accessiblita":
+ elif child.id == "dichiarazione-di-accessibilita":
self.assertEqual(child.portal_type, "Link")
else:
self.assertEqual(child.portal_type, "Document")
diff --git a/src/design/plone/policy/tests/test_setup.py b/src/design/plone/policy/tests/test_setup.py
index 13b2d64..7c25d22 100644
--- a/src/design/plone/policy/tests/test_setup.py
+++ b/src/design/plone/policy/tests/test_setup.py
@@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-
"""Setup tests for this package."""
-from design.plone.policy.testing import DESIGN_PLONE_POLICY_INTEGRATION_TESTING
+import unittest
+
+from design.plone.policy.testing import (
+ DESIGN_PLONE_POLICY_INTEGRATION_TESTING,
+ DESIGN_PLONE_POLICY_LIMIT_ROOT_ADDABLES_INTEGRATION_TESTING,
+)
from plone import api
-from plone.app.testing import setRoles
-from plone.app.testing import TEST_USER_ID
+from plone.app.testing import TEST_USER_ID, setRoles
from plone.registry.interfaces import IRegistry
-from Products.CMFPlone.interfaces import ISearchSchema
-from Products.CMFPlone.interfaces import ISiteSchema
+from Products.CMFPlone.interfaces import ISearchSchema, ISiteSchema
from Products.CMFPlone.interfaces.controlpanel import INavigationSchema
from zope.component import getUtility
-import unittest
-
-
try:
from Products.CMFPlone.utils import get_installer
except ImportError:
@@ -58,6 +58,10 @@ def test_searchable_types(self):
sorted(settings.types_not_searched),
sorted(
(
+ "File",
+ "Image",
+ "Incarico",
+ "Modulo",
"Documento Personale",
"Bando Folder Deepening",
"Pratica",
@@ -100,3 +104,50 @@ def test_browserlayer_removed(self):
from plone.browserlayer import utils
self.assertNotIn(IDesignPlonePolicyLayer, utils.registered_layers())
+
+
+class TestSetupLimitRootAddables(unittest.TestCase):
+
+ layer = DESIGN_PLONE_POLICY_LIMIT_ROOT_ADDABLES_INTEGRATION_TESTING
+
+ def setUp(self):
+ """Custom shared utility setup for tests."""
+ self.portal = self.layer["portal"]
+ if get_installer:
+ self.installer = get_installer(self.portal, self.layer["request"])
+ else:
+ self.installer = api.portal.get_tool("portal_quickinstaller")
+ self.installer.install_product("design.plone.policy.limit_root_addables")
+
+ def test_setup(self):
+ plonesite = api.portal.get_tool("portal_types")["Plone Site"]
+ self.assertTrue(plonesite.filter_content_types)
+ self.assertEqual(
+ sorted(plonesite.allowed_content_types),
+ sorted(("Folder", "File", "Document", "Image", "Subsite")),
+ )
+
+
+class TestUninstallLimitRootAddables(unittest.TestCase):
+
+ layer = DESIGN_PLONE_POLICY_INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer["portal"]
+ if get_installer:
+ self.installer = get_installer(self.portal, self.layer["request"])
+ else:
+ self.installer = api.portal.get_tool("portal_quickinstaller")
+ # roles_before = api.user.get_roles(TEST_USER_ID)
+ # setRoles(self.portal, TEST_USER_ID, ["Manager"])
+ self.installer.install_product("design.plone.policy.limit_root_addables")
+ # setRoles(self.portal, TEST_USER_ID, roles_before)
+
+ def test_uninstall(self):
+ plonesite = api.portal.get_tool("portal_types")["Plone Site"]
+ self.installer.uninstall_product("design.plone.policy.limit_root_addables")
+ self.assertFalse(plonesite.filter_content_types)
+ self.assertEqual(
+ plonesite.allowed_content_types,
+ (),
+ )