掲示板
Checking user role in velocity template
16年前 に Adam Causey によって更新されました。
Checking user role in velocity template
Junior Member 投稿: 70 参加年月日: 07/06/13 最新の投稿
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.
16年前 に Jorge Ferrer によって更新されました。
RE: Checking user role in velocity template
Liferay Legend 投稿: 2871 参加年月日: 06/08/31 最新の投稿
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(..)
13年前 に Patrick Stackpoole によって更新されました。
RE: Checking user role in velocity template
New Member 投稿: 21 参加年月日: 10/06/10 最新の投稿
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
10年前 に cacaca cacaca によって更新されました。
RE: Checking user role in velocity template
New Member 投稿: 14 参加年月日: 13/04/12 最新の投稿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.#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
9年前 に Fernando Fernandez によって更新されました。
RE: Checking user role in velocity template
Expert 投稿: 396 参加年月日: 07/08/22 最新の投稿
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
8年前 に Achmed Tyrannus Albab によって更新されました。
RE: Checking user role in velocity template
Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
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-->
7年前 に Onochie Ojekwe によって更新されました。
RE: Checking user role in velocity template
New Member 投稿: 17 参加年月日: 11/04/08 最新の投稿
Cleaner than VM, Nice! Thanks
5年前 に Avinash Kashid によって更新されました。
RE: Checking user role in velocity template
New Member 投稿: 5 参加年月日: 14/09/22 最新の投稿
Thanks. It help me.
13年前 に Jairo Luna によって更新されました。
RE: Checking user role in velocity template
Junior Member 投稿: 57 参加年月日: 10/07/21 最新の投稿
May be you can use:
$permissionChecker.isCompanyAdmin($company_id)
11年前 に Ankit _ によって更新されました。
RE: Checking user role in velocity template
Junior Member 投稿: 46 参加年月日: 12/10/18 最新の投稿
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..
11年前 に James Falkner によって更新されました。
RE: Checking user role in velocity template
Liferay Legend 投稿: 1399 参加年月日: 10/09/17 最新の投稿
Make sure you uncheck the 'cacheable' option when editing the template.
11年前 に Ankit _ によって更新されました。
RE: Checking user role in velocity template
Junior Member 投稿: 46 参加年月日: 12/10/18 最新の投稿
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
11年前 に Ankit _ によって更新されました。
RE: Checking user role in velocity template
Junior Member 投稿: 46 参加年月日: 12/10/18 最新の投稿
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
11年前 に Devendra Patel によって更新されました。
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member 投稿: 71 参加年月日: 11/09/26 最新の投稿
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
11年前 に Devendra Patel によって更新されました。
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member 投稿: 71 参加年月日: 11/09/26 最新の投稿
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
11年前 に Devendra Patel によって更新されました。
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member 投稿: 71 参加年月日: 11/09/26 最新の投稿
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
11年前 に Devendra Patel によって更新されました。
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member 投稿: 71 参加年月日: 11/09/26 最新の投稿
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
11年前 に Devendra Patel によって更新されました。
Re: [Liferay Forums][4. General] RE: Checking user role in velocity templat
Junior Member 投稿: 71 参加年月日: 11/09/26 最新の投稿
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