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

Enforce Block Restrictions Across All Nesting Levels #6575

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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.
TechSubham marked this conversation as resolved.
Show resolved Hide resolved
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
Loading