Skip to content

Commit

Permalink
Add support for tokens in room shares
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danxuliu committed Aug 1, 2018
1 parent a693e11 commit a0c1f49
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,15 @@ public function getShareByToken($token) {
}
}

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'));
}
Expand Down
50 changes: 50 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,56 @@ public function testGetShareByToken() {
$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())
Expand Down

0 comments on commit a0c1f49

Please sign in to comment.