Skip to content
Open
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
19 changes: 2 additions & 17 deletions lib/Helper/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OCA\Tables\Helper;

use OCA\Tables\Errors\InternalError;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -48,30 +47,16 @@ private function getUser(string $userId): IUser {
throw new InternalError('User not found for ' . $userId);
}

/**
* @param string $userId
* @return IGroup[]
* @throws InternalError
*/
public function getGroupsForUser(string $userId): array {
$user = $this->getUser($userId);
return $this->groupManager->getUserGroups($user);
}

/**
* @param string $userId
* @return array|null
*/
public function getGroupIdsForUser(string $userId): ?array {
try {
$userGroups = $this->getGroupsForUser($userId);
$user = $this->getUser($userId);
return $this->groupManager->getUserGroupIds($user);
} catch (InternalError $e) {
return null;
}

$groupArray = array_map(function (IGroup $group) {
return $group->getGID();
}, $userGroups);
return $groupArray;
}
}
6 changes: 3 additions & 3 deletions lib/Service/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ public function canReadShare(Share $share, ?string $userId = null): bool {

if ($share->getReceiverType() === 'group') {
try {
$userGroups = $this->userHelper->getGroupsForUser($userId);
foreach ($userGroups as $userGroup) {
if ($userGroup->getGID() === $share->getReceiver()) {
$userGroups = $this->userHelper->getGroupIdsForUser($userId);
foreach ($userGroups as $userGroupId) {
if ($userGroupId === $share->getReceiver()) {
return true;
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use OCP\AppFramework\Db\TTransactional;
use OCP\DB\Exception;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IUserManager;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -234,8 +233,7 @@ private function findElementsSharedWithMe(string $elementType = 'table', ?string
try {
$shares['user'] = $this->mapper->findAllSharesFor($elementType, [$userId], $userId);

$userGroups = $this->userHelper->getGroupsForUser($userId);
$userGroupIds = array_map(static fn (IGroup $group) => $group->getGid(), $userGroups);
$userGroupIds = $this->userHelper->getGroupIdsForUser($userId);
$shares['groups'] = $this->mapper->findAllSharesFor($elementType, $userGroupIds, $userId, ShareReceiverType::GROUP);

$userCircles = $this->circleHelper->getUserCircles($userId);
Expand Down
Loading