Skip to content

Commit 89ef31c

Browse files
committed
fix(Wopi): fall back to super share if share token is not available
On internal shares the controller is called without the share token. But necessary information, like share attributes, might be necessary to know and are available from the super share of the SharedMount in that case. Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 4425504 commit 89ef31c

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/Controller/WopiController.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace OCA\Richdocuments\Controller;
77

8+
use OCA\Files_Sharing\SharedMount;
89
use OCA\Files_Versions\Versions\IVersionManager;
910
use OCA\Richdocuments\AppConfig;
1011
use OCA\Richdocuments\AppInfo\Application;
@@ -219,7 +220,7 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
219220
$response['TemplateSource'] = $this->getWopiUrlForTemplate($wopi);
220221
}
221222

222-
$share = $this->getShareForWopiToken($wopi);
223+
$share = $this->getShareForWopiToken($wopi, $file);
223224
if ($this->permissionManager->shouldWatermark($file, $wopi->getEditorUid(), $share)) {
224225
$email = $user !== null && !$isPublic ? $user->getEMailAddress() : '';
225226
$currentDateTime = new \DateTime(
@@ -925,9 +926,20 @@ private function getFileForWopiToken(Wopi $wopi) {
925926
return array_shift($files);
926927
}
927928

928-
private function getShareForWopiToken(Wopi $wopi): ?IShare {
929+
private function getShareForWopiToken(Wopi $wopi, File $file): ?IShare {
929930
try {
930-
return $wopi->getShare() ? $this->shareManager->getShareByToken($wopi->getShare()) : null;
931+
$shareToken = $wopi->getShare();
932+
if ($shareToken) {
933+
return $this->shareManager->getShareByToken($shareToken);
934+
}
935+
936+
// on internal shares the token is not stored, but we can use the
937+
// super share. It is not a specific share, but a cumulative one and#
938+
//carries necessary information
939+
$mount = $file->getMountPoint();
940+
if ($mount instanceof SharedMount) {
941+
return $mount->getShare();
942+
}
931943
} catch (ShareNotFound) {
932944
}
933945

0 commit comments

Comments
 (0)