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 24, 2024
1 parent b64b589 commit eb4ef48
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 21 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');
}
}
}
4 changes: 2 additions & 2 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export default {
},
fontHint() {
return t('richdocuments', 'Make sure to set this URL: {url} in the coolwsd.xml file of your Collabora Online server to ensure the added fonts get loaded automatically.',
{ url: this.fontHintUrl }
{ url: this.fontHintUrl },
)
},
fontXmlHint() {
Expand Down Expand Up @@ -658,7 +658,7 @@ export default {
try {
const result = await axios.post(
generateFilePath('richdocuments', 'ajax', 'admin.php'),
data
data,
)
this.updating = false
Expand Down
2 changes: 1 addition & 1 deletion src/components/SettingsSelectGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default {
}
}
return this.groups[id]
}
},
)
},
update() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SettingsSelectTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default {
},
getValueObject() {
return this.value.filter((tag) => tag !== '').map(
(id) => this.tags.find((tag) => tag.id === id)
(id) => this.tags.find((tag) => tag.id === id),
)
},
update() {
Expand Down
12 changes: 6 additions & 6 deletions src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const documentsMain = {
title += `_${version}`
}
documentsMain.UI.showViewer(
fileId, title
fileId, title,
)
}
break
Expand Down Expand Up @@ -463,7 +463,7 @@ const documentsMain = {
case 'rev-history':
documentsMain.UI.loadRevViewerContainer()
documentsMain.UI.showViewer(
documentsMain.fileId, documentsMain.title
documentsMain.fileId, documentsMain.title,
)
break
case 'RD_Version_Restored':
Expand Down Expand Up @@ -516,7 +516,7 @@ const documentsMain = {
},
true,
t('richdocuments', 'New filename'),
false
false,
).then(function() {
const $dialog = $('.oc-dialog:visible')
const $buttons = $dialog.find('.oc-dialog-buttonrow button')
Expand Down Expand Up @@ -575,7 +575,7 @@ const documentsMain = {
}
documentsMain.openingLocally = true
PostMessages.sendWOPIPostMessage('loolframe', 'Get_Views')
}
},
)
},

Expand Down Expand Up @@ -606,7 +606,7 @@ const documentsMain = {

axios.post(
OC.linkToOCS('apps/files/api/v1', 2) + 'openlocaleditor?format=json',
{ path: documentsMain.fullPath }
{ path: documentsMain.fullPath },
).then((result) => {
const url = 'nc://open/'
+ Config.get('userId') + '@' + getNextcloudUrl()
Expand All @@ -633,7 +633,7 @@ const documentsMain = {
_window.location = url
this.showOpenLocalConfirmation(url, _window)
}
}
},
)
},

Expand Down
6 changes: 2 additions & 4 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const odfViewer = {
timeout: 0,
})
}
}
},
)
return
}
Expand Down 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 Expand Up @@ -293,7 +291,7 @@ addEventListener('DOMContentLoaded', () => {
})
odfViewer.onClose()
OC.Notification.showTemporary(t('richdocuments', 'Failed to connect to {productName}. Please try again later or contact your server administrator.',
{ productName: OC.getCapabilities().richdocuments.productName }
{ productName: OC.getCapabilities().richdocuments.productName },
))
}
break
Expand Down
18 changes: 18 additions & 0 deletions src/helpers/isDocument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
13 changes: 13 additions & 0 deletions src/helpers/isPublicPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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
1 change: 0 additions & 1 deletion src/helpers/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]>
*
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const getDocumentUrlFromTemplate = (templateId, fileName, fileDir, fillWithTempl
fileName,
dir: fileDir,
requesttoken: OC.requestToken,
}
},
)
}

Expand All @@ -88,7 +88,7 @@ const getDocumentUrlForPublicFile = (fileName, fileId) => {
fileName,
fileId,
requesttoken: OC.requestToken,
}
},
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/mixins/saveAs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
},
true,
t('richdocuments', 'New filename'),
false
false,
).then(() => {
const $dialog = $('.oc-dialog:visible')
const $buttons = $dialog.find('.oc-dialog-buttonrow button')
Expand Down
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/FilesAppIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export default {
},
true,
t('richdocuments', 'New filename'),
false
false,
).then(function() {
const $dialog = parent.$('.oc-dialog:visible')
const $buttons = $dialog.find('button')
Expand Down
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 eb4ef48

Please sign in to comment.