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
This commit is contained in:
parent
81e3787f9c
commit
7b25839bd5
12 changed files with 111 additions and 24 deletions
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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'])
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -99,7 +99,15 @@ class Share20OCS {
|
|||
*/
|
||||
protected function formatShare(\OCP\Share\IShare $share) {
|
||||
$sharedBy = $this->userManager->get($share->getSharedBy());
|
||||
$shareOwner = $this->userManager->get($share->getShareOwner());
|
||||
// for federated shares the owner can be a remote user, in this
|
||||
// case we use the initiator
|
||||
if ($this->userManager->userExists($share->getShareOwner())) {
|
||||
$shareOwner = $this->userManager->get($share->getShareOwner());
|
||||
$localUser = $share->getShareOwner();
|
||||
} else {
|
||||
$shareOwner = $this->userManager->get($share->getSharedBy());
|
||||
$localUser = $share->getSharedBy();
|
||||
}
|
||||
$result = [
|
||||
'id' => $share->getId(),
|
||||
'share_type' => $share->getShareType(),
|
||||
|
@ -115,7 +123,7 @@ class Share20OCS {
|
|||
];
|
||||
|
||||
$node = $share->getNode();
|
||||
$result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner())->getRelativePath($node->getPath());
|
||||
$result['path'] = $this->rootFolder->getUserFolder($localUser)->getRelativePath($node->getPath());
|
||||
if ($node instanceOf \OCP\Files\Folder) {
|
||||
$result['item_type'] = 'folder';
|
||||
} else {
|
||||
|
|
|
@ -82,6 +82,8 @@ class Share20OCSTest extends \Test\TestCase {
|
|||
$this->currentUser = $this->getMock('OCP\IUser');
|
||||
$this->currentUser->method('getUID')->willReturn('currentUser');
|
||||
|
||||
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||
|
||||
$this->l = $this->getMock('\OCP\IL10N');
|
||||
$this->l->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = []) {
|
||||
|
|
|
@ -733,7 +733,7 @@ class DefaultShareProvider implements IShareProvider {
|
|||
* @throws InvalidShare
|
||||
*/
|
||||
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'])
|
||||
|
|
|
@ -201,7 +201,12 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
// And you can't share your rootfolder
|
||||
if ($this->rootFolder->getUserFolder($share->getSharedBy())->getPath() === $share->getNode()->getPath()) {
|
||||
if ($this->userManager->userExists($share->getSharedBy())) {
|
||||
$sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath();
|
||||
} else {
|
||||
$sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath();
|
||||
}
|
||||
if ($sharedPath === $share->getNode()->getPath()) {
|
||||
throw new \InvalidArgumentException('You can\'t share your root folder');
|
||||
}
|
||||
|
||||
|
@ -713,7 +718,11 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
if ($share->getPermissions() !== $originalShare->getPermissions()) {
|
||||
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
|
||||
if ($this->userManager->userExists($share->getShareOwner())) {
|
||||
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
|
||||
} else {
|
||||
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
|
||||
}
|
||||
\OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
|
||||
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
|
||||
'itemSource' => $share->getNode()->getId(),
|
||||
|
@ -1107,7 +1116,7 @@ class Manager implements IManager {
|
|||
* @return \OCP\Share\IShare;
|
||||
*/
|
||||
public function newShare() {
|
||||
return new \OC\Share20\Share($this->rootFolder);
|
||||
return new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,8 @@ class ProviderFactory implements IProviderFactory {
|
|||
$l,
|
||||
$this->serverContainer->getLogger(),
|
||||
$this->serverContainer->getLazyRootFolder(),
|
||||
$this->serverContainer->getConfig()
|
||||
$this->serverContainer->getConfig(),
|
||||
$this->serverContainer->getUserManager()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,7 @@ use OCP\Files\File;
|
|||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Node;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IUser;
|
||||
use OCP\IGroup;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share\Exceptions\IllegalIDChangeException;
|
||||
|
||||
class Share implements \OCP\Share\IShare {
|
||||
|
@ -68,8 +67,12 @@ class Share implements \OCP\Share\IShare {
|
|||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
public function __construct(IRootFolder $rootFolder) {
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +148,13 @@ class Share implements \OCP\Share\IShare {
|
|||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
|
||||
// for federated shares the owner can be a remote user, in this
|
||||
// case we use the initiator
|
||||
if($this->userManager->userExists($this->shareOwner)) {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
|
||||
} else {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
|
||||
}
|
||||
|
||||
$nodes = $userFolder->getById($this->fileId);
|
||||
if (empty($nodes)) {
|
||||
|
|
|
@ -57,6 +57,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
$this->groupManager = $this->getMock('OCP\IGroupManager');
|
||||
$this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
|
||||
|
||||
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||
|
||||
//Empty share table
|
||||
$this->dbConn->getQueryBuilder()->delete('share')->execute();
|
||||
|
||||
|
@ -587,7 +589,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateUserShare() {
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
$share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
||||
|
||||
$shareOwner = $this->getMock('OCP\IUser');
|
||||
$shareOwner->method('getUID')->WillReturn('shareOwner');
|
||||
|
@ -635,7 +637,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateGroupShare() {
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
$share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
||||
|
||||
$shareOwner = $this->getMock('\OCP\IUser');
|
||||
$shareOwner->method('getUID')->willReturn('shareOwner');
|
||||
|
@ -683,7 +685,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateLinkShare() {
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
$share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
||||
|
||||
$shareOwner = $this->getMock('\OCP\IUser');
|
||||
$shareOwner->method('getUID')->willReturn('shareOwner');
|
||||
|
|
|
@ -2283,6 +2283,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testUpdateShareUser() {
|
||||
|
||||
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods([
|
||||
'canShare',
|
||||
|
@ -2567,4 +2570,4 @@ class DummyFactory implements IProviderFactory {
|
|||
public function getProviderForType($shareType) {
|
||||
return $this->provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,8 @@ class ShareTest extends \Test\TestCase {
|
|||
|
||||
public function setUp() {
|
||||
$this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
|
||||
$this->share = new \OC\Share20\Share($this->rootFolder);
|
||||
$this->userManager = $this->getMock('OCP\IUserManager');
|
||||
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue