* This allows us to retrieve usergroup shares for a given id.
If the user deleted a share or moved it this will be a different share
}
/**
- * Get share by id
- *
- * @param int $id
- * @return \OCP\Share\IShare
- * @throws ShareNotFound
+ * @inheritdoc
*/
- public function getShareById($id) {
+ public function getShareById($id, $recipient = null) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->andWhere(
$qb->expr()->in(
'share_type',
- [
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
- $qb->expr()->literal(self::SHARE_TYPE_USERGROUP),
- ]
+ $qb->createNamedParameter([
+ \OCP\Share::SHARE_TYPE_USER,
+ \OCP\Share::SHARE_TYPE_GROUP,
+ \OCP\Share::SHARE_TYPE_LINK,
+ ], IQueryBuilder::PARAM_INT_ARRAY)
)
);
throw new ShareNotFound();
}
+ // 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);
+ }
+
return $share;
}
}
/**
- * Retrieve a share by the share id
- *
- * @param string $id
- * @return Share
- *
- * @throws ShareNotFound
+ * @inheritdoc
*/
- public function getShareById($id) {
+ public function getShareById($id, $recipient = null) {
if ($id === null) {
throw new ShareNotFound();
}
list($providerId, $id) = $this->splitFullId($id);
$provider = $this->factory->getProvider($providerId);
- $share = $provider->getShareById($id);
+ $share = $provider->getShareById($id, $recipient);
return $share;
}
public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0);
/**
- * Retrieve a share by the share id
+ * Retrieve a share by the share id.
+ * If the recipient is set make sure to retrieve the file for that user.
+ * This makes sure that if a user has moved/deleted a group share this
+ * is reflected.
*
* @param string $id
- * @return Share
+ * @param IUser|null $recipient
+ * @return IShare
* @throws ShareNotFound
* @since 9.0.0
*/
- public function getShareById($id);
+ public function getShareById($id, $recipient = null);
/**
* Get the share by token possible with password
* Get share by id
*
* @param int $id
+ * @param IUser|null $recipient
* @return \OCP\Share\IShare
* @throws ShareNotFound
* @since 9.0.0
*/
- public function getShareById($id);
+ public function getShareById($id, $recipient = null);
/**
* Get shares for a given path
$this->assertEquals('myTarget', $share->getTarget());
}
+ public function testGetShareByIdUserGroupShare() {
+ $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null);
+ $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id);
+
+ $user0 = $this->getMock('OCP\IUser');
+ $user0->method('getUID')->willReturn('user0');
+ $user1 = $this->getMock('OCP\IUser');
+ $user1->method('getUID')->willReturn('user1');
+
+ $group0 = $this->getMock('OCP\IGroup');
+ $group0->method('inGroup')->with($user1)->willReturn(true);
+
+ $node = $this->getMock('\OCP\Files\Folder');
+ $node->method('getId')->willReturn(42);
+
+ $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf());
+ $this->rootFolder->method('getById')->willReturn([$node]);
+
+ $this->userManager->method('get')->will($this->returnValueMap([
+ ['user0', $user0],
+ ['user1', $user1],
+ ]));
+ $this->groupManager->method('get')->with('group0')->willReturn($group0);
+
+ $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($node, $share->getNode());
+ $this->assertEquals(0, $share->getPermissions());
+ $this->assertEquals(null, $share->getToken());
+ $this->assertEquals(null, $share->getExpirationDate());
+ $this->assertEquals('userTarget', $share->getTarget());
+ }
+
public function testGetShareByIdLinkShare() {
$qb = $this->dbConn->getQueryBuilder();