diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-03-24 21:08:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 21:08:15 +0100 |
commit | a7e778b57fb81c8e62d093ece7f0689d34db4c45 (patch) | |
tree | f50492f0380bb21d0cce095231c2560f77b00d36 /apps | |
parent | 00076c07098dbff236d133998de03bee8d4fec33 (diff) | |
parent | 91ab4e1df4f3e234c5e4941d89cf0d9f19166c18 (diff) | |
download | nextcloud-server-a7e778b57fb81c8e62d093ece7f0689d34db4c45.tar.gz nextcloud-server-a7e778b57fb81c8e62d093ece7f0689d34db4c45.zip |
Merge pull request #31265 from nextcloud/fs-limited-setup
Fine grained filesystem setup
Diffstat (limited to 'apps')
11 files changed, 63 insertions, 32 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index 71e833809ac..df4e3c65ce0 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -235,7 +235,6 @@ class Auth extends AbstractBasic { \OC_User::handleApacheAuth() ) { $user = $this->userSession->getUser()->getUID(); - \OC_Util::setupFS($user); $this->currentUser = $user; $this->session->close(); return [true, $this->principalPrefix . $user]; diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index ff96b7a19c5..095fb631c2b 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -31,7 +31,7 @@ */ namespace OCA\DAV\Connector\Sabre; -use OC\Files\Node\Folder; +use OCP\Files\Folder; use OCA\DAV\AppInfo\PluginManager; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCP\Files\Mount\IMountManager; diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index b8eabd65e1e..489192dbdc2 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -40,7 +40,9 @@ use OCA\Files_External\Lib\Backend\InvalidBackend; use OCA\Files_External\Lib\DefinitionParameter; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; +use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\StorageNotAvailableException; use OCP\ILogger; @@ -62,15 +64,24 @@ abstract class StoragesService { */ protected $userMountCache; + protected IEventDispatcher $eventDispatcher; + /** * @param BackendService $backendService * @param DBConfigService $dbConfigService * @param IUserMountCache $userMountCache + * @param IEventDispatcher $eventDispatcher */ - public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { + public function __construct( + BackendService $backendService, + DBConfigService $dbConfigService, + IUserMountCache $userMountCache, + IEventDispatcher $eventDispatcher + ) { $this->backendService = $backendService; $this->dbConfig = $dbConfigService; $this->userMountCache = $userMountCache; + $this->eventDispatcher = $eventDispatcher; } protected function readDBConfig() { @@ -338,7 +349,8 @@ abstract class StoragesService { * @param string $mountType hook mount type param * @param array $applicableArray array of applicable users/groups for which to trigger the hook */ - protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { + protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void { + $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null)); foreach ($applicableArray as $applicable) { \OCP\Util::emitHook( Filesystem::CLASSNAME, diff --git a/apps/files_external/lib/Service/UserGlobalStoragesService.php b/apps/files_external/lib/Service/UserGlobalStoragesService.php index ba894d8f210..2eda36e9242 100644 --- a/apps/files_external/lib/Service/UserGlobalStoragesService.php +++ b/apps/files_external/lib/Service/UserGlobalStoragesService.php @@ -24,6 +24,7 @@ namespace OCA\Files_External\Service; use OCA\Files_External\Lib\StorageConfig; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; use OCP\IGroupManager; use OCP\IUser; @@ -45,15 +46,17 @@ class UserGlobalStoragesService extends GlobalStoragesService { * @param IUserSession $userSession * @param IGroupManager $groupManager * @param IUserMountCache $userMountCache + * @param IEventDispatcher $eventDispatcher */ public function __construct( BackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, IGroupManager $groupManager, - IUserMountCache $userMountCache + IUserMountCache $userMountCache, + IEventDispatcher $eventDispatcher ) { - parent::__construct($backendService, $dbConfig, $userMountCache); + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); $this->userSession = $userSession; $this->groupManager = $groupManager; } diff --git a/apps/files_external/lib/Service/UserStoragesService.php b/apps/files_external/lib/Service/UserStoragesService.php index 8af6bdb3a77..b09b37b40cc 100644 --- a/apps/files_external/lib/Service/UserStoragesService.php +++ b/apps/files_external/lib/Service/UserStoragesService.php @@ -32,6 +32,7 @@ use OC\Files\Filesystem; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; use OCP\IUserSession; @@ -49,15 +50,17 @@ class UserStoragesService extends StoragesService { * @param DBConfigService $dbConfig * @param IUserSession $userSession user session * @param IUserMountCache $userMountCache + * @param IEventDispatcher $eventDispatcher */ public function __construct( BackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, - IUserMountCache $userMountCache + IUserMountCache $userMountCache, + IEventDispatcher $eventDispatcher ) { $this->userSession = $userSession; - parent::__construct($backendService, $dbConfig, $userMountCache); + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); } protected function readDBConfig() { diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php index b23c4b8f2bf..7d77ea971f3 100644 --- a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php +++ b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php @@ -37,7 +37,7 @@ use OCA\Files_External\Service\GlobalStoragesService; class GlobalStoragesServiceTest extends StoragesServiceTest { protected function setUp(): void { parent::setUp(); - $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache); + $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); } protected function tearDown(): void { diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTest.php index 3829a9ea0ce..4eaf70a8e84 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/apps/files_external/tests/Service/StoragesServiceTest.php @@ -39,6 +39,7 @@ use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\DBConfigService; use OCA\Files_External\Service\StoragesService; use OCP\AppFramework\IAppContainer; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\Files\Config\IUserMountCache; use OCP\Files\Mount\IMountPoint; @@ -96,6 +97,11 @@ abstract class StoragesServiceTest extends \Test\TestCase { */ protected $mountCache; + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IEventDispatcher + */ + protected IEventDispatcher $eventDispatcher; + protected function setUp(): void { parent::setUp(); $this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto()); @@ -108,6 +114,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { \OCA\Files_External\MountConfig::$skipTest = true; $this->mountCache = $this->createMock(IUserMountCache::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); // prepare BackendService mock $this->backendService = diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php index ea77148c8f2..aa5aa1df431 100644 --- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php @@ -100,7 +100,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->dbConfig, $userSession, $this->groupManager, - $this->mountCache + $this->mountCache, + $this->eventDispatcher, ); } diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php index ff39ea9ddbc..cda1dd0a27f 100644 --- a/apps/files_external/tests/Service/UserStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php @@ -54,7 +54,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { protected function setUp(): void { parent::setUp(); - $this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache); + $this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); $this->userId = $this->getUniqueID('user_'); $this->createUser($this->userId, $this->userId); @@ -67,7 +67,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { ->method('getUser') ->willReturn($this->user); - $this->service = new UserStoragesService($this->backendService, $this->dbConfig, $userSession, $this->mountCache); + $this->service = new UserStoragesService($this->backendService, $this->dbConfig, $userSession, $this->mountCache, $this->eventDispatcher); } private function makeTestStorageData() { diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 102e5d96559..27edf5074e1 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -134,7 +134,9 @@ class MountProvider implements IMountProvider { ], $loader, $view, - $foldersExistCache + $foldersExistCache, + $this->eventDispatcher, + $user ); $event = new ShareMountedEvent($mount); diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index c8f5d0f64ae..60361e25fd0 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -34,7 +34,9 @@ use OC\Files\Mount\MountPoint; use OC\Files\Mount\MoveableMount; use OC\Files\View; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; use OCP\Share\Events\VerifyMountPointEvent; /** @@ -51,10 +53,7 @@ class SharedMount extends MountPoint implements MoveableMount { */ private $recipientView; - /** - * @var string - */ - private $user; + private IUser $user; /** @var \OCP\Share\IShare */ private $superShare; @@ -62,22 +61,27 @@ class SharedMount extends MountPoint implements MoveableMount { /** @var \OCP\Share\IShare[] */ private $groupedShares; - /** - * @param string $storage - * @param SharedMount[] $mountpoints - * @param array $arguments - * @param IStorageFactory $loader - * @param View $recipientView - */ - public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { - $this->user = $arguments['user']; + private IEventDispatcher $eventDispatcher; + + public function __construct( + $storage, + array $mountpoints, + $arguments, + IStorageFactory $loader, + View $recipientView, + CappedMemoryCache $folderExistCache, + IEventDispatcher $eventDispatcher, + IUser $user + ) { + $this->user = $user; $this->recipientView = $recipientView; + $this->eventDispatcher = $eventDispatcher; $this->superShare = $arguments['superShare']; $this->groupedShares = $arguments['groupedShares']; $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; + $absMountPoint = '/' . $user->getUID() . '/files' . $newMountPoint; parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class); } @@ -93,9 +97,7 @@ class SharedMount extends MountPoint implements MoveableMount { $parent = dirname($share->getTarget()); $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); - /** @var IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->query(IEventDispatcher::class); - $dispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); $parent = $event->getParent(); if ($folderExistCache->hasKey($parent)) { @@ -105,7 +107,7 @@ class SharedMount extends MountPoint implements MoveableMount { $folderExistCache->set($parent, $parentExists); } if (!$parentExists) { - $parent = Helper::getShareFolder($this->recipientView, $this->user); + $parent = Helper::getShareFolder($this->recipientView, $this->user->getUID()); } $newMountPoint = $this->generateUniqueTarget( @@ -133,8 +135,10 @@ class SharedMount extends MountPoint implements MoveableMount { foreach ($this->groupedShares as $tmpShare) { $tmpShare->setTarget($newPath); - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user->getUID()); } + + $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent($this->user)); } |