diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php index 1bc0215c5112c..8e29f5b5a9c49 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -37,6 +37,7 @@ 'OCA\\Files_Sharing\\Controller\\ShareesAPIController' => $baseDir . '/../lib/Controller/ShareesAPIController.php', 'OCA\\Files_Sharing\\DeleteOrphanedSharesJob' => $baseDir . '/../lib/DeleteOrphanedSharesJob.php', 'OCA\\Files_Sharing\\Event\\BeforeTemplateRenderedEvent' => $baseDir . '/../lib/Event/BeforeTemplateRenderedEvent.php', + 'OCA\\Files_Sharing\\Event\\ShareMountedEvent' => $baseDir . '/../lib/Event/ShareMountedEvent.php', 'OCA\\Files_Sharing\\Exceptions\\BrokenPath' => $baseDir . '/../lib/Exceptions/BrokenPath.php', 'OCA\\Files_Sharing\\Exceptions\\S2SException' => $baseDir . '/../lib/Exceptions/S2SException.php', 'OCA\\Files_Sharing\\Exceptions\\SharingRightsException' => $baseDir . '/../lib/Exceptions/SharingRightsException.php', diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php index 1903827b402cb..2230c086358bc 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -52,6 +52,7 @@ class ComposerStaticInitFiles_Sharing 'OCA\\Files_Sharing\\Controller\\ShareesAPIController' => __DIR__ . '/..' . '/../lib/Controller/ShareesAPIController.php', 'OCA\\Files_Sharing\\DeleteOrphanedSharesJob' => __DIR__ . '/..' . '/../lib/DeleteOrphanedSharesJob.php', 'OCA\\Files_Sharing\\Event\\BeforeTemplateRenderedEvent' => __DIR__ . '/..' . '/../lib/Event/BeforeTemplateRenderedEvent.php', + 'OCA\\Files_Sharing\\Event\\ShareMountedEvent' => __DIR__ . '/..' . '/../lib/Event/ShareMountedEvent.php', 'OCA\\Files_Sharing\\Exceptions\\BrokenPath' => __DIR__ . '/..' . '/../lib/Exceptions/BrokenPath.php', 'OCA\\Files_Sharing\\Exceptions\\S2SException' => __DIR__ . '/..' . '/../lib/Exceptions/S2SException.php', 'OCA\\Files_Sharing\\Exceptions\\SharingRightsException' => __DIR__ . '/..' . '/../lib/Exceptions/SharingRightsException.php', diff --git a/apps/files_sharing/lib/Event/ShareMountedEvent.php b/apps/files_sharing/lib/Event/ShareMountedEvent.php new file mode 100644 index 0000000000000..151848273899f --- /dev/null +++ b/apps/files_sharing/lib/Event/ShareMountedEvent.php @@ -0,0 +1,56 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files_Sharing\Event; + +use OCA\Files_Sharing\SharedMount; +use OCP\EventDispatcher\Event; +use OCP\Files\Mount\IMountPoint; + +class ShareMountedEvent extends Event { + /** @var SharedMount */ + private $mount; + + /** @var IMountPoint[] */ + private $additionalMounts = []; + + public function __construct(SharedMount $mount) { + parent::__construct(); + $this->mount = $mount; + } + + public function getMount(): SharedMount { + return $this->mount; + } + + public function addAdditionalMount(IMountPoint $mountPoint): void { + $this->additionalMounts[] = $mountPoint; + } + + /** + * @return IMountPoint[] + */ + public function getAdditionalMounts(): array { + return $this->additionalMounts; + } +} diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 42541b77f2d46..102e5d9655901 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -30,6 +30,8 @@ use OC\Cache\CappedMemoryCache; use OC\Files\View; +use OCA\Files_Sharing\Event\ShareMountedEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; @@ -54,15 +56,24 @@ class MountProvider implements IMountProvider { */ protected $logger; + /** @var IEventDispatcher */ + protected $eventDispatcher; + /** * @param \OCP\IConfig $config * @param IManager $shareManager * @param ILogger $logger */ - public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { + public function __construct( + IConfig $config, + IManager $shareManager, + ILogger $logger, + IEventDispatcher $eventDispatcher + ) { $this->config = $config; $this->shareManager = $shareManager; $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; } @@ -125,7 +136,14 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { $view, $foldersExistCache ); + + $event = new ShareMountedEvent($mount); + $this->eventDispatcher->dispatchTyped($event); + $mounts[$mount->getMountPoint()] = $mount; + foreach ($event->getAdditionalMounts() as $additionalMount) { + $mounts[$additionalMount->getMountPoint()] = $additionalMount; + } } catch (\Exception $e) { $this->logger->logException($e); $this->logger->error('Error while trying to create shared mount'); diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php index 8025cdddff9a5..756c6f95d4252 100644 --- a/apps/files_sharing/tests/MountProviderTest.php +++ b/apps/files_sharing/tests/MountProviderTest.php @@ -30,6 +30,7 @@ namespace OCA\Files_Sharing\Tests; use OCA\Files_Sharing\MountProvider; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; @@ -70,8 +71,9 @@ protected function setUp(): void { $this->loader = $this->getMockBuilder('OCP\Files\Storage\IStorageFactory')->getMock(); $this->shareManager = $this->getMockBuilder(IManager::class)->getMock(); $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger); + $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher); } private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31) {