We must resolve to the proper usergroup share

This commit is contained in:
Roeland Jago Douma 2016-01-26 12:58:41 +01:00
parent 3da78c8f1c
commit c090d709e7
2 changed files with 32 additions and 3 deletions

View File

@ -495,6 +495,9 @@ class DefaultShareProvider implements IShareProvider {
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$allGroups = $this->groupManager->getUserGroups($user);
/** @var Share[] $shares2 */
$shares2 = [];
$start = 0;
while(true) {
$groups = array_slice($allGroups, $start, 100);
@ -528,7 +531,7 @@ class DefaultShareProvider implements IShareProvider {
$offset--;
continue;
}
$shares[] = $this->createShare($data);
$shares2[] = $this->createShare($data);
}
$cursor->closeCursor();
}
@ -537,7 +540,9 @@ class DefaultShareProvider implements IShareProvider {
* Resolve all group shares to user specific shares
* TODO: Optmize this!
*/
$shares = array_map([$this, 'resolveGroupShare'], $shares);
foreach($shares2 as $share) {
$shares[] = $this->resolveGroupShare($share, $user);
}
} else {
throw new BackendError('Invalid backend');
}
@ -674,15 +679,18 @@ class DefaultShareProvider implements IShareProvider {
* Thus if the user moved their group share make sure this is properly reflected here.
*
* @param Share $share
* @param IUser $user
* @return Share Returns the updated share if one was found else return the original share.
*/
private function resolveGroupShare(Share $share) {
private function resolveGroupShare(Share $share, IUser $user) {
$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())))
->setMaxResults(1)
->execute();
$data = $stmt->fetch();

View File

@ -881,6 +881,27 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(1, $qb->execute());
$id = $qb->getLastInsertId();
/*
* Wrong share. Should not be taken by code.
*/
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->expr()->literal(2),
'share_with' => $qb->expr()->literal('user2'),
'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('wrongTarget'),
'permissions' => $qb->expr()->literal(31),
'parent' => $qb->expr()->literal($id),
]);
$this->assertEquals(1, $qb->execute());
/*
* Correct share. should be taken by code path.
*/
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([