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

Show error when trying to open a shared PDF without download permissions #1077

Conversation

danxuliu
Copy link
Member

@danxuliu danxuliu commented Oct 29, 2024

Fixes #649

Although the best fix would be to fallback to Collabora if available currently it does not seem to be possible to do that, so for now just an error message is shown.

Also, while it would be possible to use this.$emit('error') to notify the viewer that the file could not be loaded currently it does not seem possible to customize the message, so the standard Viewer error with Error loading {name of the file} would be shown. In this case it is worth explaning the reason, so the error is handled directly in the PDF viewer instead (but with the markup and style for the error element copied from the viewer). Maybe custom error messages will be possible in the future with the Viewer 4.0 API and then that code can go away :-)

Regarding the error message itself feel free to improve the wording :-) After several tries this is the best I could come up with 🤷

Finally, note that before Nextcloud 28 when the PDF viewer was opened in public pages for a single share the UI was directly injected. When it was changed to use the viewer instead a fallback to directly inject the UI was left just in case the viewer was not available. This pull request only handles the disabled download permissions when the viewer is used, but not in the fallback case:

  • The viewer already provides the needed file info, so handling the error without the viewer is more involved, as the file info would need to be fetched before loading the file in PDF.js, or a handler in PDF.js for loading errors would need to be used (which I have not found how 🤷 I am sure there is an easy way and I just simply missed it, but it is not worth spending more time on that due to the next point)
  • In Nextcloud 31 public.js will go away (in another pull request) because it is no longer needed, so there will be no fallback at all. But also in Nextcloud 28 to 30 the fallback should never be used anyway; the viewer is expected to be always available, and if it is not or it did not properly load then something would need to be fixed, but keeping the fallback was just being overly cautious and it is not really needed.

How to test

  • Share a PDF file with another user
  • Customize the share and disable Allow download and sync
  • In a private window, log in as the other user
  • Open the Files app
  • Open the shared PDF

Result with this pull request

image

Result without this pull request

The PDF viewer is loaded, but contents are empty

@danxuliu
Copy link
Member Author

/compile /

@danxuliu
Copy link
Member Author

/backport to stable30

@danxuliu
Copy link
Member Author

/backport to stable29

@danxuliu
Copy link
Member Author

/backport to stable28

<div v-if="!isDownloadable"
id="emptycontent">
<div class="icon-error" />
<h2>{{ t('files_pdfviewer', 'To view a shared PDF file the sharer needs to allow downloads of the file') }}</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To view a shared PDF file, the owner must allow a download of the file ?

There is also a case, when files_pdfviewer is not in the whitelist of Guests app, and guest account is trying to access it with 403.
Possibly unrelated, but I could follow-up on top of that PR later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To view a shared PDF file, the owner must allow a download of the file ?

Mmm, maybe the person should not be mentioned at all, because if a file is reshared and the owner disallows the download I guess (I have not checked) that it will be disallowed in the reshare, but if the owner allows it and the resharer disallows it then it would be also disallowed 🤔

There is also a case, when files_pdfviewer is not in the whitelist of Guests app, and guest account is trying to access it with 403. Possibly unrelated, but I could follow-up on top of that PR later

Thanks, I was not aware of that. A follow up sounds good :-)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any news on the follow up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR covers all shares (with users, guests, oublic links), where download is disabled.

For guests accounts + shareswith enabled download, it returns 500 Server error, which is correct, and not to be handled by PDF Viewer.
Instead, this app should be whitelisted in admin settings. Issue is tracked here: nextcloud/guests#1249

@danxuliu danxuliu marked this pull request as ready for review October 29, 2024 15:09
@szaimen
Copy link
Collaborator

szaimen commented Dec 6, 2024

Hi @danxuliu, I wanted to test this. Unfortunately when I try to install the pdfviewer dependencies, I run into the following error:
image
I am not sure how to fix this unfortunately.

This should be easily reproducible with

sudo docker run -it --rm \
--name nextcloud-easy-test \
-p 8443:443 \
-e SERVER_BRANCH=master \
-e PDFVIEWER_BRANCH=show-error-when-trying-to-open-a-shared-pdf-without-download-permissions \
-e VIEWER_BRANCH=master \
--volume="nextcloud_easy_test_npm_cache_volume:/var/www/.npm" \
ghcr.io/szaimen/nextcloud-easy-test:latest

@Antreesy
Copy link
Contributor

Antreesy commented Dec 6, 2024

when I try to install the pdfviewer dependencies

Does it work with master/main branch of pdf_viewer? As there is only frontend changes and composer dependencies shouldn't affect it

Tested with Julius' docker, Viewer content is replaced:

@szaimen
Copy link
Collaborator

szaimen commented Dec 6, 2024

@Antreesy since you were able to test this, can you approve or is something missing from your Pov?

"canDownload" inverted the value of the "hideDownload" setting. However,
that was not accurate, as if the download is hidden the file can still
be downloaded. Moreover, it is possible to actually disallow downloads,
which is a different setting (using share attributes) than hiding it.

Therefore, to better differentiate between a hidden download and a
disabled download the previous "canDownload" was renamed (and adjusted
as needed) to "hideDownload".

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
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 <danxuliu@gmail.com>
@Antreesy Antreesy force-pushed the show-error-when-trying-to-open-a-shared-pdf-without-download-permissions branch from 762d781 to 44b9067 Compare December 7, 2024 10:20
@Antreesy
Copy link
Contributor

Antreesy commented Dec 7, 2024

/compile /

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased, recompiled, adjusted wording to user-insensitive: To view a shared PDF file, the download needs to be allowed for this file share

Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
@szaimen
Copy link
Collaborator

szaimen commented Dec 7, 2024

Thanks @Antreesy ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable pdf viewer on files that have download disabled
5 participants