Skip to content

Commit

Permalink
Add linkintegrity check also for count_down block.
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Nov 21, 2024
1 parent 37260d4 commit 82639af
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 30 deletions.
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.6.1 (unreleased)
------------------

- Nothing changed yet.
- Add linkintegrity check also for count_down block.
[cekk]


5.6.0 (2024-11-21)
Expand Down
17 changes: 15 additions & 2 deletions src/redturtle/volto/adapters/blocks_linkintegrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_urls_from_value(value):


class SubBlocksRetriever(SlateBlockLinksRetriever):

def extract_links(self, block_data):
children = iterate_children(block_data or [])
for child in children:
Expand Down Expand Up @@ -170,7 +169,6 @@ def __call__(self, block):

for row in block.get("table", {}).get("rows", []):
for cell in row.get("cells", []):

self.extract_links(block_data=cell.get("value", {}))

return self.links
Expand Down Expand Up @@ -218,3 +216,18 @@ def __call__(self, block):
self.links.append(url)

return self.links


@adapter(IDexterityContent, IBrowserRequest)
@implementer(IBlockFieldLinkIntegrityRetriever)
class CountDownBlockLinksRetriever(SubBlocksRetriever):
order = 200
block_type = "count_down"

def __call__(self, block):
if not block:
return self.links
for field_id in ["text", "countdown_text"]:
self.extract_links(block_data=block.get(field_id, []))

return self.links
4 changes: 4 additions & 0 deletions src/redturtle/volto/adapters/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
factory=".blocks_linkintegrity.IconBlockLinksRetriever"
provides="plone.restapi.interfaces.IBlockFieldLinkIntegrityRetriever"
/>
<subscriber
factory=".blocks_linkintegrity.CountDownBlockLinksRetriever"
provides="plone.restapi.interfaces.IBlockFieldLinkIntegrityRetriever"
/>
<!-- end of blocks linkintegrity for specific blocks -->

<adapter
Expand Down
1 change: 0 additions & 1 deletion src/redturtle/volto/adapters/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

@adapter(ICustomFeedItem, IFeed)
class CustomFeedItem(DexterityItem):

def _has_valid_image(self, behavior, field_name):
if not behavior:
return False
Expand Down
84 changes: 62 additions & 22 deletions src/redturtle/volto/tests/test_blocks_linkintegrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def get_references(self):
return links_info.get_breaches()

def test_testo_riquadro_semplice_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -67,7 +66,6 @@ def test_testo_riquadro_semplice_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_alert_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -99,7 +97,6 @@ def test_alert_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_accordion_description_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -131,7 +128,6 @@ def test_accordion_description_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_accordion_subblocks_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -169,7 +165,6 @@ def test_accordion_subblocks_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_testo_riquadro_immagine_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -201,7 +196,6 @@ def test_testo_riquadro_immagine_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_callout_block_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -233,7 +227,6 @@ def test_callout_block_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_cta_block_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -265,7 +258,6 @@ def test_cta_block_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_cta_block_ctalink_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "cta_block", "ctaLink": f"/resolveuid/{self.ref.UID()}"}
Expand All @@ -281,7 +273,6 @@ def test_cta_block_ctalink_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_cta_block_background_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "cta_block", "ctaImage": [self.ref.UID()]}
Expand All @@ -297,7 +288,6 @@ def test_cta_block_background_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_table_block_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -349,7 +339,6 @@ def test_table_block_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_contacts_block_description_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -381,7 +370,6 @@ def test_contacts_block_description_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_contacts_block_subblocks_text_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -417,7 +405,6 @@ def test_contacts_block_subblocks_text_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_contacts_block_subblocks_tel_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -453,7 +440,6 @@ def test_contacts_block_subblocks_tel_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_contacts_block_subblocks_email_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -489,7 +475,6 @@ def test_contacts_block_subblocks_email_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_icon_block_description_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -521,7 +506,6 @@ def test_icon_block_description_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_icon_block_href_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "iconBlocks", "href": f"/resolveuid/{self.ref.UID()}"}
Expand All @@ -537,7 +521,6 @@ def test_icon_block_href_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_icon_block_background_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "iconBlocks", "background": [self.ref.UID()]}
Expand All @@ -553,7 +536,6 @@ def test_icon_block_background_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_icon_block_subblocks_text_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand Down Expand Up @@ -589,7 +571,6 @@ def test_icon_block_subblocks_text_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_icon_block_subblocks_href_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand All @@ -608,7 +589,6 @@ def test_icon_block_subblocks_href_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_listing_block_linkHref_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
Expand All @@ -634,7 +614,6 @@ def test_listing_block_linkHref_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_rss_block_linkMore_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "rssBlock", "linkMore": f"resolveuid/{self.ref.UID()}"}
Expand All @@ -650,7 +629,6 @@ def test_rss_block_linkMore_link_integrity(self):
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_audio_block_link_integrity(self):

self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {"@type": "audioBlock", "audio": [{"UID": self.ref.UID()}]}
Expand All @@ -663,3 +641,65 @@ def test_audio_block_link_integrity(self):
self.assertEqual(len(reference["sources"]), 1)
self.assertEqual(reference["sources"][0]["uid"], self.document.UID())
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_count_down_text_link_integrity(self):
self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
"@type": "count_down",
"text": [
{
"type": "p",
"children": [
{
"type": "link",
"data": {
"url": f"/resolveuid/{self.ref.UID()}",
},
"children": [{"text": "foo"}],
},
],
}
],
}
}
notify(ObjectModifiedEvent(self.document))

references = self.get_references()
reference = references[0]

self.assertEqual(len(references), 1)
self.assertEqual(len(reference["sources"]), 1)
self.assertEqual(reference["sources"][0]["uid"], self.document.UID())
self.assertEqual(reference["target"]["uid"], self.ref.UID())

def test_count_down_countdown_text_link_integrity(self):
self.assertEqual(self.get_references(), [])
self.document.blocks = {
"xyz": {
"@type": "count_down",
"countdown_text": [
{
"type": "p",
"children": [
{
"type": "link",
"data": {
"url": f"/resolveuid/{self.ref.UID()}",
},
"children": [{"text": "foo"}],
},
],
}
],
}
}
notify(ObjectModifiedEvent(self.document))

references = self.get_references()
reference = references[0]

self.assertEqual(len(references), 1)
self.assertEqual(len(reference["sources"]), 1)
self.assertEqual(reference["sources"][0]["uid"], self.document.UID())
self.assertEqual(reference["target"]["uid"], self.ref.UID())
2 changes: 0 additions & 2 deletions src/redturtle/volto/tests/test_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_rss_item_iface_provided(self):
self.assertTrue(ICustomFeedItem.providedBy(self.news2))

def test_rss_item_field_name_image(self):

adapter_news_1 = CustomFeedItem(self.news1, self.feed)
adapter_news_2 = CustomFeedItem(self.news2, self.feed)

Expand All @@ -97,7 +96,6 @@ def test_rss_item_field_name_image(self):
self.assertEqual(adapter_news_2.field_name, None)

def test_rss_item_field_name_preview_image(self):

api.portal.set_registry_record(
"redturtle.volto.rss_image_choice", "preview_image"
)
Expand Down
2 changes: 0 additions & 2 deletions src/redturtle/volto/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,7 @@ def to_4307(context):


def to_4308(context):

def should_reindex(blocks):

reindexable_blocks = [
"accordion",
"alert",
Expand Down

0 comments on commit 82639af

Please sign in to comment.