Skip to content

Changing the Serialization Context Dynamically #1660

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

Closed
Yoann-TYT opened this issue Jan 19, 2018 · 6 comments
Closed

Changing the Serialization Context Dynamically #1660

Yoann-TYT opened this issue Jan 19, 2018 · 6 comments

Comments

@Yoann-TYT
Copy link

Yoann-TYT commented Jan 19, 2018

Hello,

I use the last version v2.1.5, and when I follow the example, it works for GET / PUT but not for POST calls.

When I POST and when normalization == false, the subject class is AppBundle\Serializer\BookContextBuilder, so it doesn't pass my condition :-/

Everyone get the same problem ?

@Yoann-TYT Yoann-TYT changed the title Using Different Serialization Groups per Operation Changing the Serialization Context Dynamically Jan 19, 2018
@Yoann-TYT
Copy link
Author

@Yoann-TYT
Copy link
Author

Nobody has the same problem ? :-/

@Nek-
Copy link
Contributor

Nek- commented Mar 27, 2018

@Yoann-TYT Please provide more information about your issue (like the code and configuration you used). Because this feature looks ok to me.

But it may be related to #1616 (comment)

@Simperfit
Copy link
Contributor

As @Nek- said, could you please provide a reproducer? So we could directly test the behaviour.

@Yoann-TYT
Copy link
Author

Thanks for your responses :)
I think it's a particular case :
To allow user to fill some fields, I need to check their rights on a property

        $subject = $request->attributes->get('data');
        if (
            isset($context['groups']) &&
            $subject instanceof Book &&
            $this->authorizationChecker->isGranted('VIEW', $subject->getAuthor())
        ) {
            $context['groups'][] = 'specific-input';
        }

And this code doesn't work for POST method :-/

@soyuka
Copy link
Member

soyuka commented Apr 7, 2019

Did you find an answer? As this issue is quite old I'm going to close it but feel free to ping me or to seek for an answer on the api-platform slack (symfony-devs.slack.com)!

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