]> source.dussan.org Git - nextcloud-server.git/commitdiff
add method to check if a share provider for a given type is loaded
authorBjoern Schiessle <bjoern@schiessle.org>
Mon, 24 Oct 2016 15:03:36 +0000 (17:03 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Tue, 1 Nov 2016 18:54:39 +0000 (19:54 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
lib/private/Share20/Manager.php
lib/public/Share/IManager.php
tests/lib/Share20/ManagerTest.php

index 19d6151a037bd16581d9a2df9628519ff092c4b0..899bd4ebfa1e46a90d8a71c3851004d4e40dcbf6 100644 (file)
@@ -30,6 +30,7 @@ namespace OC\Share20;
 use OC\Cache\CappedMemoryCache;
 use OC\Files\Mount\MoveableMount;
 use OC\HintException;
+use OC\Share20\Exception\ProviderException;
 use OCP\Files\File;
 use OCP\Files\Folder;
 use OCP\Files\IRootFolder;
@@ -1291,4 +1292,17 @@ class Manager implements IManager {
                return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
        }
 
+       /**
+        * @inheritdoc
+        */
+       public function shareProviderExists($shareType) {
+               try {
+                       $this->factory->getProviderForType($shareType);
+               } catch (ProviderException $e) {
+                       return false;
+               }
+
+               return true;
+       }
+
 }
index a74ab5fe7968306cb525c4ae9c96dc7be3083095..137dc30928004450e510dda39255e6a1c136922a 100644 (file)
@@ -286,4 +286,12 @@ interface IManager {
         */
        public function outgoingServer2ServerSharesAllowed();
 
+       /**
+        * Check if a given share provider exists
+        * @param int $shareType
+        * @return bool
+        * @since 9.2.0
+        */
+       public function shareProviderExists($shareType);
+
 }
index c0c7b48b35dbbc427da1e6f66ee25f731767edfe..bd85e3c73aa922a462ea6aed1cb9a211498c1115 100644 (file)
@@ -2530,6 +2530,46 @@ class ManagerTest extends \Test\TestCase {
                $this->manager->moveShare($share, 'recipient');
        }
 
+
+       /**
+        * @dataProvider dataTestShareProviderExists
+        */
+       public function testShareProviderExists($shareType, $expected) {
+
+               $factory = $this->getMockBuilder('OCP\Share\IProviderFactory')->getMock();
+               $factory->expects($this->any())->method('getProviderForType')
+                       ->willReturnCallback(function ($id) {
+                               if ($id === \OCP\Share::SHARE_TYPE_USER) {
+                                       return true;
+                               }
+                               throw new Exception\ProviderException();
+                       });
+
+               $manager = new Manager(
+                       $this->logger,
+                       $this->config,
+                       $this->secureRandom,
+                       $this->hasher,
+                       $this->mountManager,
+                       $this->groupManager,
+                       $this->l,
+                       $factory,
+                       $this->userManager,
+                       $this->rootFolder,
+                       $this->eventDispatcher
+               );
+               $this->assertSame($expected,
+                       $manager->shareProviderExists($shareType)
+               );
+       }
+
+       public function dataTestShareProviderExists() {
+               return [
+                       [\OCP\Share::SHARE_TYPE_USER, true],
+                       [42, false],
+               ];
+       }
+
        public function testGetSharesInFolder() {
                $factory = new DummyFactory2($this->createMock(IServerContainer::class));