From 320cc48c60f4e726218fff9cf28e39fa13596d7b Mon Sep 17 00:00:00 2001 From: llj Date: Wed, 17 Jul 2019 17:34:22 +0800 Subject: [PATCH] [shared file view] added modification for 'preview only' (#3867) --- .../shared-file-view/shared-file-view.js | 19 +++++++++++++++++-- seahub/templates/shared_file_view_react.html | 14 +++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/shared-file-view/shared-file-view.js b/frontend/src/components/shared-file-view/shared-file-view.js index 34fcf7edd4..fc4b61cc05 100644 --- a/frontend/src/components/shared-file-view/shared-file-view.js +++ b/frontend/src/components/shared-file-view/shared-file-view.js @@ -15,7 +15,7 @@ const propTypes = { }; let loginUser = window.app.pageOptions.name; -const { repoID, sharedToken, trafficOverLimit, fileName, fileSize, sharedBy, siteName, enableWatermark, download, zipped, filePath } = window.shared.pageOptions; +const { repoID, sharedToken, trafficOverLimit, fileName, fileSize, sharedBy, siteName, enableWatermark, canDownload, zipped, filePath } = window.shared.pageOptions; class SharedFileView extends React.Component { @@ -50,6 +50,21 @@ class SharedFileView extends React.Component { duration: 3 }); } + if (!canDownload) { + document.addEventListener('contextmenu', function(e) { + e.preventDefault(); + return false; + }); + document.addEventListener('keydown', function(e) { + // prevent ctrl + s/p/a/c, i.e, 'save', 'print', 'select all', 'copy' + // metaKey: for mac + if ((e.ctrlKey || e.metaKey) && (e.which == 83 || e.which == 80 || e.which == 65 || e.which == 67)) { + e.preventDefault(); + e.stopPropagation(); + return false; + } + }); + } } renderPath = () => { @@ -91,7 +106,7 @@ class SharedFileView extends React.Component {

{gettext('Shared by:')}{' '}{sharedBy}

} - {download && + {canDownload &&
{(loginUser && loginUser !== sharedBy) &&