Skip to content

Commit ea2be66

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 ea2be66

2 files changed

Lines changed: 21 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

tests/stub.phpstub

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ namespace Doctrine\DBAL\Platforms {
5252
}
5353

5454
namespace OCA\Files_Sharing {
55+
use OCP\Files\Mount\IMountPoint;
5556
use OCP\Files\Storage\IStorage;
5657
use \OCP\Share\IShare;
5758

5859
abstract class SharedStorage implements IStorage {
5960
public function getShare(): IShare {
6061
}
6162
}
63+
64+
abstract class SharedMount implements IMountPoint {
65+
public function getShare(): IShare {
66+
}
67+
}
6268
}
6369

6470
namespace OCA\Files_Sharing\Event {

0 commit comments

Comments
 (0)