Skip to content

Commit

Permalink
Merge pull request #3602 from nextcloud/backport/3601/stable27
Browse files Browse the repository at this point in the history
[stable27] fix: Use Close_Session post message to properly end the Collabora editing before opening locally
  • Loading branch information
juliusknorr authored Apr 19, 2024
2 parents 871897c + 33e6712 commit 9ac2677
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
16 changes: 12 additions & 4 deletions cypress/e2e/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,19 @@ describe('Nextcloud integration', function() {
cy.get('.oc-dialog .oc-dialog-title')
.should('contain', 'Open file locally ')

cy.on('url:changed', (newUrl) => {
expect(newUrl).to.contain('nc://')
})
cy.intercept({
method: 'POST',
url: '**/openlocaleditor',
}).as('getLocalToken')
cy.window()
.then((window) => {
cy.stub(window, 'open').as('open')
})
cy.get('.oc-dialog button.primary').click()

cy.wait('@getLocalToken').its('response.statusCode').should('equal', 200)
cy.get('@open').should('have.been.calledOnce')
const nextcloudHost = new URL(Cypress.config('baseUrl')).host
cy.get('@open').its('firstCall.args.0').should('contain', 'nc://open/' + randUser.userId + '@' + nextcloudHost + '/document.odt')
})

it('Insert image', function() {
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function checkFileInfo($fileId, $access_token) {
'EnableInsertRemoteImage' => !$isPublic,
'EnableShare' => $file->isShareable() && !$isVersion && !$isPublic,
'HideUserList' => '',
'EnableOwnerTermination' => $wopi->getCanwrite() && !$isPublic,
'DisablePrint' => $wopi->getHideDownload(),
'DisableExport' => $wopi->getHideDownload(),
'DisableCopy' => $wopi->getHideDownload(),
Expand Down
39 changes: 19 additions & 20 deletions src/mixins/openLocal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
* @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
Expand Down Expand Up @@ -36,20 +36,6 @@ export default {
startOpenLocalProcess() {
this.showOpenLocalConfirmation()
},
async unlockAndOpenLocally() {
if (this.openingLocally) {
let shouldContinue = true
try {
await this.unlockFile()
} catch (e) {
shouldContinue = e.response.status === 400
}

if (shouldContinue) {
this.openLocally()
}
}
},

showOpenLocalConfirmation() {
window.OC.dialogs.confirmDestructive(
Expand All @@ -66,8 +52,20 @@ export default {
return
}
this.openingLocally = true
this.sendPostMessage('Get_Views')
})
this.postMessage.registerPostMessageHandler(this.handleCloseSession)
this.sendPostMessage('Action_Save', {
DontTerminateEdit: false,
DontSaveIfUnmodified: false,
Notify: false,
})
this.sendPostMessage('Close_Session')
},
)
},

handleCloseSession() {
this.postMessage.unregisterPostMessageHandler(this.handleCloseSession)
this.openLocally()
},

showOpenLocalFinished() {
Expand All @@ -91,8 +89,9 @@ export default {
return
}
this.openingLocally = true
this.sendPostMessage('Get_Views')
})
this.openLocally()
},
)
},

unlockFile() {
Expand All @@ -114,7 +113,7 @@ export default {

this.showOpenLocalFinished(url, window.top)
this.close()
window.location.href = url
window.open(url, '_self')
})
}
},
Expand Down
20 changes: 15 additions & 5 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import { NcButton, NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import AlertOctagonOutline from 'vue-material-design-icons/AlertOctagonOutline.vue'
import { loadState } from '@nextcloud/initial-state'
import { showInfo } from '@nextcloud/dialogs'
import ZoteroHint from '../components/Modal/ZoteroHint.vue'
import { basename, dirname } from 'path'
Expand Down Expand Up @@ -173,7 +174,6 @@ export default {
error: null,
errorType: null,
loadingMsg: null,
views: [],
showLinkPicker: false,
showZotero: false,
Expand Down Expand Up @@ -368,10 +368,8 @@ export default {
case 'UI_Close':
this.close()
break
case 'Get_Views_Resp':
case 'Views_List':
this.views = args
this.unlockAndOpenLocally()
case 'Session_Closed':
this.handleSessionClosed(args)
break
case 'UI_SaveAs':
this.saveAs(args.format)
Expand Down Expand Up @@ -443,6 +441,18 @@ export default {
}
},
handleSessionClosed({ Reason }) {
if (Reason !== 'OwnerTermination') {
return
}
if (this.openingLocally) {
return
}
showInfo(t('richdocuments', 'The collaborative editing was terminated by another user'))
this.close()
},
},
}
</script>
Expand Down

0 comments on commit 9ac2677

Please sign in to comment.