Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions lib/Service/GroupSharingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\Contacts\Service;

use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\Share\IManager as IShareManager;
Expand All @@ -29,8 +28,7 @@ public function isGroupSharingAllowed(IUser $user): bool {
return false;
}

$userGroups = $this->groupManager->getUserGroups($user);
$userGroupNames = array_map(static fn (IGroup $group) => $group->getGID(), $userGroups);
$userGroupIds = $this->groupManager->getUserGroupIds($user);

$excludeGroupList = json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', '[]'), true);
$excludeGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups');
Expand All @@ -39,8 +37,8 @@ public function isGroupSharingAllowed(IUser $user): bool {
// "yes" => Exclude listed groups from sharing
// "allow" => Limit sharing to listed groups
return match ($excludeGroups) {
'yes' => count(array_intersect($userGroupNames, $excludeGroupList)) === 0,
'allow' => count(array_intersect($userGroupNames, $excludeGroupList)) > 0,
'yes' => count(array_intersect($userGroupIds, $excludeGroupList)) === 0,
'allow' => count(array_intersect($userGroupIds, $excludeGroupList)) > 0,
default => true,
};
}
Expand Down
13 changes: 3 additions & 10 deletions tests/unit/Service/GroupSharingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Contacts\Service\GroupSharingService;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\Share\IManager as IShareManager;
Expand Down Expand Up @@ -78,21 +77,15 @@ public function testIsGroupSharingAllowed(
string $excludeGroups,
): void {
$user = $this->createMock(IUser::class);
$group1 = $this->createMock(IGroup::class);
$group1->method('getGID')
->willReturn('group1');
$group2 = $this->createMock(IGroup::class);
$group2->method('getGID')
->willReturn('group2');

$this->shareManager->expects(self::once())
->method('allowGroupSharing')
->willReturn($allowGroupSharing);
if ($allowGroupSharing) {
$this->groupManager->expects(self::once())
->method('getUserGroups')
->method('getUserGroupIds')
->with($user)
->willReturn([$group1, $group2]);
->willReturn(['group1', 'group2']);
$this->config->expects(self::exactly(2))
->method('getAppValue')
->willReturnMap([
Expand All @@ -101,7 +94,7 @@ public function testIsGroupSharingAllowed(
]);
} else {
$this->groupManager->expects(self::never())
->method('getUserGroups');
->method('getUserGroupIds');
$this->config->expects(self::never())
->method('getAppValue');
}
Expand Down
Loading