diff --git a/lib/Service/Group/NextcloudGroupService.php b/lib/Service/Group/NextcloudGroupService.php index bc09246969..1fb6a9da7a 100644 --- a/lib/Service/Group/NextcloudGroupService.php +++ b/lib/Service/Group/NextcloudGroupService.php @@ -58,7 +58,10 @@ public function getNamespace(): string { } public function search(string $term): array { - if ($this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') !== 'yes') { + $c1 = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'); + $c2 = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no'); + if ($c1 !== 'yes' + || $c2 !== 'no') { return []; } $groups = $this->groupManager->search($term); diff --git a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php index 7ceee918e7..1923e95b4c 100644 --- a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php +++ b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php @@ -83,7 +83,7 @@ private function createTestUser($id, $name, $email) { public function dataForTestSearch(): array { return [ - ['yes', [ + ['yes', 'no', [ [ 'id' => 'testgroup', 'name' => 'first test group', @@ -93,7 +93,9 @@ public function dataForTestSearch(): array { 'name' => 'second test group', ] ]], - ['no', []] + ['no', 'yes', []], + ['no', 'no', []], + ['yes', 'yes', []], ]; } @@ -103,22 +105,24 @@ public function dataForTestSearch(): array { * @param string $allowGroupSharing * @param array $expected */ - public function testSearch(string $allowGroupSharing, array $expected): void { + public function testSearch(string $allowGroupSharing, string $restrictSharingToGroups, array $expected): void { $term = 'te'; // searching for: John Doe $searchResult = [ $this->createTestGroup('testgroup', 'first test group'), $this->createTestGroup('testgroup2', 'second test group'), ]; - $this->groupsManager->expects($allowGroupSharing === 'yes' ? self::once() : self::never()) + $this->groupsManager->expects(($allowGroupSharing === 'yes' && $restrictSharingToGroups === 'no') ? self::once() : self::never()) ->method('search') ->with($term) ->willReturn($searchResult); - $this->config->expects(self::once()) + $this->config->expects(self::exactly(2)) ->method('getAppValue') - ->with('core', 'shareapi_allow_group_sharing', 'yes') - ->willReturn($allowGroupSharing); + ->willReturnMap([ + ['core', 'shareapi_allow_group_sharing', 'yes', $allowGroupSharing], + ['core', 'shareapi_only_share_with_group_members', 'no', $restrictSharingToGroups], + ]); $actual = $this->groupService->search($term);