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

[stable27] fix: Use Close_Session post message to properly end the Collabora editing before opening locally #3602

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 <jus@bitgrid.net>
* @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
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
Loading