Skip to content

Commit

Permalink
Merge pull request #3604 from nextcloud/backport/3601/stable29
Browse files Browse the repository at this point in the history
[stable29] fix: Use Close_Session post message to properly end the Collabora editing before opening locally
  • Loading branch information
juliusknorr authored Apr 18, 2024
2 parents 0ae2679 + 6395ea7 commit 1651df5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
28 changes: 18 additions & 10 deletions cypress/e2e/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,28 @@ describe('Nextcloud integration', function() {
cy.openFile('document.rtf')
})

it.skip('Open locally', function() {
it('Open locally', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#Open_Local_Editor').click()
})

cy.get('.oc-dialog').should('be.visible')
cy.get('.oc-dialog .oc-dialog-title')
.should('contain', 'Open file locally ')

cy.on('url:changed', (newUrl) => {
expect(newUrl).to.contain('nc://')
})
cy.get('.oc-dialog button.primary').click()

cy.get('.confirmation-dialog').should('be.visible')
cy.get('.confirmation-dialog h1')
.should('contain', 'Open file locally')

cy.intercept({
method: 'POST',
url: '**/openlocaleditor',
}).as('getLocalToken')
cy.window()
.then((window) => {
cy.stub(window, 'open').as('open')
})
cy.get('.confirmation-dialog button:contains("Open locally")').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 @@ -176,6 +176,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
31 changes: 14 additions & 17 deletions src/mixins/openLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,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() {
spawnDialog(
Expand All @@ -66,11 +52,22 @@ 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() {
const fileName = this.filename
spawnDialog(
Expand All @@ -87,7 +84,7 @@ export default {
return
}
this.openingLocally = true
this.sendPostMessage('Get_Views')
this.openLocally()
},
)
},
Expand All @@ -111,7 +108,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 @@ -93,6 +93,7 @@ import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
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 @@ -175,7 +176,6 @@ export default {
error: null,
errorType: null,
loadingMsg: null,
views: [],
showLinkPicker: false,
showZotero: false,
Expand Down Expand Up @@ -371,10 +371,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 @@ -446,6 +444,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 1651df5

Please sign in to comment.