Fórum
Limit navigation items based on roles/groups
Andy Harb, modificado 14 Anos atrás.
Limit navigation items based on roles/groups
Junior Member Postagens: 66 Data de Entrada: 22/10/09 Postagens Recentes
I have developed my own navigation menu which works great. It displays exactly as I would expect and hides the navigation items when the "Hidden" box is checked on the page settings. However, what I would like to implement next is limiting what the users can see based on their roles.
Over simplified version of what I'm doing.
This will display all the top level navigation items in the community. However, lets say I have a top level navigation item called "Members" that I want only users who are permission to view it to see. Is there a way to return back only the children nav items or layout that the current user is permission to view? So in the example given if I wasn't logged in i wouldn't see the "Members" item listed.
Over simplified version of what I'm doing.
#foreach ($nav_item in $nav_items)
<li>$nav_item.getName()</li>
#end
This will display all the top level navigation items in the community. However, lets say I have a top level navigation item called "Members" that I want only users who are permission to view it to see. Is there a way to return back only the children nav items or layout that the current user is permission to view? So in the example given if I wasn't logged in i wouldn't see the "Members" item listed.
Oliver Bayer, modificado 14 Anos atrás.
RE: Limit navigation items based on roles/groups
Liferay Master Postagens: 894 Data de Entrada: 18/02/09 Postagens Recentes
Hi Andy,
maybe you can use $permissionChecker.hasPermission(...) inside the foreach loop to check for view rights. Use AktionKeys.<right> e.g. ActionKeys.VIEW.
Oli
maybe you can use $permissionChecker.hasPermission(...) inside the foreach loop to check for view rights. Use AktionKeys.<right> e.g. ActionKeys.VIEW.
Oli
Andy Harb, modificado 14 Anos atrás.
RE: Limit navigation items based on roles/groups
Junior Member Postagens: 66 Data de Entrada: 22/10/09 Postagens Recentes
Thanks Oli,
So I played around with it more and found out that the $navItems variable available in the theme returns what you would expect in terms of permissions & view controls.
The problem I was having was in the Layout Management section when i was using the $layout variable. The $layout.getChildren() will return all the navigation items regardless of permissions. Where as the $navItems.getChildren() will return only children that are visible to the current user.
Does anyone know if there is a way to grab the current Navigation Item based on the page you are on? This way i can build out the sub-navigation based off it.
Edit:
Solution
So I played around with it more and found out that the $navItems variable available in the theme returns what you would expect in terms of permissions & view controls.
The problem I was having was in the Layout Management section when i was using the $layout variable. The $layout.getChildren() will return all the navigation items regardless of permissions. Where as the $navItems.getChildren() will return only children that are visible to the current user.
Does anyone know if there is a way to grab the current Navigation Item based on the page you are on? This way i can build out the sub-navigation based off it.
Edit:
Solution
$layout.getChildren($permissionChecker)
Pilar Hidalgo, modificado 11 Anos atrás.
RE: Limit navigation items based on roles/groups
New Member Postagens: 14 Data de Entrada: 10/04/12 Postagens Recentes
Hi,
I have the same problem.. where goes the code of your solution? thanks!
I have the same problem.. where goes the code of your solution? thanks!
Oliver Bayer, modificado 11 Anos atrás.
RE: Limit navigation items based on roles/groups
Liferay Master Postagens: 894 Data de Entrada: 18/02/09 Postagens Recentes
Hi Pilar,
the mentioned code snippet should be put in your custom theme e.g. into the navigation.vm.
HTH Oli
the mentioned code snippet should be put in your custom theme e.g. into the navigation.vm.
HTH Oli