@@ -323,6 +323,49 @@ export default (panel) => {
323323 */
324324 saveAbortController : null ,
325325
326+ /**
327+ * Unlocks the content for the current editor
328+ */
329+ async unlock ( env = { } ) {
330+ if ( this . isProcessing === true ) {
331+ return ;
332+ }
333+
334+ // Only discard changes from the current view
335+ if ( this . isCurrent ( env ) === false ) {
336+ throw new Error ( "Cannot unlock content from another view" ) ;
337+ }
338+
339+ // Check the lock state to determine if we can unlock
340+ if ( this . isLocked ( env ) === false ) {
341+ throw new Error ( "The content is not locked" ) ;
342+ }
343+
344+ // Cancel any ongoing save requests.
345+ // The discard request will throw those
346+ // changes away anyway.
347+ this . cancelSaving ( ) ;
348+
349+ // Start processing the request
350+ this . isProcessing = true ;
351+
352+ try {
353+ await this . request ( "unlock" , { } , env ) ;
354+
355+ this . emit ( "unlock" , { } , env ) ;
356+ } catch ( error ) {
357+ // handle locked states
358+ if ( error . key ?. startsWith ( "error.content.lock" ) ) {
359+ return this . lockDialog ( error . details ) ;
360+ }
361+
362+ // let our regular error handler take over
363+ throw error ;
364+ } finally {
365+ this . isProcessing = false ;
366+ }
367+ } ,
368+
326369 /**
327370 * Updates the form values of the current view
328371 */
0 commit comments