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 dependency with collective.volto.enhancedlinks #237

Closed
wants to merge 12 commits into from
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Changelog

- Fixed script to update pdc with description
[eikichi18]
- Add getObjSize info in File field serializer.
- Add collective.volto.enhancedlinks dependency (needed for slate integration).
[cekk]
- Add enhancedlinks infos in File field serializer.
[cekk]


6.1.10 (2024-01-16)
-------------------
Expand Down
1 change: 1 addition & 0 deletions base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ design.plone.contenttypes =
#redturtle.volto = git https://github.com/RedTurtle/redturtle.volto.git [email protected]:RedTurtle/redturtle.volto.git
#redturtle.bandi = git https://github.com/RedTurtle/redturtle.bandi.git [email protected]:RedTurtle/redturtle.bandi.git
#plone.restapi = git https://github.com/plone/plone.restapi.git
collective.volto.enhancedlinks = git https://github.com/RegioneER/collective.volto.enhancedlinks.git [email protected]:RegioneER/collective.volto.enhancedlinks.git branch=main
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"z3c.unconfigure",
"eea.api.taxonomy",
"openpyxl",
"collective.volto.enhancedlinks",
],
extras_require={
"test": [
Expand Down
3 changes: 2 additions & 1 deletion src/design/plone/contenttypes/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>7023</version>
<version>7030</version>
<dependencies>
<dependency>profile-redturtle.bandi:default</dependency>
<dependency>profile-collective.venue:default</dependency>
<dependency>profile-redturtle.volto:default</dependency>
<dependency>profile-eea.api.taxonomy:default</dependency>
<dependency>profile-collective.z3cform.datagridfield:default</dependency>
<dependency>profile-design.plone.contenttypes:taxonomy</dependency>
<dependency>profile-collective.volto.enhancedlinks:default</dependency>
</dependencies>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<element value="plone.locking" />
<element value="design.plone.contenttypes.behavior.multi_file" />
<element value="plone.translatable" />
<element value="volto.enhanced_links_enabled" />
</property>

<!-- View information -->
Expand Down
16 changes: 15 additions & 1 deletion src/design/plone/contenttypes/restapi/serializers/dxfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
from zope.schema.interfaces import ISourceText
from zope.schema.interfaces import ITextLine

try:
cekk marked this conversation as resolved.
Show resolved Hide resolved
from collective.volto.enhancedlinks.interfaces import IEnhancedLinksEnabled

HAS_ENHANCEDLINKS = True
except ImportError:
HAS_ENHANCEDLINKS = False

import json
import re

Expand Down Expand Up @@ -80,9 +87,16 @@ def __call__(self):
"filename": namedfile.filename,
"content-type": namedfile.contentType,
"size": size,
"getObjSize": human_readable_size(size),
"download": url,
}
if HAS_ENHANCEDLINKS:
if IEnhancedLinksEnabled.providedBy(self.context):
result.update(
{
"getObjSize": human_readable_size(size),
"enhanced_links_enabled": True,
}
)

return json_compatible(result)

Expand Down
3 changes: 3 additions & 0 deletions src/design/plone/contenttypes/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import collective.venue
import collective.volto.blocksfield
import collective.volto.cookieconsent
import collective.volto.enhancedlinks
import collective.z3cform.datagridfield
import design.plone.contenttypes
import eea.api.taxonomy
Expand All @@ -32,6 +33,7 @@ def setUpZope(self, app, configurationContext):
super().setUpZope(app, configurationContext)
self.loadZCML(package=collective.venue)
self.loadZCML(package=collective.volto.blocksfield)
self.loadZCML(package=collective.volto.enhancedlinks)
self.loadZCML(package=design.plone.contenttypes, context=configurationContext)
self.loadZCML(package=plone.formwidget.geolocation)
self.loadZCML(name="overrides.zcml", package=design.plone.contenttypes)
Expand Down Expand Up @@ -71,6 +73,7 @@ def setUpZope(self, app, configurationContext):
super().setUpZope(app, configurationContext)
self.loadZCML(package=collective.venue)
self.loadZCML(package=collective.volto.blocksfield)
self.loadZCML(package=collective.volto.enhancedlinks)
self.loadZCML(package=design.plone.contenttypes, context=configurationContext)
self.loadZCML(package=plone.formwidget.geolocation)
self.loadZCML(package=eea.api.taxonomy)
Expand Down
5 changes: 3 additions & 2 deletions src/design/plone/contenttypes/tests/test_ct_modulo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import unittest


class TestDocument(unittest.TestCase):
class TestModulo(unittest.TestCase):
layer = DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]

def test_behaviors_enabled_for_documento(self):
def test_behaviors_enabled_for_modulo(self):
portal_types = api.portal.get_tool(name="portal_types")
self.assertEqual(
portal_types["Modulo"].behaviors,
Expand All @@ -29,5 +29,6 @@ def test_behaviors_enabled_for_documento(self):
"plone.locking",
"design.plone.contenttypes.behavior.multi_file",
"plone.translatable",
"volto.enhanced_links_enabled",
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import unittest


class SummarySerializerTest(unittest.TestCase):
class FileFieldSerializerTest(unittest.TestCase):
layer = DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING

def setUp(self):
Expand Down Expand Up @@ -61,6 +61,11 @@ def test_if_visualize_files_true_so_dsiplay(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertIn("@@display-file", response["file_principale"]["download"])

def test_human_readable_obj_size_in_data(self):
def test_if_enhancedlinks_behavior_active_has_human_readable_obj_size_in_data(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertEqual("1 KB", response["file_principale"]["getObjSize"])

def test_if_enhancedlinks_behavior_active_has_flag_in_data(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertIn("enhanced_links_enabled", response["file_principale"])
self.assertTrue(response["file_principale"]["enhanced_links_enabled"])
11 changes: 10 additions & 1 deletion src/design/plone/contenttypes/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -808,5 +808,14 @@
handler=".upgrades.add_canale_digitale_link_index"
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
profile="design.plone.contenttypes:default"
source="7022"
destination="7030"
>
<genericsetup:upgradeStep
title="Add collective.volto.enhancedlinks"
handler=".upgrades.to_7030"
/>
</genericsetup:upgradeSteps>
</configure>
20 changes: 20 additions & 0 deletions src/design/plone/contenttypes/upgrades/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,26 @@ def update_pdc_with_pdc_desc(context):
logger.info("Ends of update")


def to_7030(context):
installOrReinstallProduct(api.portal.get(), "collective.volto.enhancedlinks")
# add behavior to modulo
portal_types = api.portal.get_tool(name="portal_types")
modulo_behaviors = [x for x in portal_types["Modulo"].behaviors]
if "volto.enhanced_links_enabled" not in modulo_behaviors:
modulo_behaviors.append("volto.enhanced_links_enabled")
portal_types["Modulo"].behaviors = tuple(modulo_behaviors)

# update index/metadata
brains = api.content.find(portal_type=["File", "Image", "Modulo"])
tot = len(brains)
i = 0
for brain in brains:
i += 1
if i % 100 == 0:
logger.info("Progress: {}/{}".format(i, tot))
brain.getObject().reindexObject(idxs=["enhanced_links_enabled"])


def add_canale_digitale_link_index(context):
update_catalog(context)
update_registry(context)
Expand Down
Loading