Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -888,7 +887,7 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$cursor->closeCursor();
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$user = $this->userManager->get($userId);
$allGroups = $this->groupManager->getUserGroups($user);
$allGroups = $this->groupManager->getUserGroupIds($user);

/** @var Share[] $shares2 */
$shares2 = [];
Expand Down Expand Up @@ -925,12 +924,7 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
}


$groups = array_filter($groups, function ($group) {
return $group instanceof IGroup;
});
$groups = array_map(function (IGroup $group) {
return $group->getGID();
}, $groups);
$groups = array_filter($groups);

$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
Expand Down
47 changes: 15 additions & 32 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function addShareToDB($shareType, $sharedWith, $sharedBy, $shareOwner,




public function testGetShareByIdNotExist() {
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);

Expand Down Expand Up @@ -856,7 +856,7 @@ public function testGetShareByToken() {
$this->assertSame(null, $share->getSharedWith());
}


public function testGetShareByTokenNotFound() {
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);

Expand Down Expand Up @@ -986,14 +986,10 @@ public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2)

$groups = [];
foreach (range(0, 100) as $i) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups[] = $group;
$groups[] = 'group'.$i;
}

$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('sharedWith');
$groups[] = $group;
$groups[] = 'sharedWith';

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('sharedWith');
Expand All @@ -1007,8 +1003,7 @@ public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2)
['shareOwner', $owner],
['sharedBy', $initiator],
]);
$this->groupManager->method('getUserGroups')->with($user)->willReturn($groups);
$this->groupManager->method('get')->with('sharedWith')->willReturn($group);
$this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);

$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
Expand Down Expand Up @@ -1082,9 +1077,7 @@ public function testGetSharedWithGroupUserModified($storageStringId, $fileName1,
]);
$this->assertEquals(1, $qb->execute());

$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('sharedWith');
$groups = [$group];
$groups = ['sharedWith'];

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user');
Expand All @@ -1098,8 +1091,7 @@ public function testGetSharedWithGroupUserModified($storageStringId, $fileName1,
['shareOwner', $owner],
['sharedBy', $initiator],
]);
$this->groupManager->method('getUserGroups')->with($user)->willReturn($groups);
$this->groupManager->method('get')->with('sharedWith')->willReturn($group);
$this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);

$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
Expand Down Expand Up @@ -1182,11 +1174,7 @@ public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fi
['user1', $user1],
]);

$group0 = $this->createMock(IGroup::class);
$group0->method('getGID')->willReturn('group0');

$this->groupManager->method('get')->with('group0')->willReturn($group0);
$this->groupManager->method('getUserGroups')->with($user0)->willReturn([$group0]);
$this->groupManager->method('getUserGroupIds')->with($user0)->willReturn(['group0']);

$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn($fileId2);
Expand Down Expand Up @@ -1246,14 +1234,10 @@ public function testGetSharedWithWithDeletedFile($shareType, $trashed) {

$groups = [];
foreach (range(0, 100) as $i) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups[] = $group;
$groups[] = 'group'.$i;
}

$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('sharedWith');
$groups[] = $group;
$groups[] = 'sharedWith';

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('sharedWith');
Expand All @@ -1267,8 +1251,7 @@ public function testGetSharedWithWithDeletedFile($shareType, $trashed) {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
$this->groupManager->method('getUserGroups')->with($user)->willReturn($groups);
$this->groupManager->method('get')->with('sharedWith')->willReturn($group);
$this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);

$share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1 , 0);
$this->assertCount(0, $share);
Expand Down Expand Up @@ -1559,7 +1542,7 @@ public function testDeleteFromSelfGroupAlreadyCustomShare() {
$this->assertEquals('user2', $share2['share_with']);
}


public function testDeleteFromSelfGroupUserNotInGroup() {
$this->expectException(\OC\Share20\Exception\ProviderException::class);
$this->expectExceptionMessage('Recipient not in receiving group');
Expand Down Expand Up @@ -1604,7 +1587,7 @@ public function testDeleteFromSelfGroupUserNotInGroup() {
$this->provider->deleteFromSelf($share, 'user2');
}


public function testDeleteFromSelfGroupDoesNotExist() {
$this->expectException(\OC\Share20\Exception\ProviderException::class);
$this->expectExceptionMessage('Group "group" does not exist');
Expand Down Expand Up @@ -1695,7 +1678,7 @@ public function testDeleteFromSelfUser() {
$this->assertCount(0, $shares);
}


public function testDeleteFromSelfUserNotRecipient() {
$this->expectException(\OC\Share20\Exception\ProviderException::class);
$this->expectExceptionMessage('Recipient does not match');
Expand Down Expand Up @@ -1738,7 +1721,7 @@ public function testDeleteFromSelfUserNotRecipient() {
$this->provider->deleteFromSelf($share, $user3);
}


public function testDeleteFromSelfLink() {
$this->expectException(\OC\Share20\Exception\ProviderException::class);
$this->expectExceptionMessage('Invalid shareType');
Expand Down