Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,6 @@ public function createShare(
$permissions &= ~($permissions & ~$node->getPermissions());
}

if ($attributes !== null) {
$share = $this->setShareAttributes($share, $attributes);
}

$share->setSharedBy($this->currentUser);
$this->checkInheritedAttributes($share);

if ($shareType === IShare::TYPE_USER) {
Expand Down Expand Up @@ -684,11 +679,16 @@ public function createShare(
}

$share->setShareType($shareType);
$share->setSharedBy($this->currentUser);

if ($note !== '') {
$share->setNote($note);
}

if ($attributes !== null) {
$share = $this->setShareAttributes($share, $attributes);
}

try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
Expand Down Expand Up @@ -1104,10 +1104,24 @@ public function updateShare(
$share->setNote($note);
}

if ($attributes !== null) {
$share = $this->setShareAttributes($share, $attributes);
$userFolder = $this->rootFolder->getUserFolder($this->currentUser);

// get the node with the point of view of the current user
$nodes = $userFolder->getById($share->getNode()->getId());
if (count($nodes) > 0) {
$node = $nodes[0];
$storage = $node->getStorage();
if ($storage && $storage->instanceOfStorage(SharedStorage::class)) {

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType

Docblock-defined type OCP\Files\Storage\IStorage for $storage is never falsy
/** @var \OCA\Files_Sharing\SharedStorage $storage */
$inheritedAttributes = $storage->getShare()->getAttributes();
if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
if ($hideDownload === 'false') {
throw new OCSBadRequestException($this->l->t('Cannot increase permissions'));
}
$share->setHideDownload(true);
}
}
}
$this->checkInheritedAttributes($share);

/**
* expirationdate, password and publicUpload only make sense for link shares
Expand Down Expand Up @@ -1239,6 +1253,10 @@ public function updateShare(
}
}

if ($attributes !== null) {
$share = $this->setShareAttributes($share, $attributes);
}

try {
$share = $this->shareManager->updateShare($share);
} catch (GenericShareException $e) {
Expand Down Expand Up @@ -1884,17 +1902,8 @@ private function setShareAttributes(IShare $share, ?string $attributesString) {
}

private function checkInheritedAttributes(IShare $share): void {
if (!$share->getSharedBy()) {
return; // Probably in a test
}
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
$nodes = $userFolder->getById($share->getNodeId());
if (empty($nodes)) {
return;
}
$node = $nodes[0];
if ($node->getStorage()->instanceOfStorage(SharedStorage::class)) {
$storage = $node->getStorage();
if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
$storage = $share->getNode()->getStorage();
if ($storage instanceof Wrapper) {
$storage = $storage->getInstanceOfStorage(SharedStorage::class);
if ($storage === null) {
Expand All @@ -1907,11 +1916,6 @@ private function checkInheritedAttributes(IShare $share): void {
$inheritedAttributes = $storage->getShare()->getAttributes();
if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
$share->setHideDownload(true);
$attributes = $share->getAttributes();
if ($attributes) {
$attributes->setAttribute('permissions', 'download', false);
$share->setAttributes($attributes);
}
}
}

Expand Down