-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: securityPostDenormalize not working because clone is made after …
…denormalization (#5182) * fix: securityPostDenormalize not working because clone is made after denormalization * test: add non-regression tests
- Loading branch information
1 parent
62af874
commit d188135
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
tests/Fixtures/TestBundle/Entity/SecuredDummyWithPropertiesDependingOnThemselves.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Patch; | ||
use ApiPlatform\Metadata\Post; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* Secured resource with properties depending on themselves. | ||
* | ||
* @author Loïc Boursin <[email protected]> | ||
*/ | ||
#[ApiResource( | ||
operations: [ | ||
new Get(), | ||
new Patch(inputFormats: ['json' => ['application/merge-patch+json'], 'jsonapi']), | ||
new Post(security: 'is_granted("ROLE_ADMIN")'), | ||
] | ||
)] | ||
#[ORM\Entity] | ||
class SecuredDummyWithPropertiesDependingOnThemselves | ||
{ | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column] | ||
private bool $canUpdateProperty = false; | ||
|
||
/** | ||
* @var bool Special property, only writable when granted rights by another property | ||
*/ | ||
#[ApiProperty(securityPostDenormalize: 'previous_object and previous_object.getCanUpdateProperty()')] | ||
#[ORM\Column] | ||
private bool $property = false; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getCanUpdateProperty(): bool | ||
{ | ||
return $this->canUpdateProperty; | ||
} | ||
|
||
public function setCanUpdateProperty(bool $canUpdateProperty): void | ||
{ | ||
$this->canUpdateProperty = $canUpdateProperty; | ||
} | ||
|
||
public function getProperty(): bool | ||
{ | ||
return $this->property; | ||
} | ||
|
||
public function setProperty(bool $property): void | ||
{ | ||
$this->property = $property; | ||
} | ||
} |