Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix external share manager with multiple user groups
Use query builder with proper matching for finding the group names.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Aug 10, 2021
commit df0ca2f1db8b3bacf8fd6b9b927f370b377acdee
23 changes: 15 additions & 8 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent;
use OCA\Files_Sharing\Helper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
Expand Down Expand Up @@ -740,16 +741,22 @@ private function getShares($accepted) {
$userGroups[] = $group->getGID();
}

// FIXME: use query builder
$query = 'SELECT `id`, `share_type`, `parent`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
FROM `*PREFIX*share_external`
WHERE (`user` = ? OR `user` IN (?))';
$parameters = [$this->uid, implode(',', $userGroups)];
$query .= ' ORDER BY `id` ASC';
$qb = $this->connection->getQueryBuilder();
$qb->select('id', 'share_type', 'parent', 'remote', 'remote_id', 'share_token', 'name', 'owner', 'user', 'mountpoint', 'accepted')
->from('share_external')
->where(
$qb->expr()->orX(
$qb->expr()->eq('user', $qb->createNamedParameter($this->uid)),
$qb->expr()->in(
'user',
$qb->createNamedParameter($userGroups, IQueryBuilder::PARAM_STR_ARRAY)
)
)
)
->orderBy('id', 'ASC');

$sharesQuery = $this->connection->prepare($query);
try {
$result = $sharesQuery->execute($parameters);
$result = $qb->execute();
$shares = $result->fetchAll();
$result->closeCursor();

Expand Down
12 changes: 10 additions & 2 deletions apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ protected function setUp(): void {
$group1->expects($this->any())->method('getGID')->willReturn('group1');
$group1->expects($this->any())->method('inGroup')->with($this->user)->willReturn(true);

$group2 = $this->createMock(IGroup::class);
$group2->expects($this->any())->method('getGID')->willReturn('group2');
$group2->expects($this->any())->method('inGroup')->with($this->user)->willReturn(true);

$this->userManager->expects($this->any())->method('get')->willReturn($this->user);
$this->groupManager->expects($this->any())->method(('getUserGroups'))->willReturn([$group1]);
$this->groupManager->expects($this->any())->method(('get'))->with('group1')->willReturn($group1);
$this->groupManager->expects($this->any())->method(('getUserGroups'))->willReturn([$group1, $group2]);
$this->groupManager->expects($this->any())->method(('get'))
->will($this->returnValueMap([
['group1', $group1],
['group2', $group2],
]));
}

protected function tearDown(): void {
Expand Down