Skip to content

Commit 832bf49

Browse files
committed
Fix scope for Route requirements and security definitions
1 parent b4e0a60 commit 832bf49

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Entity/Core/Route.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
use Symfony\Component\Serializer\Annotation\Groups;
3434
use Symfony\Component\Validator\Constraints as Assert;
3535

36-
const REQUIREMENTS = ['id' => '(.+)'];
37-
const SECURITY = "is_granted('read_route', object)";
38-
3936
/**
4037
* Although a user will be able to get the routes and the tree of data down to getting the ID for a component
4138
* fetching a component will be restricted based on the route it is within.
@@ -63,20 +60,23 @@
6360
#[ApiFilter(OrSearchFilter::class, properties: ['path' => 'ipartial'])]
6461
#[Post]
6562
#[GetCollection(order: ['createdAt' => 'DESC'])]
66-
#[Delete(requirements: REQUIREMENTS, security: SECURITY)]
67-
#[Put(requirements: REQUIREMENTS, security: SECURITY)]
68-
#[Patch(requirements: REQUIREMENTS, security: SECURITY)]
69-
#[Get(requirements: ['id' => "(?!.+\/redirects$).+"], security: SECURITY)]
63+
#[Delete(requirements: Route::API_REQUIREMENTS, security: Route::API_SECURITY)]
64+
#[Put(requirements: Route::API_REQUIREMENTS, security: Route::API_SECURITY)]
65+
#[Patch(requirements: Route::API_REQUIREMENTS, security: Route::API_SECURITY)]
66+
#[Get(requirements: ['id' => "(?!.+\/redirects$).+"], security: Route::API_SECURITY)]
7067
// Custom endpoints
7168
#[Post(uriTemplate: '/routes/generate{._format}', validationContext: ['groups' => ['Route:generate:write']])]
72-
#[Get(uriTemplate: '/routes/{id}/redirects{._format}', defaults: ['_api_item_operation_name' => 'route_redirects'], requirements: REQUIREMENTS, order: ['createdAt' => 'DESC'], normalizationContext: ['groups' => ['Route:redirect:read']], security: SECURITY)]
73-
#[Get(uriTemplate: '/routes_manifest/{id}{._format}', defaults: ['_api_item_operation_name' => 'route_resources'], requirements: REQUIREMENTS, normalizationContext: ['groups' => ['Route:manifest:read']], security: SECURITY)]
69+
#[Get(uriTemplate: '/routes/{id}/redirects{._format}', defaults: ['_api_item_operation_name' => 'route_redirects'], requirements: Route::API_REQUIREMENTS, order: ['createdAt' => 'DESC'], normalizationContext: ['groups' => ['Route:redirect:read']], security: Route::API_SECURITY)]
70+
#[Get(uriTemplate: '/routes_manifest/{id}{._format}', defaults: ['_api_item_operation_name' => 'route_resources'], requirements: Route::API_REQUIREMENTS, normalizationContext: ['groups' => ['Route:manifest:read']], security: Route::API_SECURITY)]
7471
#[Silverback\Timestamped]
7572
class Route
7673
{
7774
use IdTrait;
7875
use TimestampedTrait;
7976

77+
private const array API_REQUIREMENTS = ['id' => '(.+)'];
78+
private const string API_SECURITY = "is_granted('read_route', object)";
79+
8080
#[Assert\NotBlank]
8181
#[Groups(['Route:redirect:read'])]
8282
private string $path = '';

0 commit comments

Comments
 (0)