Foros de discusión
Checking user role in velocity template
Adam Causey, modificado hace 16 años.
Checking user role in velocity template
Junior Member Mensajes: 70 Fecha de incorporación: 13/06/07 Mensajes recientes
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, modificado hace 16 años.
RE: Checking user role in velocity template
Liferay Legend Mensajes: 2871 Fecha de incorporación: 31/08/06 Mensajes recientes
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(..)
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, modificado hace 13 años.
RE: Checking user role in velocity template
New Member Mensajes: 21 Fecha de incorporación: 10/06/10 Mensajes recientes
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.
#set ($isAdmin = false)
#if ( $is_signed_in )
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id ))
#foreach( $usrRole in $usrRoles )
#if ( $usrRole.getName() == "Administrator" )
#set ($isAdmin = true)
#end
#end
cacaca cacaca, modificado hace 10 años.
RE: Checking user role in velocity template
New Member Mensajes: 14 Fecha de incorporación: 12/04/13 Mensajes recientesPatrick 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.#set ($isAdmin = false) #if ( $is_signed_in ) #set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService")) #set ($usrRoles = $rService.getUserRoles( $user_id )) #foreach( $usrRole in $usrRoles ) #if ( $usrRole.getName() == "Administrator" ) #set ($isAdmin = true) #end #end
Fernando Fernandez, modificado hace 9 años.
RE: Checking user role in velocity template
Expert Mensajes: 396 Fecha de incorporación: 22/08/07 Mensajes recientes
BTW, if somebody wants to check Site Roles also, you have to add something like:
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.UserGroupRoleLocalService"))
#set ($usrRoles = $rService.getUserGroupRoles( $user.getUserId() ) )
#foreach( $usrRole in $usrRoles )
#if($usrRole.getRole().getName() == "SiteRoleOne" || $usrRole.getRole().getName() == "SiteRoleTwo")
#set ($isAdmin = true)
#end
#set ($userNameAndRoles = $userNameAndRoles+" "+$usrRole.getRole().getName())
#end
Achmed Tyrannus Albab, modificado hace 8 años.
RE: Checking user role in velocity template
Regular Member Mensajes: 158 Fecha de incorporación: 5/03/10 Mensajes recientes
In case anyone was looking for a way to do it in FreeMarker, this is how i did it.
If anyone else could simplify and make it better, please do. Thanks.
If anyone else could simplify and make it better, please do. Thanks.
<#assign usrRoles = user.getRoles()>
<#list usrRoles as usrRole>
<#if usrRole.getName() == "Administrator">
//Roll some .. dough
<!--#if-->
<!--#list-->
Onochie Ojekwe, modificado hace 7 años.
RE: Checking user role in velocity template
New Member Mensajes: 17 Fecha de incorporación: 8/04/11 Mensajes recientes
Cleaner than VM, Nice! Thanks
Avinash Kashid, modificado hace 5 años.
RE: Checking user role in velocity template
New Member Mensajes: 5 Fecha de incorporación: 22/09/14 Mensajes recientes
Thanks. It help me.
Jairo Luna, modificado hace 13 años.
RE: Checking user role in velocity template
Junior Member Mensajes: 57 Fecha de incorporación: 21/07/10 Mensajes recientes
May be you can use:
$permissionChecker.isCompanyAdmin($company_id)
Ankit _, modificado hace 11 años.
RE: Checking user role in velocity template
Junior Member Mensajes: 46 Fecha de incorporación: 18/10/12 Mensajes recientes
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
and this also
but both way i can't get my dockbar for that admin user, i can get dockbar for test user only..
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
#if ( $is_signed_in )
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id ))
#foreach( $usrRole in $usrRoles )
#if ( $usrRole.getName() == "Administrator" )
#dockbar()
#end
#end
#end
and this also
$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, modificado hace 11 años.
RE: Checking user role in velocity template
Liferay Legend Mensajes: 1399 Fecha de incorporación: 17/09/10 Mensajes recientes
Make sure you uncheck the 'cacheable' option when editing the template.
Ankit _, modificado hace 11 años.
RE: Checking user role in velocity template
Junior Member Mensajes: 46 Fecha de incorporación: 18/10/12 Mensajes recientes
Hi James,
Thanks for your reply.
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
but still it getting only test user to show dockbar, not for site admin/other site owner(apply after site creation)
Thanks,
Ankit
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
#if ($permissionChecker.isOmniadmin())
#dockbar()
#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 _, modificado hace 11 años.
RE: Checking user role in velocity template
Junior Member Mensajes: 46 Fecha de incorporación: 18/10/12 Mensajes recientes
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
Thanks,
Ankit
mean while i got my solution for site admin can see dockbar throught theme by changing in portal_normal.vm as below
#if ($is_signed_in && $permissionChecker.isGroupAdmin($group_id))
#dockbar()
#end
Thanks,
Ankit
Devendra Patel, modificado hace 11 años.
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member Mensajes: 71 Fecha de incorporación: 26/09/11 Mensajes recientes
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
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, modificado hace 11 años.
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member Mensajes: 71 Fecha de incorporación: 26/09/11 Mensajes recientes
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
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, modificado hace 11 años.
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member Mensajes: 71 Fecha de incorporación: 26/09/11 Mensajes recientes
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
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, modificado hace 11 años.
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member Mensajes: 71 Fecha de incorporación: 26/09/11 Mensajes recientes
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
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, modificado hace 11 años.
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member Mensajes: 71 Fecha de incorporación: 26/09/11 Mensajes recientes
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
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