Merge pull request #9788 from nextcloud/fix/integration/nextcloud-sharing-groups-restriction

fix(integration): Honor sharing to group members restriction
This commit is contained in:
Richard Steinmetz 2024-08-13 15:06:21 +02:00 коммит произвёл GitHub
Родитель 649f29e6d2 fb4ae5e5d4
Коммит 846c85301e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 15 добавлений и 8 удалений

Просмотреть файл

@ -43,7 +43,10 @@ class NextcloudGroupService implements IGroupService {
}
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);

Просмотреть файл

@ -68,7 +68,7 @@ class NextcloudGroupServiceTest extends TestCase {
public function dataForTestSearch(): array {
return [
['yes', [
['yes', 'no', [
[
'id' => 'testgroup',
'name' => 'first test group',
@ -78,7 +78,9 @@ class NextcloudGroupServiceTest extends TestCase {
'name' => 'second test group',
]
]],
['no', []]
['no', 'yes', []],
['no', 'no', []],
['yes', 'yes', []],
];
}
@ -88,22 +90,24 @@ class NextcloudGroupServiceTest extends TestCase {
* @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);