]> source.dussan.org Git - nextcloud-server.git/commitdiff
add event for when a share is mounted 28399/head
authorRobin Appelman <robin@icewind.nl>
Mon, 9 Aug 2021 13:53:09 +0000 (15:53 +0200)
committerRobin Appelman <robin@icewind.nl>
Tue, 24 Aug 2021 13:26:50 +0000 (15:26 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_sharing/composer/composer/autoload_classmap.php
apps/files_sharing/composer/composer/autoload_static.php
apps/files_sharing/lib/Event/ShareMountedEvent.php [new file with mode: 0644]
apps/files_sharing/lib/MountProvider.php
apps/files_sharing/tests/MountProviderTest.php

index 1bc0215c5112ca0bbaf5e27c3e0b9ed150a741b9..8e29f5b5a9c49137ccd035d9600f8c75c6482142 100644 (file)
@@ -37,6 +37,7 @@ return array(
     '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',
index 1903827b402cbb2f38dd3542c0bb76a3be76fc2f..2230c086358bc7fd0a5dc5c6808d74b8343349db 100644 (file)
@@ -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 (file)
index 0000000..1518482
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+       }
+}
index 42541b77f2d460068d9d876761bb48887e428aab..102e5d9655901ad3b2f789a10db8f42d31466b28 100644 (file)
@@ -30,6 +30,8 @@ namespace OCA\Files_Sharing;
 
 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 @@ class MountProvider implements IMountProvider {
                                        $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');
index 8025cdddff9a5fa660fd665ebb7d9c8b49e1b8c7..756c6f95d4252f10cfd7a03f1eb8fa811590b05b 100644 (file)
@@ -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 @@ class MountProviderTest extends \Test\TestCase {
                $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) {