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 patch for slateblocklinksretriver #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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.6.4 (unreleased)
------------------

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


5.6.3 (2024-12-02)
Expand Down
37 changes: 37 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,38 @@ 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
Loading