Skip to content

Commit

Permalink
Show error when trying to open a shared PDF without download permissions
Browse files Browse the repository at this point in the history
In order to show a PDF file it needs to be downloaded. Therefore, if a
shared PDF file does not have download permissions it is not possible to
show it, so now an error is shown instead.

The error is a custom one rather than a standard error from the viewer
(although with the same appearance) to better explain the reason.

Note that the error is shown only when the PDF file is loaded through
the viewer, which should be always the case. There is a fallback to
inject the UI in public shares in case the viewer is not available, but
handling the error also in that case was not trivial and that fallback
should never be used anyway, so it was not taken into account.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Dec 7, 2024
1 parent 6e5a8ed commit 152cfc2
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<iframe ref="iframe"
<iframe v-if="isDownloadable"
ref="iframe"
:src="iframeSrc"
@load="onIFrameLoaded" />
<div v-else id="emptycontent">
<div class="icon-error" />
<h3>{{ t('files_pdfviewer', 'To view a shared PDF file, the download needs to be allowed for this file share') }}</h3>
</div>
</template>

<script>
Expand Down Expand Up @@ -41,12 +46,32 @@ export default {
return this.fileList.find((file) => file.fileid === this.fileid)
},

isDownloadable() {
if (!this.file.shareAttributes) {
return true
}

const shareAttributes = JSON.parse(this.file.shareAttributes)
const downloadPermissions = shareAttributes.find(({ scope, key }) => scope === 'permissions' && key === 'download')
if (downloadPermissions) {
return downloadPermissions.value
}

return true
},

isEditable() {
return this.file?.permissions?.indexOf('W') >= 0
},
},

async mounted() {
if (!this.isDownloadable) {
this.doneLoading()

return
}

document.addEventListener('webviewerloaded', this.handleWebviewerloaded)

if (isPublicPage() && isPdf()) {
Expand Down Expand Up @@ -186,6 +211,12 @@ export default {
</script>

<style lang="scss" scoped>
#emptycontent {
margin: 0;
padding: 10% 5%;
background-color: var(--color-main-background);
}

iframe {
width: 100%;
height: calc(100vh - var(--header-height));
Expand Down

0 comments on commit 152cfc2

Please sign in to comment.