]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add support for tokens in room shares 10255/head
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Wed, 1 Aug 2018 17:04:32 +0000 (19:04 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Wed, 8 Aug 2018 12:25:44 +0000 (14:25 +0200)
Tokens will be used to give access to a share to guests in public rooms.
Although the token itself is created in the provider of room shares and
no changes are needed for that, due to the code structure it is
necessary to explicitly call the provider from the manager when getting
a room share by token.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
lib/private/Share20/Manager.php
tests/lib/Share20/ManagerTest.php

index 7cfa83dbb4a0f1834deda9546a231381690f5cb6..037ea53048a3723704ad245ea62c82021b4d82b8 100644 (file)
@@ -1248,6 +1248,15 @@ class Manager implements IManager {
                        }
                }
 
+               if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) {
+                       try {
+                               $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM);
+                               $share = $provider->getShareByToken($token);
+                       } catch (ProviderException $e) {
+                       } catch (ShareNotFound $e) {
+                       }
+               }
+
                if ($share === null) {
                        throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
                }
index 7106e22b264d753a36242b0f5568e136a737ed72..1125cae95658b8d9810888ca8bac4c4ed81073bc 100644 (file)
@@ -2165,6 +2165,56 @@ class ManagerTest extends \Test\TestCase {
                $this->assertSame($share, $ret);
        }
 
+       public function testGetShareByTokenRoom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('core', 'shareapi_allow_links', 'yes')
+                       ->willReturn('no');
+
+               $factory = $this->createMock(IProviderFactory::class);
+
+               $manager = new Manager(
+                       $this->logger,
+                       $this->config,
+                       $this->secureRandom,
+                       $this->hasher,
+                       $this->mountManager,
+                       $this->groupManager,
+                       $this->l,
+                       $this->l10nFactory,
+                       $factory,
+                       $this->userManager,
+                       $this->rootFolder,
+                       $this->eventDispatcher,
+                       $this->mailer,
+                       $this->urlGenerator,
+                       $this->defaults
+               );
+
+               $share = $this->createMock(IShare::class);
+
+               $roomShareProvider = $this->createMock(IShareProvider::class);
+
+               $factory->expects($this->any())
+                       ->method('getProviderForType')
+                       ->will($this->returnCallback(function($shareType) use ($roomShareProvider) {
+                               if ($shareType !== \OCP\Share::SHARE_TYPE_ROOM) {
+                                       throw new Exception\ProviderException();
+                               }
+
+                               return $roomShareProvider;
+                       }));
+
+               $roomShareProvider->expects($this->once())
+                       ->method('getShareByToken')
+                       ->with('token')
+                       ->willReturn($share);
+
+               $ret = $manager->getShareByToken('token');
+               $this->assertSame($share, $ret);
+       }
+
        public function testGetShareByTokenWithException() {
                $this->config
                        ->expects($this->once())