Skip to content

Commit

Permalink
fix(integration): Honor sharing to group members restriction
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst authored and backportbot[bot] committed Aug 13, 2024
1 parent ec37b46 commit 8c60504
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/Service/Group/NextcloudGroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions tests/Unit/Service/Group/NextcloudGroupServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function createTestUser($id, $name, $email) {

public function dataForTestSearch(): array {
return [
['yes', [
['yes', 'no', [
[
'id' => 'testgroup',
'name' => 'first test group',
Expand All @@ -93,7 +93,9 @@ public function dataForTestSearch(): array {
'name' => 'second test group',
]
]],
['no', []]
['no', 'yes', []],
['no', 'no', []],
['yes', 'yes', []],
];
}

Expand All @@ -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);
Expand Down

0 comments on commit 8c60504

Please sign in to comment.