Skip to content

Commit 4b7fa4a

Browse files
committed
Add support for tokens in room shares
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>
1 parent e2e6f23 commit 4b7fa4a

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

lib/private/Share20/Manager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,15 @@ public function getShareByToken($token) {
12481248
}
12491249
}
12501250

1251+
if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) {
1252+
try {
1253+
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM);
1254+
$share = $provider->getShareByToken($token);
1255+
} catch (ProviderException $e) {
1256+
} catch (ShareNotFound $e) {
1257+
}
1258+
}
1259+
12511260
if ($share === null) {
12521261
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
12531262
}

tests/lib/Share20/ManagerTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,56 @@ public function testGetShareByToken() {
21652165
$this->assertSame($share, $ret);
21662166
}
21672167

2168+
public function testGetShareByTokenRoom() {
2169+
$this->config
2170+
->expects($this->once())
2171+
->method('getAppValue')
2172+
->with('core', 'shareapi_allow_links', 'yes')
2173+
->willReturn('no');
2174+
2175+
$factory = $this->createMock(IProviderFactory::class);
2176+
2177+
$manager = new Manager(
2178+
$this->logger,
2179+
$this->config,
2180+
$this->secureRandom,
2181+
$this->hasher,
2182+
$this->mountManager,
2183+
$this->groupManager,
2184+
$this->l,
2185+
$this->l10nFactory,
2186+
$factory,
2187+
$this->userManager,
2188+
$this->rootFolder,
2189+
$this->eventDispatcher,
2190+
$this->mailer,
2191+
$this->urlGenerator,
2192+
$this->defaults
2193+
);
2194+
2195+
$share = $this->createMock(IShare::class);
2196+
2197+
$roomShareProvider = $this->createMock(IShareProvider::class);
2198+
2199+
$factory->expects($this->any())
2200+
->method('getProviderForType')
2201+
->will($this->returnCallback(function($shareType) use ($roomShareProvider) {
2202+
if ($shareType !== \OCP\Share::SHARE_TYPE_ROOM) {
2203+
throw new Exception\ProviderException();
2204+
}
2205+
2206+
return $roomShareProvider;
2207+
}));
2208+
2209+
$roomShareProvider->expects($this->once())
2210+
->method('getShareByToken')
2211+
->with('token')
2212+
->willReturn($share);
2213+
2214+
$ret = $manager->getShareByToken('token');
2215+
$this->assertSame($share, $ret);
2216+
}
2217+
21682218
public function testGetShareByTokenWithException() {
21692219
$this->config
21702220
->expects($this->once())

0 commit comments

Comments
 (0)