Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Andy Harb
Limit navigation items based on roles/groups
30 de Março de 2010 15:28
Resposta

Andy Harb

Ranking: Junior Member

Mensagens: 66

Data de entrada: 22 de Outubro de 2009

Mensagens 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.
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 Março de 2010 02:16
Resposta

Oliver Bayer

Ranking: Liferay Master

Mensagens: 883

Data de entrada: 18 de Fevereiro de 2009

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

Andy Harb

Ranking: Junior Member

Mensagens: 66

Data de entrada: 22 de Outubro de 2009

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

Pilar Hidalgo

Ranking: New Member

Mensagens: 14

Data de entrada: 10 de Abril de 2012

Mensagens recentes

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 Outubro de 2012 01:02
Resposta

Oliver Bayer

Ranking: Liferay Master

Mensagens: 883

Data de entrada: 18 de Fevereiro de 2009

Mensagens recentes

Hi Pilar,

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

HTH Oli