Skip to content

Commit

Permalink
add patch + updated CHANGES
Browse files Browse the repository at this point in the history
  • Loading branch information
eikichi18 committed Dec 2, 2024
1 parent 5fee913 commit 468e701
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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.4 (unreleased)
------------------

- Nothing changed yet.
- Add patch for SlateBlockLinksRetriever.
[eikichi18]


5.6.3 (2024-12-02)
Expand Down
36 changes: 36 additions & 0 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from collections import deque
from plone.app.caching import purge
from plone.app.event.base import dt_start_of_day
from plone.app.event.dx.behaviors import IEventBasic
Expand Down Expand Up @@ -208,6 +209,7 @@ def plone_restapi_blocks_linkintegrity_blocksretriever_retrieveLinks(self):
blocks = getattr(self.context, "blocks", {})
if not blocks:
return links

for block in visit_blocks(self.context, blocks):
if not isinstance(block, dict):
continue
Expand All @@ -217,3 +219,37 @@ def plone_restapi_blocks_linkintegrity_blocksretriever_retrieveLinks(self):
):
links |= set(handler(block))
return links


def iterate_children(value):
"""iterate_children.
plone.restapi.deserializer.blocks.iterate_childen
"""
queue = deque(value)
while queue:
child = queue.pop()
yield child
if isinstance(child, dict) and child.get("children"):
queue.extend(child["children"] or [])


def plone_restapi_blocks_linkintegrity_slateblocklinksretriever_call(self, block):
"""
plone.restapi.blocks_linkintegrity.SlateBlockLinksRetriever.__call__ patch
"""
value = (block or {}).get(self.field, [])
children = iterate_children(value or [])
for child in children:
if not isinstance(child, dict):
continue

node_type = child.get("type")
if node_type:
handler = getattr(self, f"handle_{node_type}", None)
if handler:
value = handler(child)
if value:
self.links.append(value)

return self.links
8 changes: 8 additions & 0 deletions src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
preserveOriginal="True"
/>

<monkey:patch
original="__call__"
replacement=".monkey.plone_restapi_blocks_linkintegrity_slateblocklinksretriever_call"
class="plone.restapi.blocks_linkintegrity.SlateBlockLinksRetriever"
description="Add check on child"
preserveOriginal="True"
/>

<monkey:patch
original="search_for_similar"
replacement=".monkey.search_for_similar"
Expand Down

0 comments on commit 468e701

Please sign in to comment.