-
Notifications
You must be signed in to change notification settings - Fork 202
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
Add access permissions for showing decisions #51
Comments
IMO the good solution would be to check the role when creating the menu instead of adding such a dependency in the MenuItem object: <?php
$menu = new MenuItem('Courses');
if ($securityContext->isGranted('ROLE_CREATE_COURSE') {
$menu->addChild('Create new', $router->generate('create_course'));
}
if ($securityContext->isGranted('ROLE_EDIT_OWN_COURSE') {
$menu->addChild('Edit own', $router->generate('edit_own_courses'));
}
$mainMenu->addChild($menu); Such a way to do gives far more flexibility about the checks you can perform. |
Third solution: create a MenuItem subclass that handles this special case: You could add a condition on url generation based on This logic could be put in a Is this a good idea? |
docteurklein, yes, |
the same default renderer can be used. If you don't provide a url, then only the label will be displayed, without link. |
I wrote MillwrightMenuBundle which extends base functionality of KnpMenuBundle and adds configuration, route, translation and security context support.
Configuration example and options descriptions in Resources/doc/index.md |
Given the new architecture of the bundle, the cleanest way is probably to do some checks in the builder of the menu using the security context (injected as a dependency when using a service, or retrieved from the container when using the alias provider). |
Confirmed passing in the security context via the service is a nicer way to doing things.
Then in your MenuBuilder
|
Updated to use the renamed RoutingBundle
Goal
Possible solution
Add dependency to SecurityContext
Modify function signatures to fit the following possible usage:
$menu = new MenuItem('Courses');
$menu->addChild('Create new', $router->generate('create_course'), 'ROLE_CREATE_COURSE');
$menu->addChild('Edit own', $router->generate('edit_own_courses'), 'ROLE_EDIT_OWN_COURSES');
$mainMenu->addChild($menu);
The text was updated successfully, but these errors were encountered: