Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a profile to limit plone site root addable types #69

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/design/plone/policy/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<include package=".browser" />
<include package=".restapi" />
<include package=".limit_root_addables" />
<include file="permissions.zcml" />
<include file="upgrades.zcml" />

Expand All @@ -21,7 +22,6 @@
directory="profiles/default"
post_handler=".setuphandlers.post_install"
/>

<genericsetup:registerProfile
name="uninstall"
title="Design Plone: policy (uninstall)"
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions src/design/plone/policy/limit_root_addables/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="design.plone.policy.limit_root_addables"
>

<genericsetup:registerProfile
name="default"
title="design.plone.policy.limit_root_addables"
description="Installs the design.plone.policy.limit_root_addables add-on"
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/default"
post_handler=".setuphandlers.post_install"
/>

<genericsetup:registerProfile
name="uninstall"
title="Design Plone: policy (uninstall)"
description="Uninstalls the design.plone.policy add-on."
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/uninstall"
post_handler=".setuphandlers.uninstall"
/>

</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<object name="Plone Site" meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="filter_content_types">True</property>
<property name="allowed_content_types">
<element value="Folder"/>
<element value="File"/>
<element value="Document"/>
<element value="Image"/>
<element value="Subsite"/>
</property>
</object>
25 changes: 25 additions & 0 deletions src/design/plone/policy/limit_root_addables/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -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 = ()
46 changes: 35 additions & 11 deletions src/design/plone/policy/testing.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# -*- 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
import collective.volto.cookieconsent
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
Expand All @@ -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):
Expand Down Expand Up @@ -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,)

Expand Down
2 changes: 1 addition & 1 deletion src/design/plone/policy/tests/test_initial_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
67 changes: 59 additions & 8 deletions src/design/plone/policy/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
(),
)
Loading