mirror of
https://github.com/nextcloud/server.git
synced 2026-03-28 21:33:40 -04:00
Fix external share manager with multiple user groups
Use query builder with proper matching for finding the group names. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
This commit is contained in:
parent
701de23857
commit
df0ca2f1db
2 changed files with 25 additions and 10 deletions
23
apps/files_sharing/lib/External/Manager.php
vendored
23
apps/files_sharing/lib/External/Manager.php
vendored
|
|
@ -37,6 +37,7 @@ use Doctrine\DBAL\Driver\Exception;
|
|||
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;
|
||||
|
|
@ -740,16 +741,22 @@ class Manager {
|
|||
$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();
|
||||
|
||||
|
|
|
|||
|
|
@ -143,9 +143,17 @@ class ManagerTest extends TestCase {
|
|||
$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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue