Skip to content

Commit

Permalink
fix: use office.vue for public shares
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Apr 23, 2024
1 parent 3a0c514 commit 33d835c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 4 deletions.
13 changes: 12 additions & 1 deletion cypress/e2e/share-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ describe('Public sharing of office documents', function() {
cy.spy(win, 'postMessage').as('postMessage')
},
})
cy.waitForCollabora(true)

cy.waitForCollabora()
cy.get('@postMessage', { timeout: 20000 }).should(spy => {
const calls = spy.getCalls()
const findMatchingCall = calls.find(call => call.args[0].indexOf('"MessageId":"App_LoadingStatus"') !== -1)
if (!findMatchingCall) {
return expect(findMatchingCall).to.not.be.undefined
}
const object = JSON.parse(findMatchingCall.args[0])
expect(object.Values).to.have.property('Status', 'Initialized')
})

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})
Expand Down
1 change: 1 addition & 0 deletions lib/Listener/ShareLinkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function handle(Event $event): void {
$this->initialStateService->provideCapabilities();
Util::addScript('richdocuments', 'richdocuments-files');
Util::addScript('richdocuments', 'richdocuments-viewer', 'viewer');
Util::addScript('richdocuments', 'richdocuments-public');
}
}
}
2 changes: 0 additions & 2 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ addEventListener('DOMContentLoaded', () => {
return
}

odfViewer.onEdit(document.getElementById('filename').value)

PostMessages.registerPostMessageHandler(({ parsed }) => {
console.debug('[viewer] Received post message', parsed)
const { msgId, args, deprecated } = parsed
Expand Down
17 changes: 17 additions & 0 deletions src/helpers/isDocument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getCapabilities } from '@nextcloud/capabilities'

/** @type Array.<String> */
const mimetypes = getCapabilities().richdocuments.mimetypes

/**
* Determines if the mimetype of the resource is supported by richdocuments
* @return {boolean}
*/
function isDocument() {
/** @type HTMLInputElement */
const mimetypeElement = document.getElementById('mimetype')

return Boolean(mimetypeElement) && mimetypes.includes(mimetypeElement.value)
}

export default isDocument
12 changes: 12 additions & 0 deletions src/helpers/isPublicPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Determines if the resource is a public share
* @return {boolean}
*/
function isPublic() {
/** @type HTMLInputElement */
const publicElement = document.getElementById('isPublic')

return Boolean(publicElement) && publicElement.value === '1'
}

export default isPublic
17 changes: 17 additions & 0 deletions src/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import isPublic from './helpers/isPublicPage.js'
import isDocument from './helpers/isDocument.js'

document.addEventListener('DOMContentLoaded', () => {

// Public share, but not a supported mimetype - do nothing
if (isPublic() && !isDocument()) {
return
}

// Public share, and is a supported mimetype - open viewer
if (isPublic() && isDocument()) {
if (OCA.Viewer) {
OCA.Viewer.open({ path: '/' })
}
}
})
2 changes: 1 addition & 1 deletion src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default {
}
this.postMessage.registerPostMessageHandler(this.postMessageHandler)
this.load()
await this.load()
},
beforeDestroy() {
this.postMessage.unregisterPostMessageHandler(this.postMessageHandler)
Expand Down
1 change: 1 addition & 0 deletions webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ webpackConfig.entry = {
admin: path.join(__dirname, 'src', 'admin.js'),
personal: path.join(__dirname, 'src', 'personal.js'),
reference: path.join(__dirname, 'src', 'reference.js'),
public: path.join(__dirname, 'src', 'public.js'),
}

webpackRules.RULE_JS.test = /\.m?js$/
Expand Down

0 comments on commit 33d835c

Please sign in to comment.