Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate attributes when resharing #34502

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
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: 24 additions & 28 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ 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 @@ -687,16 +692,11 @@ 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 @@ -1112,24 +1112,10 @@ public function updateShare(
$share->setNote($note);
}

$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)) {
/** @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);
}
}
if ($attributes !== null) {
$share = $this->setShareAttributes($share, $attributes);
}
$this->checkInheritedAttributes($share);

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

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

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

private function checkInheritedAttributes(IShare $share): void {
if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
$storage = $share->getNode()->getStorage();
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 ($storage instanceof Wrapper) {
$storage = $storage->getInstanceOfStorage(SharedStorage::class);
if ($storage === null) {
Expand All @@ -1926,6 +1917,11 @@ 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
Loading