Skip to content

#[ApiProperty(security)] doesn't work with nested object #8087

@w-aurelien

Description

@w-aurelien

API Platform version(s) affected: 3.1.18

Description

I'm trying to use the ApiProperty attribute to secure a field present in an nested object of the object I'm querying.

But the property seems to have no effect when I use it on a field of the parent object, it works perfectly!

How to reproduce

Project.php

    #[ORM\JoinColumn(nullable: false)]
    #[Groups(['read:Project'])]
    private ?User $owner = null;

    #[ORM\Column]
    #[Groups(['read:Project'])]
    #[ApiProperty(security: 'is_granted("ROLE_ADMIN")')]
    private ?int $size = null;

    #[ORM\Column]
    #[Groups(['read:Project'])]
    private ?string $label = null;

User.php (abstract class)

    #[Groups(['read:Project'])]
    #[ApiProperty(security: 'is_granted("ROLE_ADMIN")')]
    private ?string $email = null;

    #[ORM\Column(length: 180, unique: true)]
    #[Groups(['read:Project'])]
    private ?string $name = null;

Response

label: 'Test',
owner: {
    email: 'test@test.com',
    name: 'Test Test'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions