Skip to content

Commit 1468eff

Browse files
committed
saving with extra permissions
1 parent cd4793f commit 1468eff

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

controller/callbackcontroller.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,6 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
466466
$user = $this->userManager->get($userId);
467467
if (!empty($user)) {
468468
\OC_User::setUserId($userId);
469-
\OC_Util::setupFS($userId);
470-
471-
if ($userId === $hashData->userId) {
472-
$filePath = $hashData->filePath;
473-
}
474469
} else {
475470
if (empty($shareToken)) {
476471
$this->logger->error("Track without token: $fileId status $status", ["app" => $this->appName]);
@@ -480,20 +475,36 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
480475
$this->logger->debug("Track $fileId by token for $userId", ["app" => $this->appName]);
481476
}
482477

478+
// owner of file from the callback link
479+
$ownerId = $hashData->ownerId;
480+
$owner = $this->userManager->get($ownerId);
481+
482+
if (!empty($owner)) {
483+
$userId = $ownerId;
484+
} else {
485+
$callbackUserId = $hashData->userId;
486+
$callbackUser = $this->userManager->get($callbackUserId);
487+
488+
if (!empty($callbackUser)) {
489+
// author of the callback link
490+
$userId = $callbackUserId;
491+
492+
// path for author of the callback link
493+
$filePath = $hashData->filePath;
494+
}
495+
}
496+
497+
if (!empty($userId)) {
498+
\OC_Util::setupFS($userId);
499+
}
500+
483501
list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId, $filePath) : $this->getFileByToken($fileId, $shareToken);
484502

485503
if (isset($error)) {
486504
$this->logger->error("track error $fileId " . json_encode($error->getData()), ["app" => $this->appName]);
487505
return $error;
488506
}
489507

490-
if (empty($user)) {
491-
$owner = $file->getFileInfo()->getOwner();
492-
if ($owner !== null) {
493-
\OC_Util::setupFS($owner->getUID());
494-
}
495-
}
496-
497508
$url = $this->config->ReplaceDocumentServerUrlToInternal($url);
498509

499510
$prevVersion = $file->getFileInfo()->getMtime();

controller/editorapicontroller.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
391391
&& (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
392392
$params["document"]["permissions"]["edit"] = $editable;
393393
if (($editable || $restrictedEditing) && ($canEdit || $canFillForms)) {
394-
$hashCallback = $this->crypt->GetHash(["userId" => $userId, "fileId" => $file->getId(), "filePath" => $filePath, "shareToken" => $shareToken, "action" => "track"]);
394+
$ownerId = null;
395+
$owner = $file->getOwner();
396+
if (!empty($owner)) {
397+
$ownerId = $owner->getUID();
398+
}
399+
400+
$hashCallback = $this->crypt->GetHash(["userId" => $userId, "ownerId" => $ownerId, "fileId" => $file->getId(), "filePath" => $filePath, "shareToken" => $shareToken, "action" => "track"]);
395401
$callback = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.track", ["doc" => $hashCallback]);
396402

397403
if (!empty($this->config->GetStorageUrl())) {

0 commit comments

Comments
 (0)