commit
c62d499a89
7 changed files with 375 additions and 77 deletions
|
@ -618,7 +618,8 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getGroupManager(),
|
||||
$c->getL10N('core'),
|
||||
$factory,
|
||||
$c->getUserManager()
|
||||
$c->getUserManager(),
|
||||
$c->getRootFolder()
|
||||
);
|
||||
|
||||
return $manager;
|
||||
|
|
|
@ -711,7 +711,7 @@ class DefaultShareProvider implements IShareProvider {
|
|||
* @throws InvalidShare
|
||||
*/
|
||||
private function createShare($data) {
|
||||
$share = new Share();
|
||||
$share = new Share($this->rootFolder);
|
||||
$share->setId((int)$data['id'])
|
||||
->setShareType((int)$data['share_type'])
|
||||
->setPermissions((int)$data['permissions'])
|
||||
|
@ -744,8 +744,8 @@ class DefaultShareProvider implements IShareProvider {
|
|||
$share->setShareOwner($data['uid_owner']);
|
||||
}
|
||||
|
||||
$path = $this->getNode($share->getShareOwner(), (int)$data['file_source']);
|
||||
$share->setNode($path);
|
||||
$share->setNodeId((int)$data['file_source']);
|
||||
$share->setNodeType($data['item_type']);
|
||||
|
||||
if ($data['expiration'] !== null) {
|
||||
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace OC\Share20;
|
||||
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share\IManager;
|
||||
use OCP\Share\IProviderFactory;
|
||||
|
@ -45,30 +46,24 @@ class Manager implements IManager {
|
|||
|
||||
/** @var IProviderFactory */
|
||||
private $factory;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
/** @var IHasher */
|
||||
private $hasher;
|
||||
|
||||
/** @var IMountManager */
|
||||
private $mountManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/**
|
||||
* Manager constructor.
|
||||
|
@ -92,7 +87,8 @@ class Manager implements IManager {
|
|||
IGroupManager $groupManager,
|
||||
IL10N $l,
|
||||
IProviderFactory $factory,
|
||||
IUserManager $userManager
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
|
@ -103,6 +99,7 @@ class Manager implements IManager {
|
|||
$this->l = $l;
|
||||
$this->factory = $factory;
|
||||
$this->userManager = $userManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -666,13 +663,13 @@ class Manager implements IManager {
|
|||
|
||||
$hookParams = [
|
||||
'id' => $share->getId(),
|
||||
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
|
||||
'itemSource' => $share->getNode()->getId(),
|
||||
'itemType' => $share->getNodeType(),
|
||||
'itemSource' => $share->getNodeId(),
|
||||
'shareType' => $shareType,
|
||||
'shareWith' => $sharedWith,
|
||||
'itemparent' => $share->getParent(),
|
||||
'uidOwner' => $share->getSharedBy(),
|
||||
'fileSource' => $share->getNode()->getId(),
|
||||
'fileSource' => $share->getNodeId(),
|
||||
'fileTarget' => $share->getTarget()
|
||||
];
|
||||
return $hookParams;
|
||||
|
@ -888,7 +885,7 @@ class Manager implements IManager {
|
|||
* @return \OCP\Share\IShare;
|
||||
*/
|
||||
public function newShare() {
|
||||
return new \OC\Share20\Share();
|
||||
return new \OC\Share20\Share($this->rootFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,10 @@
|
|||
*/
|
||||
namespace OC\Share20;
|
||||
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Node;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IUser;
|
||||
use OCP\IGroup;
|
||||
|
||||
|
@ -31,14 +34,18 @@ class Share implements \OCP\Share\IShare {
|
|||
/** @var string */
|
||||
private $providerId;
|
||||
/** @var Node */
|
||||
private $path;
|
||||
private $node;
|
||||
/** @var int */
|
||||
private $fileId;
|
||||
/** @var string */
|
||||
private $nodeType;
|
||||
/** @var int */
|
||||
private $shareType;
|
||||
/** @var IUser|IGroup */
|
||||
/** @var string */
|
||||
private $sharedWith;
|
||||
/** @var IUser */
|
||||
/** @var string */
|
||||
private $sharedBy;
|
||||
/** @var IUser */
|
||||
/** @var string */
|
||||
private $shareOwner;
|
||||
/** @var int */
|
||||
private $permissions;
|
||||
|
@ -57,6 +64,13 @@ class Share implements \OCP\Share\IShare {
|
|||
/** @var bool */
|
||||
private $mailSend;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
public function __construct(IRootFolder $rootFolder) {
|
||||
$this->rootFolder = $rootFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -90,8 +104,8 @@ class Share implements \OCP\Share\IShare {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setNode(Node $path) {
|
||||
$this->path = $path;
|
||||
public function setNode(Node $node) {
|
||||
$this->node = $node;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -99,7 +113,66 @@ class Share implements \OCP\Share\IShare {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function getNode() {
|
||||
return $this->path;
|
||||
if ($this->node === null) {
|
||||
|
||||
if ($this->shareOwner === null || $this->fileId === null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
|
||||
|
||||
$nodes = $userFolder->getById($this->fileId);
|
||||
if (empty($nodes)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$this->node = $nodes[0];
|
||||
}
|
||||
|
||||
return $this->node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setNodeId($fileId) {
|
||||
$this->node = null;
|
||||
$this->fileId = $fileId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getNodeId() {
|
||||
if ($this->fileId === null) {
|
||||
$this->fileId = $this->getNode()->getId();
|
||||
}
|
||||
|
||||
return $this->fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setNodeType($type) {
|
||||
if ($type !== 'file' && $type !== 'folder') {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->nodeType = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getNodeType() {
|
||||
if ($this->nodeType === null) {
|
||||
$node = $this->getNode();
|
||||
$this->nodeType = $node instanceof File ? 'file' : 'folder';
|
||||
}
|
||||
|
||||
return $this->nodeType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,7 @@ namespace OCP\Share;
|
|||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\Node;
|
||||
use OCP\IUser;
|
||||
use OCP\IGroup;
|
||||
use OCP\Files\NotFoundException;
|
||||
|
||||
/**
|
||||
* Interface IShare
|
||||
|
@ -55,20 +54,55 @@ interface IShare {
|
|||
/**
|
||||
* Set the node of the file/folder that is shared
|
||||
*
|
||||
* @param File|Folder $path
|
||||
* @param Node $node
|
||||
* @return \OCP\Share\IShare The modified object
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setNode(Node $path);
|
||||
public function setNode(Node $node);
|
||||
|
||||
/**
|
||||
* Get the node of the file/folder that is shared
|
||||
*
|
||||
* @return File|Folder
|
||||
* @since 9.0.0
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getNode();
|
||||
|
||||
/**
|
||||
* Set file id for lazy evaluation of the node
|
||||
* @param int $fileId
|
||||
* @return \OCP\Share\IShare The modified object
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setNodeId($fileId);
|
||||
|
||||
/**
|
||||
* Get the fileid of the node of this share
|
||||
* @return int
|
||||
* @since 9.0.0
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getNodeId();
|
||||
|
||||
/**
|
||||
* Set the type of node (file/folder)
|
||||
*
|
||||
* @param string $type
|
||||
* @return \OCP\Share\IShare The modified object
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setNodeType($type);
|
||||
|
||||
/**
|
||||
* Get the type of node (file/folder)
|
||||
*
|
||||
* @return string
|
||||
* @since 9.0.0
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getNodeType();
|
||||
|
||||
/**
|
||||
* Set the shareType
|
||||
*
|
||||
|
|
|
@ -171,6 +171,85 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
$this->assertEquals('myTarget', $share->getTarget());
|
||||
}
|
||||
|
||||
public function testGetShareByIdLazy() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
|
||||
$qb->insert('share')
|
||||
->values([
|
||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
|
||||
'share_with' => $qb->expr()->literal('sharedWith'),
|
||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||
'item_type' => $qb->expr()->literal('file'),
|
||||
'file_source' => $qb->expr()->literal(42),
|
||||
'file_target' => $qb->expr()->literal('myTarget'),
|
||||
'permissions' => $qb->expr()->literal(13),
|
||||
]);
|
||||
$qb->execute();
|
||||
|
||||
$id = $qb->getLastInsertId();
|
||||
|
||||
$this->rootFolder->expects($this->never())->method('getUserFolder');
|
||||
|
||||
$share = $this->provider->getShareById($id);
|
||||
|
||||
// We do not fetch the node so the rootfolder is never called.
|
||||
|
||||
$this->assertEquals($id, $share->getId());
|
||||
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
|
||||
$this->assertEquals('sharedWith', $share->getSharedWith());
|
||||
$this->assertEquals('sharedBy', $share->getSharedBy());
|
||||
$this->assertEquals('shareOwner', $share->getShareOwner());
|
||||
$this->assertEquals(13, $share->getPermissions());
|
||||
$this->assertEquals(null, $share->getToken());
|
||||
$this->assertEquals(null, $share->getExpirationDate());
|
||||
$this->assertEquals('myTarget', $share->getTarget());
|
||||
}
|
||||
|
||||
public function testGetShareByIdLazy2() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
|
||||
$qb->insert('share')
|
||||
->values([
|
||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
|
||||
'share_with' => $qb->expr()->literal('sharedWith'),
|
||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||
'item_type' => $qb->expr()->literal('file'),
|
||||
'file_source' => $qb->expr()->literal(42),
|
||||
'file_target' => $qb->expr()->literal('myTarget'),
|
||||
'permissions' => $qb->expr()->literal(13),
|
||||
]);
|
||||
$qb->execute();
|
||||
|
||||
$id = $qb->getLastInsertId();
|
||||
|
||||
$ownerPath = $this->getMock('\OCP\Files\File');
|
||||
|
||||
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
|
||||
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
|
||||
|
||||
$this->rootFolder
|
||||
->method('getUserFolder')
|
||||
->with('shareOwner')
|
||||
->willReturn($shareOwnerFolder);
|
||||
|
||||
$share = $this->provider->getShareById($id);
|
||||
|
||||
// We fetch the node so the root folder is eventually called
|
||||
|
||||
$this->assertEquals($id, $share->getId());
|
||||
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
|
||||
$this->assertEquals('sharedWith', $share->getSharedWith());
|
||||
$this->assertEquals('sharedBy', $share->getSharedBy());
|
||||
$this->assertEquals('shareOwner', $share->getShareOwner());
|
||||
$this->assertEquals($ownerPath, $share->getNode());
|
||||
$this->assertEquals(13, $share->getPermissions());
|
||||
$this->assertEquals(null, $share->getToken());
|
||||
$this->assertEquals(null, $share->getExpirationDate());
|
||||
$this->assertEquals('myTarget', $share->getTarget());
|
||||
}
|
||||
|
||||
public function testGetShareByIdGroupShare() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
|
||||
|
@ -370,6 +449,39 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testDeleteSingleShareLazy() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
$qb->insert('share')
|
||||
->values([
|
||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
|
||||
'share_with' => $qb->expr()->literal('sharedWith'),
|
||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||
'item_type' => $qb->expr()->literal('file'),
|
||||
'file_source' => $qb->expr()->literal(42),
|
||||
'file_target' => $qb->expr()->literal('myTarget'),
|
||||
'permissions' => $qb->expr()->literal(13),
|
||||
]);
|
||||
$this->assertEquals(1, $qb->execute());
|
||||
|
||||
$id = $qb->getLastInsertId();
|
||||
|
||||
$this->rootFolder->expects($this->never())->method($this->anything());
|
||||
|
||||
$share = $this->provider->getShareById($id);
|
||||
$this->provider->delete($share);
|
||||
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('share');
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$result = $cursor->fetchAll();
|
||||
$cursor->closeCursor();
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testDeleteGroupShareWithUserGroupShares() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
$qb->insert('share')
|
||||
|
@ -561,7 +673,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateUserShare() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
|
||||
$shareOwner = $this->getMock('OCP\IUser');
|
||||
$shareOwner->method('getUID')->WillReturn('shareOwner');
|
||||
|
@ -609,7 +721,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateGroupShare() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
|
||||
$shareOwner = $this->getMock('\OCP\IUser');
|
||||
$shareOwner->method('getUID')->willReturn('shareOwner');
|
||||
|
@ -657,7 +769,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateLinkShare() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = new \OC\Share20\Share($this->rootFolder);
|
||||
|
||||
$shareOwner = $this->getMock('\OCP\IUser');
|
||||
$shareOwner->method('getUID')->willReturn('shareOwner');
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
namespace Test\Share20;
|
||||
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share\IProviderFactory;
|
||||
use OCP\Share\IShare;
|
||||
|
@ -35,7 +36,6 @@ use OCP\Security\ISecureRandom;
|
|||
use OCP\Security\IHasher;
|
||||
use OCP\Files\Mount\IMountManager;
|
||||
use OCP\IGroupManager;
|
||||
use Sabre\VObject\Property\VCard\DateTime;
|
||||
|
||||
/**
|
||||
* Class ManagerTest
|
||||
|
@ -47,36 +47,28 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
/** @var Manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var ILogger */
|
||||
protected $logger;
|
||||
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
protected $secureRandom;
|
||||
|
||||
/** @var IHasher */
|
||||
protected $hasher;
|
||||
|
||||
/** @var IShareProvider | \PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $defaultProvider;
|
||||
|
||||
/** @var IMountManager */
|
||||
protected $mountManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
protected $groupManager;
|
||||
|
||||
/** @var IL10N */
|
||||
protected $l;
|
||||
|
||||
/** @var DummyFactory */
|
||||
protected $factory;
|
||||
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $rootFolder;
|
||||
|
||||
public function setUp() {
|
||||
|
||||
|
@ -87,6 +79,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager');
|
||||
$this->groupManager = $this->getMock('\OCP\IGroupManager');
|
||||
$this->userManager = $this->getMock('\OCP\IUserManager');
|
||||
$this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
|
||||
|
||||
$this->l = $this->getMock('\OCP\IL10N');
|
||||
$this->l->method('t')
|
||||
|
@ -105,7 +98,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->factory,
|
||||
$this->userManager
|
||||
$this->userManager,
|
||||
$this->rootFolder
|
||||
);
|
||||
|
||||
$this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
|
||||
|
@ -131,7 +125,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->factory,
|
||||
$this->userManager
|
||||
$this->userManager,
|
||||
$this->rootFolder
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -247,6 +242,86 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testDeleteLazyShare() {
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods(['getShareById', 'deleteChildren'])
|
||||
->getMock();
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setId(42)
|
||||
->setProviderId('prov')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('sharedWith')
|
||||
->setSharedBy('sharedBy')
|
||||
->setShareOwner('shareOwner')
|
||||
->setTarget('myTarget')
|
||||
->setNodeId(1)
|
||||
->setNodeType('file');
|
||||
|
||||
$this->rootFolder->expects($this->never())->method($this->anything());
|
||||
|
||||
$manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share);
|
||||
$manager->expects($this->once())->method('deleteChildren')->with($share);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with($share);
|
||||
|
||||
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
|
||||
\OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
|
||||
\OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
|
||||
|
||||
$hookListnerExpectsPre = [
|
||||
'id' => 42,
|
||||
'itemType' => 'file',
|
||||
'itemSource' => 1,
|
||||
'shareType' => \OCP\Share::SHARE_TYPE_USER,
|
||||
'shareWith' => 'sharedWith',
|
||||
'itemparent' => null,
|
||||
'uidOwner' => 'sharedBy',
|
||||
'fileSource' => 1,
|
||||
'fileTarget' => 'myTarget',
|
||||
];
|
||||
|
||||
$hookListnerExpectsPost = [
|
||||
'id' => 42,
|
||||
'itemType' => 'file',
|
||||
'itemSource' => 1,
|
||||
'shareType' => \OCP\Share::SHARE_TYPE_USER,
|
||||
'shareWith' => 'sharedWith',
|
||||
'itemparent' => null,
|
||||
'uidOwner' => 'sharedBy',
|
||||
'fileSource' => 1,
|
||||
'fileTarget' => 'myTarget',
|
||||
'deletedShares' => [
|
||||
[
|
||||
'id' => 42,
|
||||
'itemType' => 'file',
|
||||
'itemSource' => 1,
|
||||
'shareType' => \OCP\Share::SHARE_TYPE_USER,
|
||||
'shareWith' => 'sharedWith',
|
||||
'itemparent' => null,
|
||||
'uidOwner' => 'sharedBy',
|
||||
'fileSource' => 1,
|
||||
'fileTarget' => 'myTarget',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$hookListner
|
||||
->expects($this->exactly(1))
|
||||
->method('pre')
|
||||
->with($hookListnerExpectsPre);
|
||||
$hookListner
|
||||
->expects($this->exactly(1))
|
||||
->method('post')
|
||||
->with($hookListnerExpectsPost);
|
||||
|
||||
$manager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testDeleteNested() {
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods(['getShareById'])
|
||||
|
@ -792,7 +867,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Only sharing with group members is allowed
|
||||
*/
|
||||
public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$sharedBy = $this->getMock('\OCP\IUser');
|
||||
$sharedWith = $this->getMock('\OCP\IUser');
|
||||
|
@ -822,7 +897,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$sharedBy = $this->getMock('\OCP\IUser');
|
||||
$sharedWith = $this->getMock('\OCP\IUser');
|
||||
|
@ -904,8 +979,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
->setProviderId('foo')
|
||||
->setId('bar');
|
||||
|
||||
$share2 = new \OC\Share20\Share();
|
||||
$owner2 = $this->getMock('\OCP\IUser');
|
||||
$share2 = $this->manager->newShare();
|
||||
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setShareOwner('shareOwner2')
|
||||
->setProviderId('foo')
|
||||
|
@ -928,7 +1002,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testUserCreateChecksIdenticalPathNotSharedWithUser() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$sharedWith = $this->getMock('\OCP\IUser');
|
||||
$path = $this->getMock('\OCP\Files\Node');
|
||||
$share->setSharedWith('sharedWith')
|
||||
|
@ -939,7 +1013,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
|
||||
|
||||
$share2 = new \OC\Share20\Share();
|
||||
$share2 = $this->manager->newShare();
|
||||
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setShareOwner('shareOwner2')
|
||||
->setProviderId('foo')
|
||||
|
@ -967,7 +1041,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Only sharing within your own groups is allowed
|
||||
*/
|
||||
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$user = $this->getMock('\OCP\IUser');
|
||||
$group = $this->getMock('\OCP\IGroup');
|
||||
|
@ -988,7 +1062,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$user = $this->getMock('\OCP\IUser');
|
||||
$group = $this->getMock('\OCP\IGroup');
|
||||
|
@ -1028,7 +1102,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
->setProviderId('foo')
|
||||
->setId('bar');
|
||||
|
||||
$share2 = new \OC\Share20\Share();
|
||||
$share2 = $this->manager->newShare();
|
||||
$share2->setSharedWith('sharedWith')
|
||||
->setProviderId('foo')
|
||||
->setId('baz');
|
||||
|
@ -1041,14 +1115,14 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setSharedWith('sharedWith');
|
||||
|
||||
$path = $this->getMock('\OCP\Files\Node');
|
||||
$share->setNode($path);
|
||||
|
||||
$share2 = new \OC\Share20\Share();
|
||||
$share2 = $this->manager->newShare();
|
||||
$share2->setSharedWith('sharedWith2');
|
||||
|
||||
$this->defaultProvider->method('getSharesByPath')
|
||||
|
@ -1063,7 +1137,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Link sharing not allowed
|
||||
*/
|
||||
public function testLinkCreateChecksNoLinkSharesAllowed() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
|
@ -1079,7 +1153,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Link shares can't have reshare permissions
|
||||
*/
|
||||
public function testLinkCreateChecksSharePermissions() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_SHARE);
|
||||
|
||||
|
@ -1097,7 +1171,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Link shares can't have delete permissions
|
||||
*/
|
||||
public function testLinkCreateChecksDeletePermissions() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_DELETE);
|
||||
|
||||
|
@ -1115,7 +1189,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
* @expectedExceptionMessage Public upload not allowed
|
||||
*/
|
||||
public function testLinkCreateChecksNoPublicUpload() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
|
||||
|
||||
|
@ -1130,7 +1204,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testLinkCreateChecksPublicUpload() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
|
||||
|
||||
|
@ -1145,7 +1219,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testLinkCreateChecksReadOnly() {
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
|
||||
|
||||
|
@ -1316,7 +1390,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
->getMock();
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(false);
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$manager->createShare($share);
|
||||
}
|
||||
|
||||
|
@ -1610,7 +1684,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->groupManager,
|
||||
$this->l,
|
||||
$factory,
|
||||
$this->userManager
|
||||
$this->userManager,
|
||||
$this->rootFolder
|
||||
);
|
||||
|
||||
$share = $this->getMock('\OCP\Share\IShare');
|
||||
|
@ -1695,7 +1770,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
->getMock();
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(false);
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$manager->updateShare($share);
|
||||
}
|
||||
|
||||
|
@ -1711,13 +1786,13 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(true);
|
||||
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
|
||||
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')
|
||||
->setId('42')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER);
|
||||
|
@ -1737,14 +1812,14 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setSharedWith('origGroup');
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(true);
|
||||
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
|
||||
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')
|
||||
->setId('42')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
|
@ -1765,14 +1840,14 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('sharedWith');
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(true);
|
||||
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
|
||||
|
||||
$share = new \OC\Share20\Share();
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')
|
||||
->setId('42')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
|
@ -1793,19 +1868,22 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('origUser');
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(true);
|
||||
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
|
||||
|
||||
$share = new \OC\Share20\Share();
|
||||
$node = $this->getMock('\OCP\Files\File');
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')
|
||||
->setId('42')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('origUser')
|
||||
->setShareOwner('newUser');
|
||||
->setShareOwner('newUser')
|
||||
->setNode($node);
|
||||
|
||||
$this->defaultProvider->expects($this->once())
|
||||
->method('update')
|
||||
|
@ -1831,19 +1909,22 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setSharedWith('origUser');
|
||||
|
||||
$manager->expects($this->once())->method('canShare')->willReturn(true);
|
||||
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
|
||||
|
||||
$share = new \OC\Share20\Share();
|
||||
$node = $this->getMock('\OCP\Files\File');
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')
|
||||
->setId('42')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setSharedWith('origUser')
|
||||
->setShareOwner('owner');
|
||||
->setShareOwner('owner')
|
||||
->setNode($node);
|
||||
|
||||
$this->defaultProvider->expects($this->once())
|
||||
->method('update')
|
||||
|
@ -1871,7 +1952,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
])
|
||||
->getMock();
|
||||
|
||||
$originalShare = new \OC\Share20\Share();
|
||||
$originalShare = $this->manager->newShare();
|
||||
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
|
||||
|
||||
$tomorrow = new \DateTime();
|
||||
|
|
Loading…
Reference in a new issue