Fórum

Check if User has Custom Organization Role

Guru k, modificado 11 Anos atrás.

Check if User has Custom Organization Role

Junior Member Postagens: 64 Data de Entrada: 08/02/12 Postagens Recentes
Hi,

I have created custom Organization Roles. How to check if the current user has custom Organization Roles in Custom portlet jsp.

Thanks
thumbnail
Paul ., modificado 11 Anos atrás.

RE: Check if User has Custom Organization Role

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
Roughly you can achieve it with:-

1. Get current userId from ThemeDisplay
2. Get companyId from ThemeDisplay
3. Get Role from RoleLocalServiceUitl passing companyId and the name of role you created
4. Check if the user has role using RoleLocalServiceUitl passing roleId and UserId


1. long com.liferay.portal.theme.ThemeDisplay.getUserId()
2. long com.liferay.portal.theme.ThemeDisplay.getCompanyId()
3. Role com.liferay.portal.service.RoleLocalServiceUtil.getRole(long companyId, String name) throws PortalException, SystemException
4. boolean com.liferay.portal.service.RoleLocalServiceUtil.hasUserRole(long userId, long roleId) throws SystemException

There are so many ways, may be more efficient ones.
Guru k, modificado 11 Anos atrás.

RE: Check if User has Custom Organization Role

Junior Member Postagens: 64 Data de Entrada: 08/02/12 Postagens Recentes
Hi Paul,

Thanks for the reply... but with these i could get only the regular roles not the Organization Role.

Thanks
thumbnail
Jitendra Rajput, modificado 11 Anos atrás.

RE: Check if User has Custom Organization Role

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Even you can check with below method also .
It will check for the current user is having specified role or not .
portletRequest.isUserInRole("roleName")
thumbnail
Paul ., modificado 11 Anos atrás.

RE: Check if User has Custom Organization Role

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
You are right, try:

getting all UserGroupRoles using UserGroupRoleLocalServiceUtil.getUserGroupRoles(themeDisplay.getUserId());
get actual role object using Role com.liferay.portal.model.UserGroupRole.getRole() and then tally the name traversing the list

Hope it helps.