Closed
Description
API Platform version(s) affected: 4.1
Description
- The
identifiers
feature ofLink
works well for linking subresources on properties other than the main identifier. - The
security
feature ofLink
works well for adding access control based on theuriVariable
objects - thanks for this recent addition. - Unfortunately the two seem incompatible, because
security
always uses the main identifier rather than usingidentifiers
to query the object.
How to reproduce
# security.yaml
api_platform:
enable_link_security: true
// Employee.php
#[ApiResource(
uriTemplate: '/companies/{slug}/employees',
uriVariables: [
'slug' => new Link(
identifiers: ['slug'],
fromClass: Company::class,
toProperty: 'company',
security: 'company == user.company',
),
],
operations: [
new GetCollection(),
],
)]
GET /companies/acme/employees
gives error:
500: Could not convert database value "acme" to Doctrine Type uuid
Can be worked around by removing security
, or by linking on id
instead of slug
. But the former means a more complicated security setup, and the latter inconvenient for API consumers. So it would be ideal if these features could complement each other.