]> source.dussan.org Git - nextcloud-server.git/commitdiff
more share permission logic to storage wrapper
authorRobin Appelman <robin@icewind.nl>
Mon, 14 Aug 2023 13:50:05 +0000 (15:50 +0200)
committerRobin Appelman <robin@icewind.nl>
Mon, 4 Sep 2023 12:09:41 +0000 (14:09 +0200)
this way we only have to determine the share permissions once

Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_sharing/tests/ApiTest.php
lib/private/Files/FileInfo.php
lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
lib/private/Files/SetupManager.php
lib/private/Files/Storage/Home.php
lib/public/Files/IHomeStorage.php

index d7661297e9e860de1d0d8f1f72d3a412de3fad34..3484bb29d941ddbcb3706ecd586340656cea34df 100644 (file)
@@ -36,6 +36,8 @@
 namespace OCA\Files_Sharing\Tests;
 
 use OC\Files\Cache\Scanner;
+use OC\Files\Filesystem;
+use OC\Files\SetupManager;
 use OCA\Files_Sharing\Controller\ShareAPIController;
 use OCP\App\IAppManager;
 use OCP\AppFramework\OCS\OCSBadRequestException;
@@ -74,6 +76,8 @@ class ApiTest extends TestCase {
                \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no');
                \OC::$server->getConfig()->setAppValue('core', 'shareapi_expire_after_n_days', '7');
 
+               Filesystem::getLoader()->removeStorageWrapper('sharing_mask');
+
                $this->folder = self::TEST_FOLDER_NAME;
                $this->subfolder = '/subfolder_share_api_test';
                $this->subsubfolder = '/subsubfolder_share_api_test';
index 2b6b83a25462cc564ae812e408685a403e364472..b3c4629e2b23c25b8ed748b641f196f550303a54 100644 (file)
@@ -231,7 +231,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
        }
 
        /**
-        * Return the currently version used for the HMAC in the encryption app
+        * Return the current version used for the HMAC in the encryption app
         */
        public function getEncryptedVersion(): int {
                return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
@@ -241,11 +241,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
         * @return int
         */
        public function getPermissions() {
-               $perms = (int) $this->data['permissions'];
-               if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
-                       $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
-               }
-               return $perms;
+               return (int) $this->data['permissions'];
        }
 
        /**
index 824adcc1d0e22ead9cb935680a68290a94a2586b..b361249ff477130e37e1ebf65a27e998e817aa35 100644 (file)
@@ -26,6 +26,7 @@
 namespace OC\Files\ObjectStore;
 
 use OC\User\User;
+use OCP\IUser;
 
 class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
        /**
@@ -61,7 +62,7 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IH
         * @param string $path, optional
         * @return \OC\User\User
         */
-       public function getUser($path = null) {
+       public function getUser($path = null): IUser {
                return $this->user;
        }
 }
index 01ce4a1cc59923c44c4d9ab8630b494443bb956f..47c58dd18da7092e5b725e397b015934d75ae6ef 100644 (file)
@@ -34,9 +34,11 @@ use OC\Files\Storage\Wrapper\Encoding;
 use OC\Files\Storage\Wrapper\PermissionsMask;
 use OC\Files\Storage\Wrapper\Quota;
 use OC\Lockdown\Filesystem\NullStorage;
+use OC\Share\Share;
 use OC_App;
 use OC_Hook;
 use OC_Util;
+use OCA\Files_Sharing\ISharedStorage;
 use OCP\Constants;
 use OCP\Diagnostics\IEventLogger;
 use OCP\EventDispatcher\IEventDispatcher;
@@ -60,6 +62,7 @@ use OCP\IUserManager;
 use OCP\IUserSession;
 use OCP\Lockdown\ILockdownManager;
 use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\IManager;
 use Psr\Log\LoggerInterface;
 
 class SetupManager {
@@ -139,8 +142,17 @@ class SetupManager {
                        return $storage;
                });
 
-               Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
-                       if (!$mount->getOption('enable_sharing', true)) {
+               Filesystem::addStorageWrapper('sharing_mask', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
+                       $reSharingEnabled = Share::isResharingAllowed();
+                       $sharingEnabledForMount = $mount->getOption('enable_sharing', true);
+                       /** @var IUserSession $userSession */
+                       $userSession = \OC::$server->get(IUserSession::class);
+                       $user = $userSession->getUser();
+                       /** @var IManager $shareManager */
+                       $shareManager = \OC::$server->get(IManager::class);
+                       $sharingEnabledForUser = $user ? !$shareManager->sharingDisabledForUser($user->getUID()) : true;
+                       $isShared = $storage->instanceOfStorage(ISharedStorage::class);
+                       if (!$sharingEnabledForMount || !$sharingEnabledForUser || (!$reSharingEnabled && $isShared)) {
                                return new PermissionsMask([
                                        'storage' => $storage,
                                        'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
index 5427bc425c2622d812be2873787324af5b2b5199..5100b15215b9ade6217c6bf2e9a1601aec9ef2b1 100644 (file)
@@ -26,6 +26,7 @@
 namespace OC\Files\Storage;
 
 use OC\Files\Cache\HomePropagator;
+use OCP\IUser;
 
 /**
  * Specialized version of Local storage for home directory usage
@@ -94,7 +95,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
         *
         * @return \OC\User\User owner of this home storage
         */
-       public function getUser() {
+       public function getUser(): IUser {
                return $this->user;
        }
 
index 7eb3ffc4a24ec58d4e7390a9e2d28e510dd96cb8..1fea80f2d87c3b9d924bd1beab6dd32a11dfc6ee 100644 (file)
@@ -27,6 +27,7 @@
 namespace OCP\Files;
 
 use OCP\Files\Storage\IStorage;
+use OCP\IUser;
 
 /**
  * Interface IHomeStorage
@@ -34,4 +35,11 @@ use OCP\Files\Storage\IStorage;
  * @since 7.0.0
  */
 interface IHomeStorage extends IStorage {
+       /**
+        * Get the user for this home storage
+        *
+        * @return IUser
+        * @since 28.0.0
+        */
+       public function getUser(): IUser;
 }