Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Andy Harb
Limit navigation items based on roles/groups
30 de marzo de 2010 15:28
Respuesta

Andy Harb

Ranking: Junior Member

Mensajes: 66

Fecha de incorporación: 22 de octubre de 2009

Mensajes recientes

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.
1#foreach ($nav_item in $nav_items)
2    <li>$nav_item.getName()</li>
3  #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
RE: Limit navigation items based on roles/groups
31 de marzo de 2010 2:16
Respuesta

Oliver Bayer

Ranking: Liferay Master

Mensajes: 883

Fecha de incorporación: 18 de febrero de 2009

Mensajes recientes

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
Andy Harb
RE: Limit navigation items based on roles/groups
1 de abril de 2010 7:58
Respuesta

Andy Harb

Ranking: Junior Member

Mensajes: 66

Fecha de incorporación: 22 de octubre de 2009

Mensajes recientes

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
1$layout.getChildren($permissionChecker)
Pilar Hidalgo
RE: Limit navigation items based on roles/groups
25 de septiembre de 2012 1:20
Respuesta

Pilar Hidalgo

Ranking: New Member

Mensajes: 14

Fecha de incorporación: 10 de abril de 2012

Mensajes recientes

Hi,

I have the same problem.. where goes the code of your solution? thanks!
Oliver Bayer
RE: Limit navigation items based on roles/groups
11 de octubre de 2012 1:02
Respuesta

Oliver Bayer

Ranking: Liferay Master

Mensajes: 883

Fecha de incorporación: 18 de febrero de 2009

Mensajes recientes

Hi Pilar,

the mentioned code snippet should be put in your custom theme e.g. into the navigation.vm.

HTH Oli