Skip to content

Commit

Permalink
Merged branch '2.3' of ezsystems/ezplatform-admin-ui into 4.3 (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz authored Feb 14, 2023
2 parents 3295123 + 378e68d commit 58b070d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
21 changes: 14 additions & 7 deletions src/lib/Menu/ContentRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,23 @@ private function canCopy(bool $hasCreatePermission): bool

private function canCopySubtree(Location $location, bool $hasCreatePermission): bool
{
$copyLimit = $this->configResolver->getParameter(
'subtree_operations.copy_subtree.limit'
);
if (!$hasCreatePermission) {
return false;
}

$canCopySubtree = (new IsWithinCopySubtreeLimit(
$copyLimit,
$isWithinCopySubtreeLimit = new IsWithinCopySubtreeLimit(
$this->getCopySubtreeLimit(),
$this->locationService
))->and((new IsRoot())->not())->isSatisfiedBy($location);
);

return $canCopySubtree && $hasCreatePermission;
return (new IsRoot())->not()->and($isWithinCopySubtreeLimit)->isSatisfiedBy($location);
}

private function getCopySubtreeLimit(): int
{
return $this->configResolver->getParameter(
'subtree_operations.copy_subtree.limit'
);
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/lib/Specification/Location/IsWithinCopySubtreeLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

use Ibexa\AdminUi\Specification\AbstractSpecification;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;

/**
* @internal
Expand All @@ -34,24 +33,23 @@ public function __construct(

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $item
*
* @return bool
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
*/
public function isSatisfiedBy($item): bool
{
if ($this->copyLimit === -1) {
return true;
}

if ($this->copyLimit === 0) {
if ($this->copyLimit === 0 || !$this->isContainer($item)) {
return false;
}

$filter = new Filter(new Criterion\Subtree($item->pathString));
return $this->copyLimit >= $this->locationService->getSubtreeSize($item);
}

return $this->copyLimit >= $this->locationService->count($filter);
private function isContainer(Location $location): bool
{
return $location->getContentInfo()->getContentType()->isContainer();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
use Ibexa\AdminUi\Validator\Constraints\LocationIsWithinCopySubtreeLimit;
use Ibexa\AdminUi\Validator\Constraints\LocationIsWithinCopySubtreeLimitValidator;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
Expand Down Expand Up @@ -62,6 +65,8 @@ public function testValid(): void
->expects($this->never())
->method('addViolation');

$this->mockLocationContentContentTypeIsContainer($this->location);

$this->validator->validate($this->location, new LocationIsWithinCopySubtreeLimit());
}

Expand All @@ -87,6 +92,16 @@ public function testInvalid(): void

$this->validator->validate($this->location, new LocationIsWithinCopySubtreeLimit());
}

private function mockLocationContentContentTypeIsContainer(MockObject $location): void
{
$contentType = $this->createMock(ContentType::class);
$contentType->method('isContainer')->willReturn(true);
$contentInfo = $this->createMock(ContentInfo::class);
$contentInfo->method('getContentType')->willReturn($contentType);

$location->method('getContentInfo')->willReturn($contentInfo);
}
}

class_alias(LocationIsWithinCopySubtreeLimitValidatorTest::class, 'EzSystems\EzPlatformAdminUi\Tests\Validator\Constraint\LocationIsWithinCopySubtreeLimitValidatorTest');

0 comments on commit 58b070d

Please sign in to comment.