Skip to content

Unable to set a subject of the IsGranted attribute of mapped DTO #58508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
infinitum11 opened this issue Oct 9, 2024 · 3 comments
Open

Unable to set a subject of the IsGranted attribute of mapped DTO #58508

infinitum11 opened this issue Oct 9, 2024 · 3 comments

Comments

@infinitum11
Copy link

Symfony version(s) affected

7.1.5

Description

You may want to map request data to a DTO and then pass that DTO object to a VoterInterface. However, this is impossible because the IsGrantedAttributeListener is called before the RequestPayloadValueResolver event subscriber.
The resolved DTO object is expected by the Voter, but the MapQueryString instance is passed.

How to reproduce

  1. Create any DTO class you want to map from a request data.
  2. Create a Voter that accepts the DTO class.
  3. Add the IsGranted attribute to a controller and set the subject to the mapped variable like so #[IsGranted('post_create', 'post' )]
  4. The Voter expects the PostDto instance as a subject, but gets the MapQueryString instance.
#[IsGranted('post_create', 'post')]
#[Route('/post, name: "app_post")]
public function post(
    #[MapQueryString] PostDto $post,
): Response
{
  return new Response('OK');
}

Possible Solution

Explicitly set higher priority for the RequestPayloadValueResolver. It should be triggered right before the IsGrantedAttributeListener.

class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::CONTROLLER_ARGUMENTS => ['onKernelControllerArguments', 21],
        ];
    }
}

Additional Context

No response

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get a reply or should I close this?

@stof
Copy link
Member

stof commented Apr 24, 2025

This was implemented this way in #50125 to solve #50120

This issue is basically asking for a revert of this.

@carsonbot carsonbot removed the Stalled label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants