|
33 | 33 | use Symfony\Component\Serializer\Annotation\Groups; |
34 | 34 | use Symfony\Component\Validator\Constraints as Assert; |
35 | 35 |
|
36 | | -const REQUIREMENTS = ['id' => '(.+)']; |
37 | | -const SECURITY = "is_granted('read_route', object)"; |
38 | | - |
39 | 36 | /** |
40 | 37 | * Although a user will be able to get the routes and the tree of data down to getting the ID for a component |
41 | 38 | * fetching a component will be restricted based on the route it is within. |
|
63 | 60 | #[ApiFilter(OrSearchFilter::class, properties: ['path' => 'ipartial'])] |
64 | 61 | #[Post] |
65 | 62 | #[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)] |
70 | 67 | // Custom endpoints |
71 | 68 | #[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)] |
74 | 71 | #[Silverback\Timestamped] |
75 | 72 | class Route |
76 | 73 | { |
77 | 74 | use IdTrait; |
78 | 75 | use TimestampedTrait; |
79 | 76 |
|
| 77 | + private const array API_REQUIREMENTS = ['id' => '(.+)']; |
| 78 | + private const string API_SECURITY = "is_granted('read_route', object)"; |
| 79 | + |
80 | 80 | #[Assert\NotBlank] |
81 | 81 | #[Groups(['Route:redirect:read'])] |
82 | 82 | private string $path = ''; |
|
0 commit comments