summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2016-05-11 20:48:27 +0200
committerBjörn Schießle <schiessle@owncloud.com>2016-05-20 21:15:15 +0200
commit7b25839bd51b3b6cd920209c254f014c03437113 (patch)
tree2e9885bdb068d56ff7bb9fde344c4da0cc95e2d3 /apps/federatedfilesharing
parent81e3787f9cb4936f186b25e0dccb07b4e6dcce83 (diff)
downloadnextcloud-server-7b25839bd51b3b6cd920209c254f014c03437113.tar.gz
nextcloud-server-7b25839bd51b3b6cd920209c254f014c03437113.zip
use share initiator as fall back to access the file
in case of federated re-shares the owner can be a remote user. Therefore we can't always use to owner to access the local file
Diffstat (limited to 'apps/federatedfilesharing')
-rw-r--r--apps/federatedfilesharing/lib/AppInfo/Application.php3
-rw-r--r--apps/federatedfilesharing/lib/FederatedShareProvider.php13
-rw-r--r--apps/federatedfilesharing/tests/FederatedShareProviderTest.php52
3 files changed, 60 insertions, 8 deletions
diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php
index 5a213aec8e2..d1b0646ba5b 100644
--- a/apps/federatedfilesharing/lib/AppInfo/Application.php
+++ b/apps/federatedfilesharing/lib/AppInfo/Application.php
@@ -81,7 +81,8 @@ class Application extends App {
\OC::$server->getL10N('federatedfilesharing'),
\OC::$server->getLogger(),
\OC::$server->getLazyRootFolder(),
- \OC::$server->getConfig()
+ \OC::$server->getConfig(),
+ \OC::$server->getUserManager()
);
}
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 590c61559bf..762b015d280 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -23,13 +23,12 @@
namespace OCA\FederatedFileSharing;
-use OC\Files\View;
use OC\Share20\Share;
use OCP\Files\IRootFolder;
-use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
+use OCP\IUserManager;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare;
@@ -74,6 +73,9 @@ class FederatedShareProvider implements IShareProvider {
/** @var string */
private $externalShareTable = 'share_external';
+ /** @var IUserManager */
+ private $userManager;
+
/**
* DefaultShareProvider constructor.
*
@@ -85,6 +87,7 @@ class FederatedShareProvider implements IShareProvider {
* @param ILogger $logger
* @param IRootFolder $rootFolder
* @param IConfig $config
+ * @param IUserManager $userManager
*/
public function __construct(
IDBConnection $connection,
@@ -94,7 +97,8 @@ class FederatedShareProvider implements IShareProvider {
IL10N $l10n,
ILogger $logger,
IRootFolder $rootFolder,
- IConfig $config
+ IConfig $config,
+ IUserManager $userManager
) {
$this->dbConnection = $connection;
$this->addressHandler = $addressHandler;
@@ -104,6 +108,7 @@ class FederatedShareProvider implements IShareProvider {
$this->logger = $logger;
$this->rootFolder = $rootFolder;
$this->config = $config;
+ $this->userManager = $userManager;
}
/**
@@ -699,7 +704,7 @@ class FederatedShareProvider implements IShareProvider {
*/
private function createShare($data) {
- $share = new Share($this->rootFolder);
+ $share = new Share($this->rootFolder, $this->userManager);
$share->setId((int)$data['id'])
->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions'])
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index 10770f00af5..9b3edf0398d 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -30,6 +30,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
+use OCP\IUserManager;
use OCP\Share\IManager;
/**
@@ -56,6 +57,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
protected $rootFolder;
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
protected $config;
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
/** @var IManager */
protected $shareManager;
@@ -81,7 +84,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->logger = $this->getMock('OCP\ILogger');
$this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
$this->config = $this->getMock('OCP\IConfig');
- $this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
+ $this->userManager = $this->getMock('OCP\IUserManager');
+ //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
+ $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock();
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
@@ -93,7 +98,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->l,
$this->logger,
$this->rootFolder,
- $this->config
+ $this->config,
+ $this->userManager
);
$this->shareManager = \OC::$server->getShareManager();
@@ -120,6 +126,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -186,6 +197,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -233,7 +249,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
- $shareWith = 'sharedBy@' . $this->addressHandler->generateRemoteURL();
+ $this->addressHandler->expects($this->any())->method('compareAddresses')
+ ->willReturn(true);
+
+ $shareWith = 'sharedBy@localhost';
$share->setSharedWith($shareWith)
->setSharedBy('sharedBy')
@@ -269,6 +288,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
->setShareOwner('shareOwner')
@@ -277,6 +300,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -328,6 +354,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$share->setSharedWith('user@server.com')
->setSharedBy($sharedBy)
->setShareOwner($owner)
@@ -335,6 +365,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
$this->notifications->expects($this->once())
->method('sendRemoteShare')
@@ -379,6 +411,12 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+ $this->addressHandler->expects($this->at(0))->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
+ $this->addressHandler->expects($this->at(1))->method('splitUserRemote')
+ ->willReturn(['user2', 'server.com']);
+
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')
@@ -485,6 +523,14 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturnCallback(function ($uid) {
+ if ($uid === 'user@server.com') {
+ return ['user', 'server.com'];
+ }
+ return ['user2', 'server.com'];
+ });
+
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')