Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Adam C
Checking user role in velocity template
30 de Janeiro de 2008 11:50
Resposta

Adam C

Ranking: Junior Member

Mensagens: 70

Data de entrada: 13 de Junho de 2007

Mensagens recentes

How can I determine if the user is in a certain role using Velocity? More specifically, I'd like to check if they have the Administrator role.
Jorge Ferrer
RE: Checking user role in velocity template
19 de Fevereiro de 2008 09:00
Resposta

Jorge Ferrer

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 2757

Data de entrada: 31 de Agosto de 2006

Mensagens recentes

Hi A C,

The following wiki article explains how to access Liferay's services from a velocity template in a theme:
http://wiki.liferay.com/index.php/Access_to_Liferay_services_in_Velocity


You can then use UserService.hasUserRole(..)
Patrick Stackpoole
RE: Checking user role in velocity template
4 de Novembro de 2010 07:07
Resposta

Patrick Stackpoole

Ranking: New Member

Mensagens: 21

Data de entrada: 10 de Junho de 2010

Mensagens recentes

Although I'm replying to a post that's over 2 years old, I had the same question and wanted to post a solution I found that worked.

 1
 2
 3#set ($isAdmin = false)
 4
 5#if ( $is_signed_in )
 6
 7    #set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
 8    #set ($usrRoles = $rService.getUserRoles( $user_id ))
 9    #foreach( $usrRole in $usrRoles )
10            #if ( $usrRole.getName() == "Administrator" )
11            #set ($isAdmin = true)
12            #end
13#end
Jairo Luna
RE: Checking user role in velocity template
8 de Novembro de 2010 16:46
Resposta

Jairo Luna

Ranking: Junior Member

Mensagens: 57

Data de entrada: 21 de Julho de 2010

Mensagens recentes

May be you can use:

1
2$permissionChecker.isCompanyAdmin($company_id)
Ankit _
RE: Checking user role in velocity template
14 de Fevereiro de 2013 06:34
Resposta

Ankit _

Ranking: Junior Member

Mensagens: 46

Data de entrada: 18 de Outubro de 2012

Mensagens recentes

Hi, this is old post, but i am still not getting the result that i want.

I am using liferay 6.2.0 M2 , and i created site and assign the owner and admin rights to that user. I just want if user is admin i want to show dockbar.
and i tried
 1
 2#if ( $is_signed_in )
 3    #set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
 4    #set ($usrRoles = $rService.getUserRoles( $user_id ))
 5    #foreach( $usrRole in $usrRoles )
 6            #if ( $usrRole.getName() == "Administrator" )
 7                #dockbar()
 8            #end
 9    #end
10#end

and this also
1
2$permissionChecker.isCompanyAdmin($company_id)

but both way i can't get my dockbar for that admin user, i can get dockbar for test user only..
James Falkner
RE: Checking user role in velocity template
14 de Fevereiro de 2013 08:23
Resposta

James Falkner

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 1222

Data de entrada: 17 de Setembro de 2010

Mensagens recentes

Make sure you uncheck the 'cacheable' option when editing the template.
Ankit _
RE: Checking user role in velocity template
14 de Fevereiro de 2013 21:32
Resposta

Ankit _

Ranking: Junior Member

Mensagens: 46

Data de entrada: 18 de Outubro de 2012

Mensagens recentes

Hi James,
Thanks for your reply.
James Falkner:
Make sure you uncheck the 'cacheable' option when editing the template.

but I am trying to do in theme, so i am writing it in navigation.vm file. I cleared all the server cache, but i can't figure it out.


EDIT :
I tried this one also
1#if ($permissionChecker.isOmniadmin())
2#dockbar()
3#end

but still it getting only test user to show dockbar, not for site admin/other site owner(apply after site creation)

Thanks,
Ankit
Ankit _
RE: Checking user role in velocity template
14 de Fevereiro de 2013 21:49
Resposta

Ankit _

Ranking: Junior Member

Mensagens: 46

Data de entrada: 18 de Outubro de 2012

Mensagens recentes

sorry for post my theme problem to velocity template thread,
mean while i got my solution for site admin can see dockbar throught theme by changing in portal_normal.vm as below

1#if ($is_signed_in && $permissionChecker.isGroupAdmin($group_id))
2        #dockbar()
3    #end


Thanks,
Ankit
Devendra Patel
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
28 de Fevereiro de 2013 21:30
Resposta

Devendra Patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 25 de Setembro de 2011

Mensagens recentes

Hi Ankit

Rather than using service locator for fetching you can use this code :

#foreach($role in $user.getRoles())
#if($role.getName() == "Administrator")
True
#end
#end

Regards,
Dev Patel
Devendra Patel
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
28 de Fevereiro de 2013 21:30
Resposta

Devendra Patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 25 de Setembro de 2011

Mensagens recentes

Hi Ankit

Rather than using service locator for fetching you can use this code :

#foreach($role in $user.getRoles())
#if($role.getName() == "Administrator")
True
#end
#end

Regards,
Dev Patel
Devendra Patel
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
28 de Fevereiro de 2013 21:30
Resposta

Devendra Patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 25 de Setembro de 2011

Mensagens recentes

Hi Ankit

Rather than using service locator for fetching you can use this code :

#foreach($role in $user.getRoles())
#if($role.getName() == "Administrator")
True
#end
#end

Regards,
Dev Patel
Devendra Patel
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
28 de Fevereiro de 2013 21:30
Resposta

Devendra Patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 25 de Setembro de 2011

Mensagens recentes

Hi Ankit

Rather than using service locator for fetching you can use this code :

#foreach($role in $user.getRoles())
#if($role.getName() == "Administrator")
True
#end
#end

Regards,
Dev Patel
Devendra Patel
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
28 de Fevereiro de 2013 21:30
Resposta

Devendra Patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 25 de Setembro de 2011

Mensagens recentes

Hi Ankit

Rather than using service locator for fetching you can use this code :

#foreach($role in $user.getRoles())
#if($role.getName() == "Administrator")
True
#end
#end

Regards,
Dev Patel
cacaca cacaca
RE: Checking user role in velocity template
8 de Maio de 2013 23:54
Resposta

cacaca cacaca

Ranking: New Member

Mensagens: 14

Data de entrada: 12 de Abril de 2013

Mensagens recentes

Patrick Stackpoole:
Although I'm replying to a post that's over 2 years old, I had the same question and wanted to post a solution I found that worked.

 1
 2
 3#set ($isAdmin = false)
 4
 5#if ( $is_signed_in )
 6
 7    #set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
 8    #set ($usrRoles = $rService.getUserRoles( $user_id ))
 9    #foreach( $usrRole in $usrRoles )
10            #if ( $usrRole.getName() == "Administrator" )
11            #set ($isAdmin = true)
12            #end
13#end
Fernando Fernandez
RE: Checking user role in velocity template
3 de Novembro de 2014 12:24
Resposta

Fernando Fernandez

Ranking: Junior Member

Mensagens: 27

Data de entrada: 22 de Agosto de 2007

Mensagens recentes

BTW, if somebody wants to check Site Roles also, you have to add something like:
 1
 2#set ($rService = $serviceLocator.findService("com.liferay.portal.service.UserGroupRoleLocalService"))
 3#set ($usrRoles = $rService.getUserGroupRoles( $user.getUserId() ) )
 4#foreach( $usrRole in $usrRoles )
 5    #if($usrRole.getRole().getName() == "SiteRoleOne" || $usrRole.getRole().getName() == "SiteRoleTwo")
 6        #set ($isAdmin = true)
 7    #end
 8    #set ($userNameAndRoles = $userNameAndRoles+" "+$usrRole.getRole().getName())
 9#end