Foren
Limit navigation items based on roles/groups
Andy Harb, geändert vor 14 Jahren.
Limit navigation items based on roles/groups
Junior Member Beiträge: 66 Beitrittsdatum: 22.10.09 Neueste Beiträge
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, geändert vor 14 Jahren.
RE: Limit navigation items based on roles/groups
Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
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, geändert vor 14 Jahren.
RE: Limit navigation items based on roles/groups
Junior Member Beiträge: 66 Beitrittsdatum: 22.10.09 Neueste Beiträge
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, geändert vor 11 Jahren.
RE: Limit navigation items based on roles/groups
New Member Beiträge: 14 Beitrittsdatum: 10.04.12 Neueste Beiträge
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, geändert vor 11 Jahren.
RE: Limit navigation items based on roles/groups
Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
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