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

Code cleanup, add 'volto.blocks' behavior to Plone Site GS types info… #43

Merged
merged 4 commits into from
Jan 20, 2022
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
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Changelog
- Use by default Slate blocks for the default pages
[sneridagh]

- Code cleanup, remove some outdated and unused helpers in ``setuptools.py``
[sneridagh]

- Add ``volto.blocks`` behavior to Plone Site GS types info.
[sneridagh]

- Remove ``Collection`` from types in GS types info.
[sneridagh]

- Remove ``plone.richtext`` behavior from Plone Site, Document, News Item, Events
[sneridagh]

3.1.0a9 (2022-01-15)
--------------------
Expand Down
2 changes: 1 addition & 1 deletion src/plone/volto/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1014</version>
<version>1015</version>
<dependencies>
<dependency>profile-plone.restapi:blocks</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions src/plone/volto/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<object name="Plone Site" />
<object meta_type="Dexterity FTI" name="LRF" />
<object meta_type="Dexterity FTI" name="Document" />
<object meta_type="Dexterity FTI" name="Collection" />
<object meta_type="Dexterity FTI" name="News Item" />
<object meta_type="Dexterity FTI" name="Event" />
</object>
8 changes: 8 additions & 0 deletions src/plone/volto/profiles/default/types/Collection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<object name="Collection" meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">

<!-- Collections in Volto are disabled by default -->
<property name="global_allow">False</property>

</object>
14 changes: 0 additions & 14 deletions src/plone/volto/profiles/default/types/Plone_Site.xml

This file was deleted.

140 changes: 74 additions & 66 deletions src/plone/volto/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
from plone import api
from plone.app.multilingual.browser.setup import SetupMultilingualSite
from plone.app.multilingual.setuphandlers import enable_translatable_behavior
from plone.app.portlets.utils import assignment_mapping_from_key
from plone.dexterity.interfaces import IDexterityFTI
from plone.portlets.constants import CONTEXT_CATEGORY
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from plone.volto.default_homepage.default import default_home
from plone.volto.default_homepage.demo import demo_home_page
from plone.volto.default_homepage.lrf import default_lrf_home
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import INonInstallable
from Products.CMFPlone.utils import get_installer
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component import queryUtility
from zope.component.interfaces import IFactory
from zope.container.interfaces import INameChooser
from zope.interface import implementer

import json
Expand All @@ -36,6 +28,13 @@

logger = logging.getLogger("plone.volto")

NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES = [
"Plone Site",
"Document",
"News Item",
"Event",
]


@implementer(INonInstallable)
class HiddenProfiles(object):
Expand All @@ -49,6 +48,12 @@ def post_install(context):
# For Plone 6, make sure the blocks behavior is enabled in the root
if PLONE_6:
add_behavior("Plone Site", "volto.blocks")
else:
set_edit_action_in_plone_site_for_plone5(context)

# Remove plone.richtext from content types with blocks enabled
for type_ in NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES:
remove_behavior(type_, "plone.richtext")


def uninstall(context):
Expand Down Expand Up @@ -147,64 +152,67 @@ def add_catalog_indexes(context, wanted=None):

def add_behavior(portal_type, behavior):
fti = queryUtility(IDexterityFTI, name=portal_type)
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
new.append(behavior)
fti.behaviors = tuple(new)


def setupNavigationPortlet(
context,
name="",
root=None,
includeTop=False,
currentFolderOnly=False,
bottomLevel=0,
topLevel=0,
):
"""
setupNavigationPortlet(portal['vereinigungen']['fachliche-vereinigungen']['sektion-materie-und-kosmos']['gravitation-und-relativitaetstheorie']) # noqa
"""
from plone.app.portlets.portlets.navigation import (
Assignment as NavAssignment,
) # noqa

target_manager = queryUtility(
IPortletManager, name="plone.leftcolumn", context=context
)
target_manager_assignments = getMultiAdapter(
(context, target_manager), IPortletAssignmentMapping
)

navtree = NavAssignment(
includeTop=includeTop,
currentFolderOnly=currentFolderOnly,
bottomLevel=bottomLevel,
topLevel=topLevel,
)

if "navigation" not in target_manager_assignments.keys():
target_manager_assignments["navigation"] = navtree


def setupPortletAt(portal, portlet_type, manager, path, name="", **kw):
"""
setupPortletAt(portal, 'portlets.Events', 'plone.rightcolumn', '/vereinigungen/fachliche-vereinigungen/sektion-kondensierte-materie/halbleiterphysik') # noqa
"""
portlet_factory = getUtility(IFactory, name=portlet_type)
assignment = portlet_factory(**kw)
mapping = assignment_mapping_from_key(
portal, manager, CONTEXT_CATEGORY, path, create=True
)

if not name:
chooser = INameChooser(mapping)
name = chooser.chooseName(None, assignment)

mapping[name] = assignment
if fti is not None:
# This prevents to add the behavior twice
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
new.append(behavior)
fti.behaviors = tuple(new)


def remove_behavior(portal_type, behavior):
fti = queryUtility(IDexterityFTI, name=portal_type)
if fti is not None:
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
fti.behaviors = tuple(new)


def set_edit_action_in_plone_site_for_plone5(context):
pt = api.portal.get_tool("portal_types")
fti = pt.getTypeInfo("Plone Site")

# Plone site Edit action properties
action_id = "edit"
category = "object"
condition = ""
title = "Edit"
action = "string:${object_url}/edit"
visible = "True"
permissions = ["Modify portal content"]
icon_expr = ""
link_target = ""

action_obj = fti.getActionObject(category + "/" + action_id)

if action_obj is None:
fti.addAction(
action_id,
title,
action,
condition,
tuple(permissions),
category,
visible,
icon_expr=icon_expr,
link_target=link_target,
)
else:
action_obj.edit(
title=title,
action=action,
icon_expr=icon_expr,
condition=condition,
permissions=tuple(permissions),
visible=visible,
link_target=link_target,
)


def create_default_homepage_draftjs(context):
Expand Down
27 changes: 27 additions & 0 deletions src/plone/volto/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

import unittest

try:
from Products.CMFPlone.factory import PLONE60MARKER

PLONE60MARKER # pyflakes
except ImportError:
PLONE_6 = False
else:
PLONE_6 = True


class TestSetup(unittest.TestCase):
"""Test that plone.volto is properly installed."""
Expand Down Expand Up @@ -40,6 +49,24 @@ def test_browserlayer(self):

self.assertIn(IPloneVoltoCoreLayer, utils.registered_layers())

@unittest.skipIf(
not PLONE_6,
"This test is only intended to run for Plone 6",
)
def test_plone_site_has_blocks_behavior(self):
pt = api.portal.get_tool("portal_types")
fti = pt.getTypeInfo("Plone Site")

self.assertTrue("volto.blocks" in fti.behaviors)

def test_plone_site_has_edit_action_setup(self):
pt = api.portal.get_tool("portal_types")
fti = pt.getTypeInfo("Plone Site")

action_obj = fti.getActionObject("object/edit")
self.assertIsNotNone(action_obj)
self.assertTrue("Modify portal content" in action_obj.permissions)


class TestUninstall(unittest.TestCase):

Expand Down
7 changes: 7 additions & 0 deletions src/plone/volto/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from plone.restapi.behaviors import IBlocks
from plone.volto import content
from plone.volto import logger
from plone.volto.setuphandlers import NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES
from plone.volto.setuphandlers import remove_behavior


MIGRATION = {
Expand Down Expand Up @@ -96,3 +98,8 @@ def migrate_listing(originBlocks):
for brain in pc.unrestrictedSearchResults(object_provides=IBlocks.__identifier__):
obj = brain.getObject()
obj.blocks = migrate_listing(obj.blocks)


def remove_plone_richtext_behavior(context):
for type_ in NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES:
remove_behavior(type_, "plone.richtext")
14 changes: 14 additions & 0 deletions src/plone/volto/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@
handler=".upgrades.migrate_content_classes"
/>

<genericsetup:upgradeSteps
profile="plone.volto:default"
source="1014"
destination="1015"
>
<genericsetup:upgradeDepends
title="Update types info for Plone Site"
import_steps="typeinfo"
/>
<genericsetup:upgradeStep
title="remove plone.richtext from Plone Site, Document, News Item, Event"
handler=".upgrades.remove_plone_richtext_behavior"
/>
</genericsetup:upgradeSteps>
</configure>