mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Customize: Add changeset locking in Customizer to prevent users from overriding each other's changes.
* Customization locking is checked when changesets are saved and when heartbeat ticks. * Lock is lifted immediately upon a user closing the Customizer. * Heartbeat is introduced into Customizer. * Changes made to user after it was locked by another user are stored as an autosave revision for restoration. * Lock notification displays link to preview the other user's changes on the frontend. * A user loading a locked Customizer changeset will be presented with an option to take over. * Autosave revisions attached to a published changeset are converted into auto-drafts so that they will be presented to users for restoration. * Focus constraining is improved in overlay notifications. * Escape key is stopped from propagating in overlay notifications, and it dismisses dismissible overlay notifications. * Introduces `changesetLocked` state which is used to disable the Save button and suppress the AYS dialog when leaving the Customizer. * Fixes bug where users could be presented with each other's autosave revisions. Props sayedwp, westonruter, melchoyce. See #31436, #31897, #39896. Fixes #42024. git-svn-id: https://develop.svn.wordpress.org/trunk@41839 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -516,20 +516,27 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
* Test request for dismissing autosave changesets.
|
||||
*
|
||||
* @ticket 39896
|
||||
* @covers WP_Customize_Manager::handle_dismiss_autosave_request()
|
||||
* @covers WP_Customize_Manager::handle_dismiss_autosave_or_lock_request()
|
||||
* @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets()
|
||||
*/
|
||||
public function test_handle_dismiss_autosave_request() {
|
||||
public function test_handle_dismiss_autosave_or_lock_request() {
|
||||
$uuid = wp_generate_uuid4();
|
||||
$wp_customize = $this->set_up_valid_state( $uuid );
|
||||
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data'] );
|
||||
|
||||
$nonce = wp_create_nonce( 'customize_dismiss_autosave' );
|
||||
$nonce = wp_create_nonce( 'customize_dismiss_autosave_or_lock' );
|
||||
$_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce;
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
|
||||
$_POST['dismiss_lock'] = $_GET['dismiss_lock'] = $_REQUEST['dismiss_lock'] = true;
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'no_changeset_to_dismiss_lock', $this->_last_response_parsed['data'] );
|
||||
|
||||
$_POST['dismiss_autosave'] = $_GET['dismiss_autosave'] = $_REQUEST['dismiss_autosave'] = true;
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] );
|
||||
|
||||
@@ -559,7 +566,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
foreach ( array_merge( $user_auto_draft_ids, $other_user_auto_draft_ids ) as $post_id ) {
|
||||
$this->assertFalse( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) );
|
||||
}
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'auto_draft_dismissed', $this->_last_response_parsed['data'] );
|
||||
foreach ( $user_auto_draft_ids as $post_id ) {
|
||||
@@ -572,7 +579,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
}
|
||||
|
||||
// Subsequent test results in none dismissed.
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] );
|
||||
|
||||
@@ -585,12 +592,19 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
),
|
||||
'status' => 'draft',
|
||||
) );
|
||||
|
||||
$_POST['dismiss_autosave'] = $_GET['dismiss_autosave'] = $_REQUEST['dismiss_autosave'] = false;
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'changeset_lock_dismissed', $this->_last_response_parsed['data'] );
|
||||
|
||||
$_POST['dismiss_autosave'] = $_GET['dismiss_autosave'] = $_REQUEST['dismiss_autosave'] = true;
|
||||
$this->assertNotInstanceOf( 'WP_Error', $r );
|
||||
$this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) );
|
||||
$this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content );
|
||||
|
||||
// Since no autosave yet, confirm no action.
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
|
||||
|
||||
@@ -610,13 +624,13 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
$this->assertContains( 'Bar', $autosave_revision->post_content );
|
||||
|
||||
// Confirm autosave gets deleted.
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'autosave_revision_deleted', $this->_last_response_parsed['data'] );
|
||||
$this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) );
|
||||
|
||||
// Since no autosave yet, confirm no action.
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave' );
|
||||
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
|
||||
}
|
||||
|
||||
@@ -1455,7 +1455,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
),
|
||||
'autosave' => true,
|
||||
) );
|
||||
$this->assertFalse( wp_get_post_autosave( $changeset_post_id ) );
|
||||
$this->assertFalse( wp_get_post_autosave( $changeset_post_id, get_current_user_id() ) );
|
||||
$this->assertContains( 'Autosaved Auto-draft Title', get_post( $changeset_post_id )->post_content );
|
||||
|
||||
// Update status to draft for subsequent tests.
|
||||
@@ -1493,7 +1493,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertEquals( 'illegal_autosave_with_non_current_user', $r->get_error_code() );
|
||||
|
||||
// Try autosave.
|
||||
$this->assertFalse( wp_get_post_autosave( $changeset_post_id ) );
|
||||
$this->assertFalse( wp_get_post_autosave( $changeset_post_id, get_current_user_id() ) );
|
||||
$r = $wp_customize->save_changeset_post( array(
|
||||
'data' => array(
|
||||
'blogname' => array(
|
||||
@@ -1505,7 +1505,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertInternalType( 'array', $r );
|
||||
|
||||
// Verify that autosave happened.
|
||||
$autosave_revision = wp_get_post_autosave( $changeset_post_id );
|
||||
$autosave_revision = wp_get_post_autosave( $changeset_post_id, get_current_user_id() );
|
||||
$this->assertInstanceOf( 'WP_Post', $autosave_revision );
|
||||
$this->assertContains( 'Draft Title', get_post( $changeset_post_id )->post_content );
|
||||
$this->assertContains( 'Autosave Title', $autosave_revision->post_content );
|
||||
@@ -2635,6 +2635,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
'currentUserCanPublish',
|
||||
'publishDate',
|
||||
'statusChoices',
|
||||
'lockUser',
|
||||
),
|
||||
array_keys( $data['changeset'] )
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user