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:
authorVincent Petry <vincent@nextcloud.com>2022-05-18 15:54:27 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-07-28 17:53:22 +0300
commita95c19e14b5a371240392de480278ee97c01ab12 (patch)
treec96d6efaa88d234cdc3393e5004fd27cfc174ebe /apps/files_sharing/lib/Controller/ShareAPIController.php
parentee23f41abe2fd53d00f44d9c16ebd722ac93e9a3 (diff)
Add share attributes + prevent download permission
Makes it possible to store download permission Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareAPIController.php')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index fafdb1a64cd..e40aed0da70 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 OCA\DAV\DAV\ViewOnlyPlugin;
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
use OCA\Files\Helper;
@@ -324,6 +325,11 @@ class ShareAPIController extends OCSController {
$result['mail_send'] = $share->getMailSend() ? 1 : 0;
$result['hide_download'] = $share->getHideDownload() ? 1 : 0;
+ $result['attributes'] = null;
+ if ($attributes = $share->getAttributes()) {
+ $result['attributes'] = \json_encode($attributes->toArray());
+ }
+
return $result;
}
@@ -674,6 +680,8 @@ class ShareAPIController extends OCSController {
$share->setNote($note);
}
+ $share = $this->setShareAttributes($share, $this->request->getParam('attributes', null));
+
try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
@@ -1216,6 +1224,8 @@ class ShareAPIController extends OCSController {
}
}
+ $share = $this->setShareAttributes($share, $this->request->getParam('attributes', null));
+
try {
$share = $this->shareManager->updateShare($share);
} catch (GenericShareException $e) {
@@ -1832,4 +1842,25 @@ class ShareAPIController extends OCSController {
}
}
}
+
+ /**
+ * @param IShare $share
+ * @param string[][]|null $formattedShareAttributes
+ * @return IShare modified share
+ */
+ private function setShareAttributes(IShare $share, $formattedShareAttributes) {
+ $newShareAttributes = $this->shareManager->newShare()->newAttributes();
+ if ($formattedShareAttributes !== null) {
+ foreach ($formattedShareAttributes as $formattedAttr) {
+ $newShareAttributes->setAttribute(
+ $formattedAttr['scope'],
+ $formattedAttr['key'],
+ (bool) \json_decode($formattedAttr['enabled'])
+ );
+ }
+ }
+ $share->setAttributes($newShareAttributes);
+
+ return $share;
+ }
}