Skip to content

Commit

Permalink
issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
TechSubham committed Jan 9, 2025
1 parent 374dfbc commit 8ef4e6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/2837.bugfix
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 24 additions & 4 deletions packages/volto/src/config/Blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit 8ef4e6b

Please sign in to comment.