Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareAPIController.php')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php67
1 files changed, 41 insertions, 26 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index c72fd8ba8af..59089390667 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -45,6 +45,7 @@ declare(strict_types=1);
namespace OCA\Files_Sharing\Controller;
use OC\Files\FileInfo;
+use OC\Files\Storage\Wrapper\Wrapper;
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
use OCA\Files_Sharing\SharedStorage;
@@ -524,14 +525,7 @@ class ShareAPIController extends OCSController {
$permissions &= ~($permissions & ~$node->getPermissions());
}
- if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
- /** @var \OCA\Files_Sharing\SharedStorage $storage */
- $inheritedAttributes = $share->getNode()->getStorage()->getShare()->getAttributes();
- if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
- $share->setHideDownload(true);
- }
- }
-
+ $this->checkInheritedAttributes($share);
if ($shareType === IShare::TYPE_USER) {
// Valid user is required to share
@@ -1110,6 +1104,25 @@ class ShareAPIController extends OCSController {
$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);
+ }
+ }
+ }
+
/**
* expirationdate, password and publicUpload only make sense for link shares
*/
@@ -1135,24 +1148,6 @@ class ShareAPIController extends OCSController {
$share->setHideDownload(false);
}
- $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->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 increate permissions'));
- }
- $share->setHideDownload(true);
- }
- }
- }
-
$newPermissions = null;
if ($publicUpload === 'true') {
$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
@@ -1905,4 +1900,24 @@ class ShareAPIController extends OCSController {
return $share;
}
+
+ private function checkInheritedAttributes(IShare $share): void {
+ if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
+ $storage = $share->getNode()->getStorage();
+ if ($storage instanceof Wrapper) {
+ $storage = $storage->getInstanceOfStorage(SharedStorage::class);
+ if ($storage === null) {
+ throw new \RuntimeException('Should not happen, instanceOfStorage but getInstanceOfStorage return null');
+ }
+ } else {
+ throw new \RuntimeException('Should not happen, instanceOfStorage but not a wrapper');
+ }
+ /** @var \OCA\Files_Sharing\SharedStorage $storage */
+ $inheritedAttributes = $storage->getShare()->getAttributes();
+ if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
+ $share->setHideDownload(true);
+ }
+ }
+
+ }
}