Skip to content

Commit

Permalink
Use the file owner from the share object, if available
Browse files Browse the repository at this point in the history
Fixes nextcloud#85

When a link is shared on external storage and user is not logged in, the
owner returned by the $file object is null. Use owner information from
the $share object whenever available.
  • Loading branch information
pranavk committed Jun 1, 2017
1 parent 8b02a13 commit f08bfea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function getToken($fileId, $shareToken = null) {
$rootFolder = $this->rootFolder;
$share = $this->shareManager->getShareByToken($shareToken);
$updatable = (bool)($share->getPermissions() & \OCP\Constants::PERMISSION_UPDATE);
$owneruid = $share->getShareOwner();
} else {
try {
/** @var File $file */
Expand All @@ -83,10 +84,13 @@ public function getToken($fileId, $shareToken = null) {
}
/** @var File $file */
$file = $rootFolder->getById($fileId)[0];

// If its a public share, use the owner from the share, otherwise check the file object
if (is_null($owneruid)) {
$owneruid = $file->getOwner()->getUID();
}
$row = new Wopi();
$serverHost = $this->urlGenerator->getAbsoluteURL('/');//$this->request->getServerProtocol() . '://' . $this->request->getServerHost();
$token = $row->generateFileToken($fileId, $file->getOwner()->getUID(), $this->userId, $version, (int)$updatable, $serverHost);
$token = $row->generateFileToken($fileId, $owneruid, $this->userId, $version, (int)$updatable, $serverHost);

try {

Expand Down

0 comments on commit f08bfea

Please sign in to comment.