Skip to content

Commit

Permalink
Fixed LimitationResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Sep 1, 2023
1 parent 48b235a commit 027880f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Ibexa\Bundle\AdminUi\Controller\Permission;

use Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface;
use Ibexa\AdminUi\Permission\LimitationResolverInterface;
use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\LocationService;
Expand All @@ -21,31 +21,31 @@ final class LanguageLimitationController extends Controller

private LocationService $locationService;

private PermissionLimitationResolverInterface $permissionLimitationResolver;
private LimitationResolverInterface $limitationResolver;

public function __construct(
ContentService $contentService,
LocationService $locationService,
PermissionLimitationResolverInterface $permissionLimitationResolver
LimitationResolverInterface $limitationResolver
) {
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->permissionLimitationResolver = $permissionLimitationResolver;
$this->limitationResolver = $limitationResolver;
}

public function loadLanguageLimitationsForContentAction(
int $contentId,
?int $versionId = null,
?int $versionNo = null,
?int $locationId = null
): Response {
$versionInfo = $this->contentService->loadVersionInfoById($contentId, $versionId);
$versionInfo = $this->contentService->loadVersionInfoById($contentId, $versionNo);

if (null === $locationId) {
$locationId = $versionInfo->getContentInfo()->getMainLocationId();
}

return new JsonResponse(
$this->permissionLimitationResolver->getLanguageLimitations(
$this->limitationResolver->getLanguageLimitations(
$versionInfo,
$this->locationService->loadLocation($locationId)
)
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,11 @@ ibexa.asset.upload_image:
#

ibexa.permission.limitation.language:
path: permission/limitation/language/{contentId}/{versionId}/{locationId}
path: permission/limitation/language/{contentId}/{versionNo}/{locationId}
options:
expose: true
defaults:
versionId: null
versionNo: null
locationId: null
_controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentAction'
methods: [GET]
6 changes: 3 additions & 3 deletions src/bundle/Resources/config/services/permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:

Ibexa\AdminUi\Permission\LookupLimitationsTransformer: ~

Ibexa\AdminUi\Permission\PermissionLimitationResolver: ~
Ibexa\AdminUi\Permission\LimitationResolver: ~

Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface:
alias: Ibexa\AdminUi\Permission\PermissionLimitationResolver
Ibexa\AdminUi\Permission\LimitationResolverInterface:
alias: Ibexa\AdminUi\Permission\LimitationResolver
20 changes: 10 additions & 10 deletions src/contracts/Permission/PermissionCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ public function getRestrictions(array $hasAccess, string $class): array;
public function canCreateInLocation(Location $location, $hasAccess): bool;

/**
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentCreateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface::getContentCreateLimitations } instead.
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentCreateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\LimitationResolverInterface::getContentCreateLimitations } instead.
*/
public function getContentCreateLimitations(Location $parentLocation): LookupLimitationResult;

/**
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentUpdateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface::getContentUpdateLimitations } instead.
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentUpdateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\LimitationResolverInterface::getContentUpdateLimitations } instead.
*/
public function getContentUpdateLimitations(Location $parentLocation): LookupLimitationResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @internal
*/
final class PermissionLimitationResolver implements PermissionLimitationResolverInterface
final class LimitationResolver implements LimitationResolverInterface
{
private ContentService $contentService;

Expand Down Expand Up @@ -112,7 +112,7 @@ static function (Language $language) use ($limitationLanguageCodes): array {
return [
'languageCode' => $language->getLanguageCode(),
'name' => $language->getName(),
'hasAccess' => in_array($language->getLanguageCode(), $limitationLanguageCodes, true),
'hasAccess' => empty($limitationLanguageCodes) || in_array($language->getLanguageCode(), $limitationLanguageCodes, true),
];
},
$languages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @internal
*/
interface PermissionLimitationResolverInterface
interface LimitationResolverInterface
{
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Permission/PermissionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class PermissionChecker implements PermissionCheckerInterface
/** @var \Ibexa\Contracts\Core\Repository\UserService */
private $userService;

private PermissionLimitationResolverInterface $permissionLimitationResolver;
private LimitationResolverInterface $limitationResolver;

public function __construct(
PermissionResolver $permissionResolver,
PermissionLimitationResolverInterface $permissionLimitationResolver,
LimitationResolverInterface $limitationResolver,
UserService $userService
) {
$this->permissionResolver = $permissionResolver;
$this->permissionLimitationResolver = $permissionLimitationResolver;
$this->limitationResolver = $limitationResolver;
$this->userService = $userService;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public function getContentCreateLimitations(Location $parentLocation): LookupLim
sprintf('The %s() method is deprecated, will be removed in 5.0.', __METHOD__)
);

return $this->permissionLimitationResolver->getContentCreateLimitations($parentLocation);
return $this->limitationResolver->getContentCreateLimitations($parentLocation);
}

public function getContentUpdateLimitations(Location $location): LookupLimitationResult
Expand All @@ -176,7 +176,7 @@ public function getContentUpdateLimitations(Location $location): LookupLimitatio
sprintf('The %s() method is deprecated, will be removed in 5.0.', __METHOD__)
);

return $this->permissionLimitationResolver->getContentUpdateLimitations($location);
return $this->limitationResolver->getContentUpdateLimitations($location);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/Permission/PermissionCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Ibexa\Tests\AdminUi\Permission;

use Ibexa\AdminUi\Permission\LimitationResolverInterface;
use Ibexa\AdminUi\Permission\PermissionChecker;
use Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content;
Expand All @@ -30,8 +30,8 @@ class PermissionCheckerTest extends TestCase
/** @var \Ibexa\Contracts\Core\Repository\UserService&\PHPUnit\Framework\MockObject\MockObject */
private $userService;

/** @var \Ibexa\AdminUi\Permission\PermissionLimitationResolverInterface&\PHPUnit\Framework\MockObject\MockObject */
private PermissionLimitationResolverInterface $permissionLimitationResolver;
/** @var \Ibexa\AdminUi\Permission\LimitationResolverInterface&\PHPUnit\Framework\MockObject\MockObject */
private LimitationResolverInterface $permissionLimitationResolver;

/** @var \Ibexa\AdminUi\Permission\PermissionChecker */
private $permissionChecker;
Expand All @@ -43,7 +43,7 @@ public function setUp(): void
->method('getCurrentUserReference')
->willReturn($this->generateUser(self::USER_ID));

$this->permissionLimitationResolver = $this->createMock(PermissionLimitationResolverInterface::class);
$this->permissionLimitationResolver = $this->createMock(LimitationResolverInterface::class);
$this->userService = $this->createMock(UserService::class);

$this->permissionChecker = new PermissionChecker(
Expand Down

0 comments on commit 027880f

Please sign in to comment.