From 0abfa0cb332b25b74f90e5810ebfc0745fe929e1 Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 6 Oct 2020 16:28:49 +0100 Subject: [PATCH 1/3] Add template lock attribute to column and group. --- packages/block-library/src/column/block.json | 3 + packages/block-library/src/column/edit.js | 4 +- packages/block-library/src/group/block.json | 3 + packages/block-library/src/group/edit.js | 3 +- packages/e2e-tests/plugins/cpt-locking.php | 76 +++++++++++++++++++ .../__snapshots__/cpt-locking.test.js.snap | 20 +++++ .../specs/editor/plugins/cpt-locking.test.js | 63 +++++++++++++++ 7 files changed, 169 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json index 494214858bf42..02c2084dabb3f 100644 --- a/packages/block-library/src/column/block.json +++ b/packages/block-library/src/column/block.json @@ -11,6 +11,9 @@ }, "width": { "type": "string" + }, + "templateLock": { + "type": "string" } }, "supports": { diff --git a/packages/block-library/src/column/edit.js b/packages/block-library/src/column/edit.js index 70e1e669bf511..aedf4e7270550 100644 --- a/packages/block-library/src/column/edit.js +++ b/packages/block-library/src/column/edit.js @@ -22,7 +22,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; function ColumnEdit( { - attributes: { verticalAlignment, width }, + attributes: { verticalAlignment, width, templateLock = false }, setAttributes, clientId, } ) { @@ -60,7 +60,7 @@ function ColumnEdit( { style: width ? { flexBasis: width } : undefined, } ); const innerBlocksProps = useInnerBlocksProps( blockProps, { - templateLock: false, + templateLock, renderAppender: hasChildBlocks ? undefined : InnerBlocks.ButtonBlockAppender, diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index f554f5ca01b55..6014985192acf 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -6,6 +6,9 @@ "tagName": { "type": "string", "default": "div" + }, + "templateLock": { + "type": "string" } }, "supports": { diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index ecf56d13f73dc..9920b05c334b5 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -20,12 +20,13 @@ function GroupEdit( { attributes, clientId } ) { [ clientId ] ); const blockProps = useBlockProps(); - const { tagName: TagName = 'div' } = attributes; + const { tagName: TagName = 'div', templateLock } = attributes; const innerBlocksProps = useInnerBlocksProps( { className: 'wp-block-group__inner-container', }, { + templateLock, renderAppender: hasInnerBlocks ? undefined : InnerBlocks.ButtonBlockAppender, diff --git a/packages/e2e-tests/plugins/cpt-locking.php b/packages/e2e-tests/plugins/cpt-locking.php index 8889d8a25267f..8f86aac400c73 100644 --- a/packages/e2e-tests/plugins/cpt-locking.php +++ b/packages/e2e-tests/plugins/cpt-locking.php @@ -52,6 +52,82 @@ function gutenberg_test_cpt_locking() { 'template_lock' => false, ) ); + register_post_type( + 'ul-post-ul-group', + array( + 'public' => true, + 'label' => 'Locked Post Unlocked group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array( + 'templateLock' => false, + ), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description343', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); + register_post_type( + 'l-post-l-group', + array( + 'public' => true, + 'label' => 'Locked Post Locked group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array( + 'templateLock' => 'all', + ), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); + register_post_type( + 'l-post-i-group', + array( + 'public' => true, + 'label' => 'Locked Post Inherited group', + 'show_in_rest' => true, + 'template' => array( + array( + 'core/group', + array(), + array( + array( 'core/quote' ), + array( + 'core/paragraph', + array( + 'placeholder' => 'Add a description', + ), + ), + ), + ), + ), + 'template_lock' => 'all', + ) + ); } add_action( 'init', 'gutenberg_test_cpt_locking' ); diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap index 157989c0da728..b4aa8da526a3b 100644 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap @@ -36,6 +36,26 @@ exports[`cpt locking template_lock all should not error when deleting the cotent " `; +exports[`cpt locking template_lock all unlocked group should allow blocks to be moved 1`] = ` +" +
+

p1

+ + + +

+
+" +`; + +exports[`cpt locking template_lock all unlocked group should allow blocks to be removed 1`] = ` +" +
+

+
+" +`; + exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = ` "
\\"\\"/
diff --git a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js index e4f62ca47aeb3..ecef11950b407 100644 --- a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js +++ b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js @@ -180,4 +180,67 @@ describe( 'cpt locking', () => { it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); } ); + + describe( 'template_lock all unlocked group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'ul-post-ul-group', + } ); + } ); + + it( 'should allow blocks to be removed', async () => { + await page.type( + '.block-editor-rich-text__editable[data-type="core/paragraph"]', + 'p1' + ); + await clickBlockToolbarButton( 'More options' ); + const [ removeBlock ] = await page.$x( + '//button[contains(text(), "Remove block")]' + ); + await removeBlock.click(); + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + + it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); + } ); + + describe( 'template_lock all locked group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'l-post-l-group', + } ); + } ); + + it( + 'should not allow blocks to be removed', + shouldNotAllowBlocksToBeRemoved + ); + + it( 'should not allow blocks to be moved', async () => { + await page.click( + '.block-editor-rich-text__editable[data-type="core/paragraph"]' + ); + expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull(); + } ); + } ); + + describe( 'template_lock all inherited group', () => { + beforeEach( async () => { + await createNewPost( { + postType: 'l-post-i-group', + } ); + } ); + + it( + 'should not allow blocks to be removed', + shouldNotAllowBlocksToBeRemoved + ); + + it( 'should not allow blocks to be moved', async () => { + await page.click( + '.block-editor-rich-text__editable[data-type="core/paragraph"]' + ); + expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull(); + } ); + } ); } ); From 102407d4f44e36c079c5a0e4a69157140273761b Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 16 Oct 2020 12:39:00 +0100 Subject: [PATCH 2/3] Update packages/e2e-tests/plugins/cpt-locking.php Co-authored-by: Miguel Fonseca --- packages/e2e-tests/plugins/cpt-locking.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/plugins/cpt-locking.php b/packages/e2e-tests/plugins/cpt-locking.php index 8f86aac400c73..77805022f654d 100644 --- a/packages/e2e-tests/plugins/cpt-locking.php +++ b/packages/e2e-tests/plugins/cpt-locking.php @@ -69,7 +69,7 @@ function gutenberg_test_cpt_locking() { array( 'core/paragraph', array( - 'placeholder' => 'Add a description343', + 'placeholder' => 'Add a description', ), ), ), From 120abca7d64f0223f77784047fa451ebebf79a5b Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 16 Oct 2020 12:44:01 +0100 Subject: [PATCH 3/3] Update packages/e2e-tests/plugins/cpt-locking.php Co-authored-by: Miguel Fonseca --- packages/e2e-tests/plugins/cpt-locking.php | 2 +- .../specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap | 2 +- packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/e2e-tests/plugins/cpt-locking.php b/packages/e2e-tests/plugins/cpt-locking.php index 77805022f654d..f4fbdb99ffb25 100644 --- a/packages/e2e-tests/plugins/cpt-locking.php +++ b/packages/e2e-tests/plugins/cpt-locking.php @@ -53,7 +53,7 @@ function gutenberg_test_cpt_locking() { ) ); register_post_type( - 'ul-post-ul-group', + 'l-post-ul-group', array( 'public' => true, 'label' => 'Locked Post Unlocked group', diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap index b4aa8da526a3b..bec98aa082055 100644 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap @@ -38,7 +38,7 @@ exports[`cpt locking template_lock all should not error when deleting the cotent exports[`cpt locking template_lock all unlocked group should allow blocks to be moved 1`] = ` " -
+

p1

diff --git a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js index ecef11950b407..59bb45283fca5 100644 --- a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js +++ b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js @@ -184,7 +184,7 @@ describe( 'cpt locking', () => { describe( 'template_lock all unlocked group', () => { beforeEach( async () => { await createNewPost( { - postType: 'ul-post-ul-group', + postType: 'l-post-ul-group', } ); } );