From 8ef4e6bb39d2a382079d53ca4963fcc1626ee0f6 Mon Sep 17 00:00:00 2001 From: TechSubham Date: Fri, 10 Jan 2025 02:32:20 +0530 Subject: [PATCH] issue fixed --- packages/volto/news/2837.bugfix | 1 + packages/volto/src/config/Blocks.jsx | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 packages/volto/news/2837.bugfix diff --git a/packages/volto/news/2837.bugfix b/packages/volto/news/2837.bugfix new file mode 100644 index 0000000000..80a6a3a83b --- /dev/null +++ b/packages/volto/news/2837.bugfix @@ -0,0 +1 @@ +Resolved an issue where block restrictions only applied to top-level blocks, allowing restricted blocks (e.g., Title) in nested contexts. The system now enforces restrictions across all block levels, preventing duplicates throughout the page. \ No newline at end of file diff --git a/packages/volto/src/config/Blocks.jsx b/packages/volto/src/config/Blocks.jsx index 0110a6616c..c91669dfe8 100644 --- a/packages/volto/src/config/Blocks.jsx +++ b/packages/volto/src/config/Blocks.jsx @@ -247,6 +247,29 @@ const groupBlocksOrder = [ { id: 'common', title: 'Common' }, ]; +const checkBlockRestriction = ({ properties, block }) => { + const checkBlockRecursively = (blocks, blockId) => { + if (!blocks || typeof blocks !== 'object') return false; + return Object.entries(blocks).some(([_uid, blockData]) => { + if (!blockData) return false; + if (blockData['@type'] === blockId) { + return true; + } + if ( + (blockData.blocks && blockData.blocks_layout) || + (blockData.data && + blockData.data.blocks && + blockData.data.blocks_layout) + ) { + const nestedBlocks = blockData.data?.blocks || blockData.blocks; + return checkBlockRecursively(nestedBlocks, blockId); + } + return false; + }); + }; + return checkBlockRecursively(properties.blocks, block.id); +}; + const blocksConfig = { title: { id: 'title', @@ -256,10 +279,7 @@ const blocksConfig = { view: ViewTitleBlock, edit: EditTitleBlock, schema: BlockSettingsSchema, - restricted: ({ properties, block }) => - properties.blocks_layout?.items?.find( - (uid) => properties.blocks?.[uid]?.['@type'] === block.id, - ), + restricted: checkBlockRestriction, mostUsed: false, blockHasOwnFocusManagement: true, sidebarTab: 0,