Search code examples
themesliferayvelocityroles

Liferay Theme - Velocity - Check if user has custom role


I've been scouring through questions on SO for a solution to this without any luck as of yet. I have found some similar questions, but no solution.

I'm trying to add some sort of role check on login to see if a user has a custom role i've defined. If so. They get the dockbar.

Currently it's checking to see if they're an admin across the entire site. Which is something I don't want to give people. They need to be like a Power User with a specific set of permissions.

The current check is like so:

#if ($is_signed_in && $permissionChecker.isOmniadmin())

I have seen examples checking for a specific role ID which look like they would work.

Example here:

#set($UserLocalServiceUtil = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#if ($UserLocalServiceUtil.hasRoleUser(roleID, $user.getUserId()))

The only problem with this approach is I am unsure of what my custom roles ID is and how I go about getting it..

So

Does anyone know how I can get my custom roles ID?

OR

Is there some sort of .getRoleName selector that I have overlooked?


Solution

  • Maybe this method could help you to complete the code.

    Is it possible to have Role by name (and the name could be stored & configured by theme settings)

    #set($RoleLocalServiceUtil = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
    #set ($role = $RoleLocalServiceUtil.fetchRole(roleName, $themeDisplay.companyId))