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

Prevent saving the post before previewing in locked/read-only mode. #32341

Merged
merged 3 commits into from
Jun 2, 2021
Merged
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
13 changes: 10 additions & 3 deletions packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ export class PostPreviewButton extends Component {
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
this.previewWindow.focus();

// If we don't need to autosave the post before previewing, then we simply
// load the Preview URL in the Preview tab.
if ( ! this.props.isAutosaveable ) {
if (
// If we don't need to autosave the post before previewing, then we simply
// load the Preview URL in the Preview tab.
! this.props.isAutosaveable ||
// Also, save the post only if user has the post lock.
desaiuditd marked this conversation as resolved.
Show resolved Hide resolved
// Do not save or overwrite the post, if the post is already locked.
this.props.isPostLocked
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: @joemcgill suggested to expose this boolean as a component prop to PostPreviewButton but in my opinion, we should never perform any create/update changes to a post which is already locked by someone else. So this should be checked in all the cases. So there's no point exposing it as a prop.

) {
this.setPreviewWindowLink( event.target.href );
return;
}
Expand Down Expand Up @@ -232,6 +237,7 @@ export default compose( [
isEditedPostSaveable,
isEditedPostAutosaveable,
getEditedPostPreviewLink,
isPostLocked,
} = select( 'core/editor' );
const { getPostType } = select( 'core' );

Expand All @@ -250,6 +256,7 @@ export default compose( [
[ 'draft', 'auto-draft' ].indexOf(
getEditedPostAttribute( 'status' )
) !== -1,
isPostLocked: isPostLocked(),
};
} ),
withDispatch( ( dispatch ) => ( {
Expand Down