[Share 2.0] Fix OCS endpoint

This commit is contained in:
Roeland Jago Douma 2016-02-03 08:14:48 +01:00
parent 96662c4d0d
commit c1841892d0
2 changed files with 123 additions and 108 deletions

View File

@ -26,35 +26,41 @@ use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Share\IManager;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\GenericShareException;
class Share20OCS { class Share20OCS {
/** @var \OC\Share20\Manager */ /** @var IManager */
private $shareManager; private $shareManager;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var IRequest */ /** @var IRequest */
private $request; private $request;
/** @var IRootFolder */ /** @var IRootFolder */
private $rootFolder; private $rootFolder;
/** @var IUrlGenerator */ /** @var IUrlGenerator */
private $urlGenerator; private $urlGenerator;
/** @var IUser */ /** @var IUser */
private $currentUser; private $currentUser;
/**
* Share20OCS constructor.
*
* @param IManager $shareManager
* @param IGroupManager $groupManager
* @param IUserManager $userManager
* @param IRequest $request
* @param IRootFolder $rootFolder
* @param IURLGenerator $urlGenerator
* @param IUser $currentUser
*/
public function __construct( public function __construct(
\OC\Share20\Manager $shareManager, IManager $shareManager,
IGroupManager $groupManager, IGroupManager $groupManager,
IUserManager $userManager, IUserManager $userManager,
IRequest $request, IRequest $request,
@ -78,22 +84,24 @@ class Share20OCS {
* @return array * @return array
*/ */
protected function formatShare(\OCP\Share\IShare $share) { protected function formatShare(\OCP\Share\IShare $share) {
$sharedBy = $this->userManager->get($share->getSharedBy());
$shareOwner = $this->userManager->get($share->getShareOwner());
$result = [ $result = [
'id' => $share->getId(), 'id' => $share->getId(),
'share_type' => $share->getShareType(), 'share_type' => $share->getShareType(),
'uid_owner' => $share->getSharedBy()->getUID(), 'uid_owner' => $share->getSharedBy(),
'displayname_owner' => $share->getSharedBy()->getDisplayName(), 'displayname_owner' => $sharedBy->getDisplayName(),
'permissions' => $share->getPermissions(), 'permissions' => $share->getPermissions(),
'stime' => $share->getShareTime()->getTimestamp(), 'stime' => $share->getShareTime()->getTimestamp(),
'parent' => null, 'parent' => null,
'expiration' => null, 'expiration' => null,
'token' => null, 'token' => null,
'uid_file_owner' => $share->getShareOwner()->getUID(), 'uid_file_owner' => $share->getShareOwner(),
'displayname_file_owner' => $share->getShareOwner()->getDisplayName(), 'displayname_file_owner' => $shareOwner->getDisplayName(),
]; ];
$node = $share->getNode(); $node = $share->getNode();
$result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($node->getPath()); $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner())->getRelativePath($node->getPath());
if ($node instanceOf \OCP\Files\Folder) { if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder'; $result['item_type'] = 'folder';
} else { } else {
@ -107,13 +115,12 @@ class Share20OCS {
$result['file_target'] = $share->getTarget(); $result['file_target'] = $share->getTarget();
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $share->getSharedWith(); $sharedWith = $this->userManager->get($share->getSharedWith());
$result['share_with'] = $sharedWith->getUID(); $result['share_with'] = $sharedWith->getUID();
$result['share_with_displayname'] = $sharedWith->getDisplayName(); $result['share_with_displayname'] = $sharedWith->getDisplayName();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$sharedWith = $share->getSharedWith(); $result['share_with'] = $share->getSharedWith();
$result['share_with'] = $sharedWith->getGID(); $result['share_with_displayname'] = $share->getSharedWith();
$result['share_with_displayname'] = $sharedWith->getGID();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$result['share_with'] = $share->getPassword(); $result['share_with'] = $share->getPassword();
@ -250,14 +257,14 @@ class Share20OCS {
if ($shareWith === null || !$this->userManager->userExists($shareWith)) { if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
return new \OC_OCS_Result(null, 404, 'please specify a valid user'); return new \OC_OCS_Result(null, 404, 'please specify a valid user');
} }
$share->setSharedWith($this->userManager->get($shareWith)); $share->setSharedWith($shareWith);
$share->setPermissions($permissions); $share->setPermissions($permissions);
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
// Valid group is required to share // Valid group is required to share
if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
return new \OC_OCS_Result(null, 404, 'please specify a valid group'); return new \OC_OCS_Result(null, 404, 'please specify a valid group');
} }
$share->setSharedWith($this->groupManager->get($shareWith)); $share->setSharedWith($shareWith);
$share->setPermissions($permissions); $share->setPermissions($permissions);
} else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
//Can we even share links? //Can we even share links?
@ -313,7 +320,7 @@ class Share20OCS {
} }
$share->setShareType($shareType); $share->setShareType($shareType);
$share->setSharedBy($this->currentUser); $share->setSharedBy($this->currentUser->getUID());
try { try {
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
@ -333,8 +340,8 @@ class Share20OCS {
* @return \OC_OCS_Result * @return \OC_OCS_Result
*/ */
private function getSharedWithMe($node = null) { private function getSharedWithMe($node = null) {
$userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); $userShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
$groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); $groupShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
$shares = array_merge($userShares, $groupShares); $shares = array_merge($userShares, $groupShares);
@ -361,9 +368,9 @@ class Share20OCS {
/** @var \OCP\Share\IShare[] $shares */ /** @var \OCP\Share\IShare[] $shares */
$shares = []; $shares = [];
foreach ($nodes as $node) { foreach ($nodes as $node) {
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0));
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0));
//TODO: Add federated shares //TODO: Add federated shares
} }
@ -417,9 +424,9 @@ class Share20OCS {
} }
// Get all shares // Get all shares
$userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); $userShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
$groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); $groupShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
$linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); $linkShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
//TODO: Add federated shares //TODO: Add federated shares
$shares = array_merge($userShares, $groupShares, $linkShares); $shares = array_merge($userShares, $groupShares, $linkShares);
@ -538,14 +545,6 @@ class Share20OCS {
return new \OC_OCS_Result($this->formatShare($share)); return new \OC_OCS_Result($this->formatShare($share));
} }
public function validatePermissions($permissions) {
if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
return false;
}
}
/** /**
* @param \OCP\Share\IShare $share * @param \OCP\Share\IShare $share
* @return bool * @return bool
@ -557,21 +556,23 @@ class Share20OCS {
} }
// Owner of the file and the sharer of the file can always get share // Owner of the file and the sharer of the file can always get share
if ($share->getShareOwner() === $this->currentUser || if ($share->getShareOwner() === $this->currentUser->getUID() ||
$share->getSharedBy() === $this->currentUser $share->getSharedBy() === $this->currentUser->getUID()
) { ) {
return true; return true;
} }
// If the share is shared with you (or a group you are a member of) // If the share is shared with you (or a group you are a member of)
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $this->currentUser) { $share->getSharedWith() === $this->currentUser->getUID()) {
return true; return true;
} }
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$share->getSharedWith()->inGroup($this->currentUser)) { $sharedWith = $this->groupManager->get($share->getSharedWith());
return true; if ($sharedWith->inGroup($this->currentUser)) {
return true;
}
} }
return false; return false;

View File

@ -55,7 +55,7 @@ class Share20OCSTest extends \Test\TestCase {
private $ocs; private $ocs;
protected function setUp() { protected function setUp() {
$this->shareManager = $this->getMockBuilder('OC\Share20\Manager') $this->shareManager = $this->getMockBuilder('OCP\Share\IManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->groupManager = $this->getMock('OCP\IGroupManager'); $this->groupManager = $this->getMock('OCP\IGroupManager');
@ -91,6 +91,10 @@ class Share20OCSTest extends \Test\TestCase {
->getMock(); ->getMock();
} }
private function newShare() {
return \OC::$server->getShareManager()->newShare();
}
public function testDeleteShareShareNotFound() { public function testDeleteShareShareNotFound() {
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
@ -103,8 +107,8 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testDeleteShare() { public function testDeleteShare() {
$share = $this->getMock('OCP\Share\IShare'); $share = $this->newShare();
$share->method('getSharedBy')->willReturn($this->currentUser); $share->setSharedBy($this->currentUser->getUID());
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
->method('getShareById') ->method('getShareById')
@ -137,7 +141,7 @@ class Share20OCSTest extends \Test\TestCase {
public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $token=null, $shareTime, $expiration, $parent, $target, $mail_send, $token=null,
$password=null) { $password=null) {
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn($id); $share->method('getId')->willReturn($id);
$share->method('getShareType')->willReturn($shareType); $share->method('getShareType')->willReturn($shareType);
$share->method('getSharedWith')->willReturn($sharedWith); $share->method('getSharedWith')->willReturn($sharedWith);
@ -166,21 +170,6 @@ class Share20OCSTest extends \Test\TestCase {
public function dataGetShare() { public function dataGetShare() {
$data = []; $data = [];
$initiator = $this->getMock('OCP\IUser');
$initiator->method('getUID')->willReturn('initiatorId');
$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
$owner = $this->getMock('OCP\IUser');
$owner->method('getUID')->willReturn('ownerId');
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$user = $this->getMock('OCP\IUser');
$user->method('getUID')->willReturn('userId');
$user->method('getDisplayName')->willReturn('userDisplay');
$group = $this->getMock('OCP\IGroup');
$group->method('getGID')->willReturn('groupId');
$cache = $this->getMockBuilder('OC\Files\Cache\Cache') $cache = $this->getMockBuilder('OC\Files\Cache\Cache')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -211,9 +200,9 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->createShare( $share = $this->createShare(
100, 100,
\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_USER,
$user, 'userId',
$initiator, 'initiatorId',
$owner, 'ownerId',
$file, $file,
4, 4,
5, 5,
@ -252,9 +241,9 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->createShare( $share = $this->createShare(
101, 101,
\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_GROUP,
$group, 'groupId',
$initiator, 'initiatorId',
$owner, 'ownerId',
$folder, $folder,
4, 4,
5, 5,
@ -295,8 +284,8 @@ class Share20OCSTest extends \Test\TestCase {
101, 101,
\OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_LINK,
null, null,
$initiator, 'initiatorId',
$owner, 'ownerId',
$folder, $folder,
4, 4,
5, 5,
@ -367,29 +356,53 @@ class Share20OCSTest extends \Test\TestCase {
->will($this->returnArgument(0)); ->will($this->returnArgument(0));
$this->rootFolder->method('getUserFolder') $this->rootFolder->method('getUserFolder')
->with($share->getShareOwner()->getUID()) ->with($share->getShareOwner())
->willReturn($userFolder); ->willReturn($userFolder);
$this->urlGenerator $this->urlGenerator
->method('linkToRouteAbsolute') ->method('linkToRouteAbsolute')
->willReturn('url'); ->willReturn('url');
$initiator = $this->getMock('OCP\IUser');
$initiator->method('getUID')->willReturn('initiatorId');
$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
$owner = $this->getMock('OCP\IUser');
$owner->method('getUID')->willReturn('ownerId');
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$user = $this->getMock('OCP\IUser');
$user->method('getUID')->willReturn('userId');
$user->method('getDisplayName')->willReturn('userDisplay');
$group = $this->getMock('OCP\IGroup');
$group->method('getGID')->willReturn('groupId');
$this->userManager->method('get')->will($this->returnValueMap([
['userId', $user],
['initiatorId', $initiator],
['ownerId', $owner],
]));
$this->groupManager->method('get')->will($this->returnValueMap([
['group', $group],
]));
$expected = new \OC_OCS_Result($result); $expected = new \OC_OCS_Result($result);
$this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData()); $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData());
} }
public function testCanAccessShare() { public function testCanAccessShare() {
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareOwner')->willReturn($this->currentUser); $share->method('getShareOwner')->willReturn($this->currentUser->getUID());
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getSharedBy')->willReturn($this->currentUser); $share->method('getSharedBy')->willReturn($this->currentUser->getUID());
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser); $share->method('getSharedWith')->willReturn($this->currentUser->getUID());
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
@ -399,16 +412,25 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$share->method('getSharedWith')->willReturn('group');
$group = $this->getMock('OCP\IGroup'); $group = $this->getMock('OCP\IGroup');
$group->method('inGroup')->with($this->currentUser)->willReturn(true); $group->method('inGroup')->with($this->currentUser)->willReturn(true);
$share->method('getSharedWith')->willReturn($group); $group2 = $this->getMock('OCP\IGroup');
$group2->method('inGroup')->with($this->currentUser)->willReturn(false);
$this->groupManager->method('get')->will($this->returnValueMap([
['group', $group],
['group2', $group2],
]));
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$group = $this->getMock('OCP\IGroup'); $share->method('getSharedWith')->willReturn('group2');
$group->method('inGroup')->with($this->currentUser)->willReturn(false);
$share->method('getSharedWith')->willReturn($group); $this->groupManager->method('get')->with('group2')->willReturn($group);
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
@ -587,7 +609,6 @@ class Share20OCSTest extends \Test\TestCase {
$user = $this->getMock('\OCP\IUser'); $user = $this->getMock('\OCP\IUser');
$this->userManager->method('userExists')->with('validUser')->willReturn(true); $this->userManager->method('userExists')->with('validUser')->willReturn(true);
$this->userManager->method('get')->with('validUser')->willReturn($user);
$share->method('setPath')->with($path); $share->method('setPath')->with($path);
$share->method('setPermissions') $share->method('setPermissions')
@ -596,8 +617,8 @@ class Share20OCSTest extends \Test\TestCase {
~\OCP\Constants::PERMISSION_DELETE & ~\OCP\Constants::PERMISSION_DELETE &
~\OCP\Constants::PERMISSION_CREATE); ~\OCP\Constants::PERMISSION_CREATE);
$share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_USER); $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_USER);
$share->method('setSharedWith')->with($user); $share->method('setSharedWith')->with('validUser');
$share->method('setSharedBy')->with($this->currentUser); $share->method('setSharedBy')->with('currentUser');
$expected = new \OC_OCS_Result(); $expected = new \OC_OCS_Result();
$result = $ocs->createShare(); $result = $ocs->createShare();
@ -680,13 +701,12 @@ class Share20OCSTest extends \Test\TestCase {
$group = $this->getMock('\OCP\IGroup'); $group = $this->getMock('\OCP\IGroup');
$this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
$this->groupManager->method('get')->with('validGroup')->willReturn($group);
$share->method('setPath')->with($path); $share->method('setPath')->with($path);
$share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL); $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL);
$share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP); $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP);
$share->method('setSharedWith')->with($group); $share->method('setSharedWith')->with('validGroup');
$share->method('setSharedBy')->with($this->currentUser); $share->method('setSharedBy')->with('currentUser');
$expected = new \OC_OCS_Result(); $expected = new \OC_OCS_Result();
$result = $ocs->createShare(); $result = $ocs->createShare();
@ -784,14 +804,12 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$currentUser = $this->currentUser;
$this->shareManager->expects($this->once())->method('createShare')->with( $this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (\OCP\Share\IShare $share) use ($path, $currentUser) { $this->callback(function (\OCP\Share\IShare $share) use ($path) {
return $share->getNode() === $path && return $share->getNode() === $path &&
$share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
$share->getPermissions() === \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE && $share->getPermissions() === \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE &&
$share->getSharedBy() === $currentUser && $share->getSharedBy() === 'currentUser' &&
$share->getPassword() === null && $share->getPassword() === null &&
$share->getExpirationDate() === null; $share->getExpirationDate() === null;
}) })
@ -825,14 +843,12 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$currentUser = $this->currentUser;
$this->shareManager->expects($this->once())->method('createShare')->with( $this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (\OCP\Share\IShare $share) use ($path, $currentUser) { $this->callback(function (\OCP\Share\IShare $share) use ($path) {
return $share->getNode() === $path && return $share->getNode() === $path &&
$share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
$share->getPermissions() === \OCP\Constants::PERMISSION_READ && $share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
$share->getSharedBy() === $currentUser && $share->getSharedBy() === 'currentUser' &&
$share->getPassword() === 'password' && $share->getPassword() === 'password' &&
$share->getExpirationDate() === null; $share->getExpirationDate() === null;
}) })
@ -866,17 +882,15 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$currentUser = $this->currentUser;
$this->shareManager->expects($this->once())->method('createShare')->with( $this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (\OCP\Share\IShare $share) use ($path, $currentUser) { $this->callback(function (\OCP\Share\IShare $share) use ($path) {
$date = new \DateTime('2000-01-01'); $date = new \DateTime('2000-01-01');
$date->setTime(0,0,0); $date->setTime(0,0,0);
return $share->getNode() === $path && return $share->getNode() === $path &&
$share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
$share->getPermissions() === \OCP\Constants::PERMISSION_READ && $share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
$share->getSharedBy() === $currentUser && $share->getSharedBy() === 'currentUser' &&
$share->getPassword() === null && $share->getPassword() === null &&
$share->getExpirationDate() == $date; $share->getExpirationDate() == $date;
}) })
@ -932,7 +946,7 @@ class Share20OCSTest extends \Test\TestCase {
public function testUpdateNoParametersLink() { public function testUpdateNoParametersLink() {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK); ->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@ -947,7 +961,7 @@ class Share20OCSTest extends \Test\TestCase {
public function testUpdateNoParametersOther() { public function testUpdateNoParametersOther() {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_GROUP); ->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@ -964,7 +978,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate(new \DateTime()) ->setExpirationDate(new \DateTime())
@ -1002,7 +1016,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setNode($folder); ->setNode($folder);
@ -1042,7 +1056,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setNode($folder); ->setNode($folder);
@ -1071,7 +1085,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setNode($folder); ->setNode($folder);
@ -1100,7 +1114,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setNode($file); ->setNode($file);
@ -1130,7 +1144,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate($date) ->setExpirationDate($date)
@ -1164,7 +1178,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate(new \DateTime()) ->setExpirationDate(new \DateTime())
@ -1205,7 +1219,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate($date) ->setExpirationDate($date)
@ -1245,7 +1259,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate($date) ->setExpirationDate($date)
@ -1285,7 +1299,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPassword('password') ->setPassword('password')
->setExpirationDate($date) ->setExpirationDate($date)
@ -1315,7 +1329,7 @@ class Share20OCSTest extends \Test\TestCase {
$share = \OC::$server->getShareManager()->newShare(); $share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL) $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser) ->setSharedBy($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setNode($file); ->setNode($file);