use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\NotFoundException;
use OCP\IGroup;
-use OCP\IUser;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Files\IRootFolder;
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
//Set the UID of the user we share with
- /** @var IUser $sharedWith */
- $sharedWith = $share->getSharedWith();
- $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getUID()));
+ $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Set the GID of the group we share with
- /** @var IGroup $sharedWith */
- $sharedWith = $share->getSharedWith();
- $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getGID()));
+ $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
//Set the token of the share
$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
// Set who created this share
- $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()));
+ $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
// Set who is the owner of this file/folder (and this the owner of the share)
- $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()));
+ $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
// Set the file target
$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
- ->set('share_with', $qb->createNamedParameter($share->getSharedWith()->getUID()))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute();
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
->set('share_with', $qb->createNamedParameter($share->getPassword()))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
* FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
*
* @param \OCP\Share\IShare $parent
- * @return IShare[]
+ * @return \OCP\Share\IShare[]
*/
public function getChildren(\OCP\Share\IShare $parent) {
$children = [];
* this means we need a special entry in the share db.
*
* @param \OCP\Share\IShare $share
- * @param IUser $recipient
+ * @param string $recipient UserId of recipient
* @throws BackendError
* @throws ProviderException
*/
- public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) {
+ public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- /** @var IGroup $group */
- $group = $share->getSharedWith();
+ $group = $this->groupManager->get($share->getSharedWith());
+ $user = $this->userManager->get($recipient);
- if (!$group->inGroup($recipient)) {
+ if (!$group->inGroup($user)) {
throw new ProviderException('Recipient not in receiving group');
}
$stmt = $qb->select('*')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->execute();
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
- 'share_with' => $qb->createNamedParameter($recipient->getUID()),
- 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()),
- 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
+ 'share_with' => $qb->createNamedParameter($recipient),
+ 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
+ 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($type),
'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
/**
* @inheritdoc
*/
- public function move(\OCP\Share\IShare $share, IUser $recipient) {
+ public function move(\OCP\Share\IShare $share, $recipient) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// Just update the target
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('id')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->setMaxResults(1)
->execute();
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
- 'share_with' => $qb->createNamedParameter($recipient->getUID()),
- 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()),
- 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
+ 'share_with' => $qb->createNamedParameter($recipient),
+ 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
+ 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
/**
* Get all shares by the given user. Sharetype and path can be used to filter.
*
- * @param IUser $user
+ * @param string $userId
* @param int $shareType
* @param \OCP\Files\File|\OCP\Files\Folder $node
* @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
* @param int $offset
* @return Share[]
*/
- public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset) {
+ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share');
if ($reshares === false) {
//Special case for old shares created via the web UI
$or1 = $qb->expr()->andX(
- $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())),
+ $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
$qb->expr()->isNull('uid_initiator')
);
$qb->andWhere(
$qb->expr()->orX(
- $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())),
+ $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
$or1
)
);
} else {
$qb->andWhere(
$qb->expr()->orX(
- $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())),
- $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID()))
+ $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
+ $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
)
);
}
/**
* @inheritdoc
*/
- public function getShareById($id, $recipient = null) {
+ public function getShareById($id, $recipientId = null) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
}
// If the recipient is set for a group share resolve to that user
- if ($recipient !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $share = $this->resolveGroupShare($share, $recipient);
+ if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $share = $this->resolveGroupShare($share, $recipientId);
}
return $share;
* Get shares for a given path
*
* @param \OCP\Files\Node $path
- * @return IShare[]
+ * @return \OCP\Share\IShare[]
*/
public function getSharesByPath(Node $path) {
$qb = $this->dbConn->getQueryBuilder();
/**
* @inheritdoc
*/
- public function getSharedWith(IUser $user, $shareType, $node, $limit, $offset) {
+ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
/** @var Share[] $shares */
$shares = [];
$qb->setFirstResult($offset);
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
- $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID())));
+ $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
// Filter by node if provided
if ($node !== null) {
$cursor->closeCursor();
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
+ $user = $this->userManager->get($userId);
$allGroups = $this->groupManager->getUserGroups($user);
/** @var Share[] $shares2 */
* TODO: Optmize this!
*/
foreach($shares2 as $share) {
- $shares[] = $this->resolveGroupShare($share, $user);
+ $shares[] = $this->resolveGroupShare($share, $userId);
}
} else {
throw new BackendError('Invalid backend');
* Get a share by token
*
* @param string $token
- * @return IShare
+ * @return \OCP\Share\IShare
* @throws ShareNotFound
*/
public function getShareByToken($token) {
$share->setShareTime($shareTime);
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $this->userManager->get($data['share_with']);
- if ($sharedWith === null) {
- throw new InvalidShare();
- }
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith($data['share_with']);
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $this->groupManager->get($data['share_with']);
- if ($sharedWith === null) {
- throw new InvalidShare();
- }
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith($data['share_with']);
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$share->setPassword($data['share_with']);
$share->setToken($data['token']);
if ($data['uid_initiator'] === null) {
//OLD SHARE
- $sharedBy = $this->userManager->get($data['uid_owner']);
- if ($sharedBy === null) {
- throw new InvalidShare();
- }
- $share->setSharedBy($sharedBy);
+ $share->setSharedBy($data['uid_owner']);
$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
$owner = $path->getOwner();
- $share->setShareOwner($owner);
+ $share->setShareOwner($owner->getUID());
} else {
//New share!
- $sharedBy = $this->userManager->get($data['uid_initiator']);
- $shareOwner = $this->userManager->get($data['uid_owner']);
- if ($sharedBy === null || $shareOwner === null) {
- throw new InvalidShare();
- }
- $share->setSharedBy($sharedBy);
- $share->setShareOwner($shareOwner);
+ $share->setSharedBy($data['uid_initiator']);
+ $share->setShareOwner($data['uid_owner']);
}
$path = $this->getNode($share->getShareOwner(), (int)$data['file_source']);
/**
* Get the node with file $id for $user
*
- * @param IUser $user
+ * @param string $user The userId
* @param int $id
* @return \OCP\Files\File|\OCP\Files\Folder
* @throws InvalidShare
*/
- private function getNode(IUser $user, $id) {
+ private function getNode($user, $id) {
try {
- $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $userFolder = $this->rootFolder->getUserFolder($user);
} catch (NotFoundException $e) {
throw new InvalidShare();
}
* Resolve a group share to a user specific share
* Thus if the user moved their group share make sure this is properly reflected here.
*
- * @param Share $share
- * @param IUser $user
+ * @param \OCP\Share\IShare $share
+ * @param string $userId
* @return Share Returns the updated share if one was found else return the original share.
*/
- private function resolveGroupShare(Share $share, IUser $user) {
+ private function resolveGroupShare(\OCP\Share\IShare $share, $userId) {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('*')
->from('share')
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
->setMaxResults(1)
->execute();
['shareOwner', $shareOwnerFolder],
]));
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedWith', $sharedWith],
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
-
$share = $this->provider->getShareById($id);
$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('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());
['shareOwner', $shareOwnerFolder],
]));
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
- $this->groupManager
- ->expects($this->once())
- ->method('get')
- ->with('sharedWith')
- ->willReturn($sharedWith);
-
$share = $this->provider->getShareById($id);
$this->assertEquals($id, $share->getId());
$this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
- $this->assertEquals($sharedWith, $share->getSharedWith());
- $this->assertEquals($sharedBy, $share->getSharedBy());
- $this->assertEquals($shareOwner, $share->getShareOwner());
+ $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->groupManager->method('get')->with('group0')->willReturn($group0);
- $share = $this->provider->getShareById($id, $user1);
+ $share = $this->provider->getShareById($id, 'user1');
$this->assertEquals($id, $share->getId());
$this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
- $this->assertSame($group0, $share->getSharedWith());
- $this->assertSame($user0, $share->getSharedBy());
- $this->assertSame($user0, $share->getShareOwner());
+ $this->assertSame('group0', $share->getSharedWith());
+ $this->assertSame('user0', $share->getSharedBy());
+ $this->assertSame('user0', $share->getShareOwner());
$this->assertSame($node, $share->getNode());
$this->assertEquals(0, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals($id, $share->getId());
$this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
$this->assertEquals('sharedWith', $share->getPassword());
- $this->assertEquals($sharedBy, $share->getSharedBy());
- $this->assertEquals($shareOwner, $share->getShareOwner());
+ $this->assertEquals('sharedBy', $share->getSharedBy());
+ $this->assertEquals('shareOwner', $share->getShareOwner());
$this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals('token', $share->getToken());
//Child1
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $children[0]->getShareType());
- $this->assertEquals($user1, $children[0]->getSharedWith());
- $this->assertEquals($user2, $children[0]->getSharedBy());
- $this->assertEquals($shareOwner, $children[0]->getShareOwner());
+ $this->assertEquals('user1', $children[0]->getSharedWith());
+ $this->assertEquals('user2', $children[0]->getSharedBy());
+ $this->assertEquals('shareOwner', $children[0]->getShareOwner());
$this->assertEquals($ownerPath, $children[0]->getNode());
$this->assertEquals(2, $children[0]->getPermissions());
$this->assertEquals(null, $children[0]->getToken());
//Child2
$this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $children[1]->getShareType());
- $this->assertEquals($group1, $children[1]->getSharedWith());
- $this->assertEquals($user3, $children[1]->getSharedBy());
- $this->assertEquals($shareOwner, $children[1]->getShareOwner());
+ $this->assertEquals('group1', $children[1]->getSharedWith());
+ $this->assertEquals('user3', $children[1]->getSharedBy());
+ $this->assertEquals('shareOwner', $children[1]->getShareOwner());
$this->assertEquals($ownerPath, $children[1]->getNode());
$this->assertEquals(4, $children[1]->getPermissions());
$this->assertEquals(null, $children[1]->getToken());
public function testCreateUserShare() {
$share = new \OC\Share20\Share();
- $sharedWith = $this->getMock('OCP\IUser');
- $sharedWith->method('getUID')->willReturn('sharedWith');
- $sharedBy = $this->getMock('OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->WillReturn('shareOwner');
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedWith', $sharedWith],
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
-
$path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(100);
$path->method('getOwner')->willReturn($shareOwner);
->willReturn([$path]);
$share->setShareType(\OCP\Share::SHARE_TYPE_USER);
- $share->setSharedWith($sharedWith);
- $share->setSharedBy($sharedBy);
- $share->setShareOwner($shareOwner);
+ $share->setSharedWith('sharedWith');
+ $share->setSharedBy('sharedBy');
+ $share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setTarget('/target');
$this->assertNotNull($share2->getId());
$this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
$this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share2->getShareType());
- $this->assertSame($sharedWith, $share2->getSharedWith());
- $this->assertSame($sharedBy, $share2->getSharedBy());
- $this->assertSame($shareOwner, $share2->getShareOwner());
+ $this->assertSame('sharedWith', $share2->getSharedWith());
+ $this->assertSame('sharedBy', $share2->getSharedBy());
+ $this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
public function testCreateGroupShare() {
$share = new \OC\Share20\Share();
- $sharedWith = $this->getMock('OCP\IGroup');
- $sharedWith->method('getGID')->willReturn('sharedWith');
- $sharedBy = $this->getMock('OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
- $shareOwner = $this->getMock('OCP\IUser');
- $shareOwner->method('getUID')->WillReturn('shareOwner');
-
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
- $this->groupManager
- ->method('get')
- ->with('sharedWith')
- ->willReturn($sharedWith);
+ $shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\Folder');
$path->method('getId')->willReturn(100);
->willReturn([$path]);
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
- $share->setSharedWith($sharedWith);
- $share->setSharedBy($sharedBy);
- $share->setShareOwner($shareOwner);
+ $share->setSharedWith('sharedWith');
+ $share->setSharedBy('sharedBy');
+ $share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setTarget('/target');
$this->assertNotNull($share2->getId());
$this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
$this->assertSame(\OCP\Share::SHARE_TYPE_GROUP, $share2->getShareType());
- $this->assertSame($sharedWith, $share2->getSharedWith());
- $this->assertSame($sharedBy, $share2->getSharedBy());
- $this->assertSame($shareOwner, $share2->getShareOwner());
+ $this->assertSame('sharedWith', $share2->getSharedWith());
+ $this->assertSame('sharedBy', $share2->getSharedBy());
+ $this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
public function testCreateLinkShare() {
$share = new \OC\Share20\Share();
- $sharedBy = $this->getMock('OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
- $shareOwner = $this->getMock('OCP\IUser');
- $shareOwner->method('getUID')->WillReturn('shareOwner');
-
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
+ $shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\Folder');
$path->method('getId')->willReturn(100);
->willReturn([$path]);
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
- $share->setSharedBy($sharedBy);
- $share->setShareOwner($shareOwner);
+ $share->setSharedBy('sharedBy');
+ $share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setPassword('password');
$this->assertNotNull($share2->getId());
$this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
$this->assertSame(\OCP\Share::SHARE_TYPE_LINK, $share2->getShareType());
- $this->assertSame($sharedBy, $share2->getSharedBy());
- $this->assertSame($shareOwner, $share2->getShareOwner());
+ $this->assertSame('sharedBy', $share2->getSharedBy());
+ $this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$qb->execute();
$id = $qb->getLastInsertId();
- $owner = $this->getMock('\OCP\IUser');
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->getMock('\OCP\IUser');
- $initiator->method('getUID')->willReturn('sharedBy');
-
- $this->userManager->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $initiator],
- ['shareOwner', $owner],
- ]));
-
$file = $this->getMock('\OCP\Files\File');
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$share = $this->provider->getShareByToken('secrettoken');
$this->assertEquals($id, $share->getId());
- $this->assertSame($owner, $share->getShareOwner());
- $this->assertSame($initiator, $share->getSharedBy());
+ $this->assertSame('shareOwner', $share->getShareOwner());
+ $this->assertSame('sharedBy', $share->getSharedBy());
$this->assertSame('secrettoken', $share->getToken());
$this->assertSame('password', $share->getPassword());
$this->assertSame(null, $share->getSharedWith());
]);
$this->assertEquals(1, $qb->execute());
- $user = $this->getMock('\OCP\IUser');
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->getMock('\OCP\IUser');
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->getMock('\OCP\IUser');
- $initiator->method('getUID')->willReturn('sharedBy');
-
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
-
$file = $this->getMock('\OCP\Files\File');
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_USER, null, 1 , 0);
+ $share = $this->provider->getSharedWith('sharedWith', \OCP\Share::SHARE_TYPE_USER, null, 1 , 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertEquals($user, $share->getSharedWith());
- $this->assertEquals($owner, $share->getShareOwner());
- $this->assertEquals($initiator, $share->getSharedBy());
+ $this->assertEquals('sharedWith', $share->getSharedWith());
+ $this->assertEquals('shareOwner', $share->getShareOwner());
+ $this->assertEquals('sharedBy', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
}
$initiator->method('getUID')->willReturn('sharedBy');
$this->userManager->method('get')->willReturnMap([
+ ['sharedWith', $user],
['shareOwner', $owner],
['sharedBy', $initiator],
]);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, null, 20 , 1);
+ $share = $this->provider->getSharedWith('sharedWith', \OCP\Share::SHARE_TYPE_GROUP, null, 20 , 1);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertEquals($group, $share->getSharedWith());
- $this->assertEquals($owner, $share->getShareOwner());
- $this->assertEquals($initiator, $share->getSharedBy());
+ $this->assertEquals('sharedWith', $share->getSharedWith());
+ $this->assertEquals('shareOwner', $share->getShareOwner());
+ $this->assertEquals('sharedBy', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
}
$initiator->method('getUID')->willReturn('sharedBy');
$this->userManager->method('get')->willReturnMap([
+ ['user', $user],
['shareOwner', $owner],
['sharedBy', $initiator],
]);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
+ $share = $this->provider->getSharedWith('user', \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertSame($id, $share->getId());
- $this->assertSame($group, $share->getSharedWith());
- $this->assertSame($owner, $share->getShareOwner());
- $this->assertSame($initiator, $share->getSharedBy());
+ $this->assertSame('sharedWith', $share->getSharedWith());
+ $this->assertSame('shareOwner', $share->getShareOwner());
+ $this->assertSame('sharedBy', $share->getSharedBy());
$this->assertSame(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
$this->assertSame(0, $share->getPermissions());
$this->assertSame('userTarget', $share->getTarget());
$this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(43)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user0, \OCP\Share::SHARE_TYPE_USER, $file, -1, 0);
+ $share = $this->provider->getSharedWith('user0', \OCP\Share::SHARE_TYPE_USER, $file, -1, 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertSame($user0, $share->getSharedWith());
- $this->assertSame($user1, $share->getShareOwner());
- $this->assertSame($user1, $share->getSharedBy());
+ $this->assertSame('user0', $share->getSharedWith());
+ $this->assertSame('user1', $share->getShareOwner());
+ $this->assertSame('user1', $share->getSharedBy());
$this->assertSame($file, $share->getNode());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
}
$this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(43)->willReturn([$node]);
- $share = $this->provider->getSharedWith($user0, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
+ $share = $this->provider->getSharedWith('user0', \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertSame($group0, $share->getSharedWith());
- $this->assertSame($user1, $share->getShareOwner());
- $this->assertSame($user1, $share->getSharedBy());
+ $this->assertSame('group0', $share->getSharedWith());
+ $this->assertSame('user1', $share->getShareOwner());
+ $this->assertSame('user1', $share->getSharedBy());
$this->assertSame($node, $share->getNode());
$this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
}
]);
$this->assertEquals(1, $qb->execute());
- $user = $this->getMock('\OCP\IUser');
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->getMock('\OCP\IUser');
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->getMock('\OCP\IUser');
- $initiator->method('getUID')->willReturn('sharedBy');
-
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
-
$file = $this->getMock('\OCP\Files\File');
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharesBy($initiator, \OCP\Share::SHARE_TYPE_USER, null, false, 1, 0);
+ $share = $this->provider->getSharesBy('sharedBy', \OCP\Share::SHARE_TYPE_USER, null, false, 1, 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertEquals($user, $share->getSharedWith());
- $this->assertEquals($owner, $share->getShareOwner());
- $this->assertEquals($initiator, $share->getSharedBy());
+ $this->assertEquals('sharedWith', $share->getSharedWith());
+ $this->assertEquals('shareOwner', $share->getShareOwner());
+ $this->assertEquals('sharedBy', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals('myTarget', $share->getTarget());
]);
$this->assertEquals(1, $qb->execute());
- $user = $this->getMock('\OCP\IUser');
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->getMock('\OCP\IUser');
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->getMock('\OCP\IUser');
- $initiator->method('getUID')->willReturn('sharedBy');
-
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
-
$file = $this->getMock('\OCP\Files\File');
$file->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharesBy($initiator, \OCP\Share::SHARE_TYPE_USER, $file, false, 1, 0);
+ $share = $this->provider->getSharesBy('sharedBy', \OCP\Share::SHARE_TYPE_USER, $file, false, 1, 0);
$this->assertCount(1, $share);
$share = $share[0];
$this->assertEquals($id, $share->getId());
- $this->assertEquals($user, $share->getSharedWith());
- $this->assertEquals($owner, $share->getShareOwner());
- $this->assertEquals($initiator, $share->getSharedBy());
+ $this->assertEquals('sharedWith', $share->getSharedWith());
+ $this->assertEquals('shareOwner', $share->getShareOwner());
+ $this->assertEquals('sharedBy', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals('myTarget', $share->getTarget());
$this->assertEquals(1, $qb->execute());
$id2 = $qb->getLastInsertId();
- $user = $this->getMock('\OCP\IUser');
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->getMock('\OCP\IUser');
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->getMock('\OCP\IUser');
- $initiator->method('getUID')->willReturn('sharedBy');
-
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
-
$file = $this->getMock('\OCP\Files\File');
$file->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $shares = $this->provider->getSharesBy($owner, \OCP\Share::SHARE_TYPE_USER, null, true, -1, 0);
+ $shares = $this->provider->getSharesBy('shareOwner', \OCP\Share::SHARE_TYPE_USER, null, true, -1, 0);
$this->assertCount(2, $shares);
$share = $shares[0];
$this->assertEquals($id1, $share->getId());
- $this->assertSame($user, $share->getSharedWith());
- $this->assertSame($owner, $share->getShareOwner());
- $this->assertSame($owner, $share->getSharedBy());
+ $this->assertSame('sharedWith', $share->getSharedWith());
+ $this->assertSame('shareOwner', $share->getShareOwner());
+ $this->assertSame('shareOwner', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals('myTarget', $share->getTarget());
$share = $shares[1];
$this->assertEquals($id2, $share->getId());
- $this->assertSame($user, $share->getSharedWith());
- $this->assertSame($owner, $share->getShareOwner());
- $this->assertSame($initiator, $share->getSharedBy());
+ $this->assertSame('sharedWith', $share->getSharedWith());
+ $this->assertSame('shareOwner', $share->getShareOwner());
+ $this->assertSame('sharedBy', $share->getSharedBy());
$this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
$this->assertEquals(0, $share->getPermissions());
$this->assertEquals('userTarget', $share->getTarget());
$share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user2);
+ $this->provider->deleteFromSelf($share, 'user2');
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('*')
$share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user2);
+ $this->provider->deleteFromSelf($share, 'user2');
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('*')
$share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user2);
+ $this->provider->deleteFromSelf($share, 'user2');
}
public function testDeleteFromSelfUser() {
$share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user2);
+ $this->provider->deleteFromSelf($share, 'user2');
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('*')
$share = $this->provider->getShareById($id);
- $share->setSharedWith($users['user3']);
- $share->setSharedBy($users['user4']);
- $share->setShareOwner($users['user5']);
+ $share->setSharedWith('user3');
+ $share->setSharedBy('user4');
+ $share->setShareOwner('user5');
$share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$this->assertEquals($id, $share2->getId());
- $this->assertSame($users['user3'], $share2->getSharedWith());
- $this->assertSame($users['user4'], $share2->getSharedBy());
- $this->assertSame($users['user5'], $share2->getShareOwner());
+ $this->assertSame('user3', $share2->getSharedWith());
+ $this->assertSame('user4', $share2->getSharedBy());
+ $this->assertSame('user5', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
}
$share = $this->provider->getShareById($id);
$share->setPassword('password');
- $share->setSharedBy($users['user4']);
- $share->setShareOwner($users['user5']);
+ $share->setSharedBy('user4');
+ $share->setShareOwner('user5');
$share->setNode($file2);
$share->setPermissions(1);
$this->assertEquals($id, $share2->getId());
$this->assertEquals('password', $share->getPassword());
- $this->assertSame($users['user4'], $share2->getSharedBy());
- $this->assertSame($users['user5'], $share2->getShareOwner());
+ $this->assertSame('user4', $share2->getSharedBy());
+ $this->assertSame('user5', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
}
$share = $this->provider->getShareById($id);
$share->setPassword(null);
- $share->setSharedBy($users['user4']);
- $share->setShareOwner($users['user5']);
+ $share->setSharedBy('user4');
+ $share->setShareOwner('user5');
$share->setNode($file2);
$share->setPermissions(1);
$this->assertEquals($id, $share2->getId());
$this->assertEquals(null, $share->getPassword());
- $this->assertSame($users['user4'], $share2->getSharedBy());
- $this->assertSame($users['user5'], $share2->getShareOwner());
+ $this->assertSame('user4', $share2->getSharedBy());
+ $this->assertSame('user5', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
}
$share = $this->provider->getShareById($id);
- $share->setSharedWith($groups['group0']);
- $share->setSharedBy($users['user4']);
- $share->setShareOwner($users['user5']);
+ $share->setSharedWith('group0');
+ $share->setSharedBy('user4');
+ $share->setShareOwner('user5');
$share->setNode($file2);
$share->setPermissions(1);
$this->assertEquals($id, $share2->getId());
// Group shares do not allow updating the recipient
- $this->assertSame($groups['group0'], $share2->getSharedWith());
- $this->assertSame($users['user4'], $share2->getSharedBy());
- $this->assertSame($users['user5'], $share2->getShareOwner());
+ $this->assertSame('group0', $share2->getSharedWith());
+ $this->assertSame('user4', $share2->getSharedBy());
+ $this->assertSame('user5', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
}
$share = $this->provider->getShareById($id);
- $share->setSharedWith($groups['group0']);
- $share->setSharedBy($users['user4']);
- $share->setShareOwner($users['user5']);
+ $share->setSharedWith('group0');
+ $share->setSharedBy('user4');
+ $share->setShareOwner('user5');
$share->setNode($file2);
$share->setPermissions(1);
$this->assertEquals($id, $share2->getId());
// Group shares do not allow updating the recipient
- $this->assertSame($groups['group0'], $share2->getSharedWith());
- $this->assertSame($users['user4'], $share2->getSharedBy());
- $this->assertSame($users['user5'], $share2->getShareOwner());
+ $this->assertSame('group0', $share2->getSharedWith());
+ $this->assertSame('user4', $share2->getSharedBy());
+ $this->assertSame('user5', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$qb = $this->dbConn->getQueryBuilder();
$this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
$this->rootFolder->method('getById')->willReturn([$folder]);
- $share = $this->provider->getShareById($id, $user0);
+ $share = $this->provider->getShareById($id, 'user0');
$share->setTarget('/newTarget');
- $this->provider->move($share, $user0);
+ $this->provider->move($share, 'user0');
- $share = $this->provider->getShareById($id, $user0);
+ $share = $this->provider->getShareById($id, 'user0');
$this->assertSame('/newTarget', $share->getTarget());
$share->setTarget('/ultraNewTarget');
- $this->provider->move($share, $user0);
+ $this->provider->move($share, 'user0');
- $share = $this->provider->getShareById($id, $user0);
+ $share = $this->provider->getShareById($id, 'user0');
$this->assertSame('/ultraNewTarget', $share->getTarget());
}
}