Skip to content

Commit

Permalink
Fixed UsersWithPermissionInfoMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 9, 2024
1 parent 738590b commit fc53371
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/lib/Permission/Mapper/UsersWithPermissionInfoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Ibexa\Contracts\AdminUi\Values\PermissionCheckContext;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
use Ibexa\Contracts\Core\Repository\Values\User\User;
Expand All @@ -30,14 +31,18 @@ final class UsersWithPermissionInfoMapper
{
private PermissionResolver $permissionResolver;

private Repository $repository;

private UserService $userService;

public function __construct(
UserService $userService,
PermissionResolver $permissionResolver
PermissionResolver $permissionResolver,
Repository $repository,
UserService $userService
) {
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
$this->repository = $repository;
$this->userService = $userService;
}

/**
Expand All @@ -55,11 +60,11 @@ public function mapSearchResults(
): array {
$currentUserReference = $this->permissionResolver->getCurrentUserReference();

$results = $this->groupByPermissions($searchResult, $permissionContext, $module, $function);

$this->permissionResolver->setCurrentUserReference($currentUserReference);

return $results;
try {
return $this->groupByPermissions($searchResult, $permissionContext, $module, $function);
} finally {
$this->permissionResolver->setCurrentUserReference($currentUserReference);
}
}

/**
Expand All @@ -83,8 +88,7 @@ private function groupByPermissions(
foreach ($searchResult as $result) {
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $userContentInfo */
$userContentInfo = $result->valueObject;
$user = $this->userService->loadUser($userContentInfo->getId());

$user = $this->loadUser($userContentInfo->getId());
$userReference = new UserReference($user->getUserId());
$this->permissionResolver->setCurrentUserReference($userReference);

Expand All @@ -102,6 +106,16 @@ private function groupByPermissions(
return $results;
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
private function loadUser(int $userId): User
{
return $this->repository->sudo(
fn (): User => $this->userService->loadUser($userId)
);
}

/**
* @phpstan-return TUserData
*/
Expand Down

0 comments on commit fc53371

Please sign in to comment.