Skip to content

Commit

Permalink
[BUGFIX] Respect cross classes when removing restrictions
Browse files Browse the repository at this point in the history
When removeByType is used to remove restrictions
from the container, it is now ensured that also
cross classes are properly respected.

Resolves: #103456
Releases: main, 12.4
Change-Id: I4841fe1cba7388358771cf01ee220afa4482349a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83539
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Mar 22, 2024
1 parent 5014c8c commit 41b9956
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -69,7 +69,20 @@ public function removeAll(): QueryRestrictionContainerInterface
*/
public function removeByType(string $restrictionType): QueryRestrictionContainerInterface
{
unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
foreach ($this->restrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->restrictions[$type]);
break;
}
}

foreach ($this->enforcedRestrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->enforcedRestrictions[$type]);
break;
}
}

return $this;
}

Expand Down
Expand Up @@ -19,6 +19,7 @@

use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\InstantiatableAbstractRestrictionContainer;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockEnforceableQueryRestriction;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockQueryRestriction;
Expand Down Expand Up @@ -56,6 +57,20 @@ public function enforceableRestrictionsWillBeRemovedWhenRemovedByType(): void
self::assertSame('', (string)$expression);
}

#[Test]
public function crossClassWillBeRemovedWhenRemovedByType(): void
{
$restriction = new class () extends HiddenRestriction {};

$subject = new InstantiatableAbstractRestrictionContainer();
$subject->add($restriction);
$subject->removeByType(HiddenRestriction::class);

$GLOBALS['TCA']['aTable']['ctrl']['enablecolumns']['disabled'] = 'hidden';
$expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
self::assertSame('', (string)$expression);
}

#[Test]
public function enforceableRestrictionsWillBeRemovedWhenRemovedByTypeAndRemovedAllIsAdditionallyCalled(): void
{
Expand Down

0 comments on commit 41b9956

Please sign in to comment.