From c7e922262180f05891bb32426e2743bf257e2911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 12 Apr 2019 11:33:32 +0200 Subject: [PATCH] Implement hide download support for public shares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/database.xml | 6 ++++++ appinfo/info.xml | 2 +- lib/Controller/WopiController.php | 5 ++++- lib/Db/Wopi.php | 4 ++++ lib/Db/WopiMapper.php | 3 ++- lib/TokenManager.php | 3 ++- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/appinfo/database.xml b/appinfo/database.xml index 9d19a070e..1a33e72f1 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -130,6 +130,12 @@ false 4 + + hide_download + boolean + false + true + rd_wopi_token_idx diff --git a/appinfo/info.xml b/appinfo/info.xml index cde1ff4cd..37406a093 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,7 +4,7 @@ Collabora Online Edit office documents directly in your browser. This application can connect to a Collabora Online server (WOPI Client). Nextcloud is the WOPI Host. Please read the documentation to learn more about that. - 3.2.4 + 3.2.4-1 agpl Collabora Productivity based on work of Frank Karlitschek, Victor Dubiniuk diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 0156c20c2..d76199474 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -154,7 +154,10 @@ class WopiController extends Controller { 'LastModifiedTime' => Helper::toISO8601($file->getMTime()), 'EnableInsertRemoteImage' => true, 'EnableShare' => true, - 'HideUserList' => 'desktop' + 'HideUserList' => 'desktop', + 'DisablePrint' => $wopi->getHideDownload(), + 'DisableExport' => $wopi->getHideDownload(), + 'DisableCopy' => $wopi->getHideDownload() ]; if ($wopi->isTemplateToken()) { diff --git a/lib/Db/Wopi.php b/lib/Db/Wopi.php index 941e241b7..0c35dacf3 100644 --- a/lib/Db/Wopi.php +++ b/lib/Db/Wopi.php @@ -81,6 +81,9 @@ class Wopi extends Entity { /** @var int */ protected $templateDestination; + /** @var bool */ + protected $hideDownload; + public function __construct() { $this->addType('owner_uid', 'string'); $this->addType('editor_uid', 'string'); @@ -92,6 +95,7 @@ class Wopi extends Entity { $this->addType('expiry', 'int'); $this->addType('guest_displayname', 'string'); $this->addType('templateDestination', 'int'); + $this->addType('hide_download', 'bool'); } public function isTemplateToken() { diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index 01dfded3c..f14df1818 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -64,7 +64,7 @@ class WopiMapper extends Mapper { * @param int $templateDestination * @return Wopi */ - public function generateFileToken($fileId, $owner, $editor, $version, $updatable, $serverHost, $guestDisplayname, $templateDestination = 0) { + public function generateFileToken($fileId, $owner, $editor, $version, $updatable, $serverHost, $guestDisplayname, $templateDestination = 0, $hideDownload = false) { $token = $this->random->generate(32, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); $wopi = Wopi::fromParams([ @@ -78,6 +78,7 @@ class WopiMapper extends Mapper { 'expiry' => $this->timeFactory->getTime() + self::TOKEN_LIFETIME_SECONDS, 'guestDisplayname' => $guestDisplayname, 'templateDestination' => $templateDestination, + 'hideDownload' => $hideDownload ]); /** @var Wopi $wopi */ diff --git a/lib/TokenManager.php b/lib/TokenManager.php index 1267569a7..a332aced1 100644 --- a/lib/TokenManager.php +++ b/lib/TokenManager.php @@ -94,6 +94,7 @@ class TokenManager { $rootFolder = $this->rootFolder; $share = $this->shareManager->getShareByToken($shareToken); $updatable = (bool)($share->getPermissions() & \OCP\Constants::PERMISSION_UPDATE); + $hideDownload = $share->getHideDownload(); $owneruid = $share->getShareOwner(); } else if (!is_null($this->userId)) { try { @@ -156,7 +157,7 @@ class TokenManager { $guest_name = NULL; } - $wopi = $this->wopiMapper->generateFileToken($fileId, $owneruid, $editoruid, $version, (int)$updatable, $serverHost, $guest_name); + $wopi = $this->wopiMapper->generateFileToken($fileId, $owneruid, $editoruid, $version, (int)$updatable, $serverHost, $guest_name, 0, $hideDownload); try {