Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Guru k
Check if User has Custom Organization Role
17 de Maio de 2012 00:03
Resposta

Guru k

Ranking: Junior Member

Mensagens: 64

Data de entrada: 7 de Fevereiro de 2012

Mensagens recentes

Hi,

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

Thanks
Bart Simpson
RE: Check if User has Custom Organization Role
17 de Maio de 2012 00:26
Resposta

Bart Simpson

Ranking: Liferay Master

Mensagens: 524

Data de entrada: 29 de Agosto de 2011

Mensagens 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


11. long com.liferay.portal.theme.ThemeDisplay.getUserId()
22. long com.liferay.portal.theme.ThemeDisplay.getCompanyId()
33. Role com.liferay.portal.service.RoleLocalServiceUtil.getRole(long companyId, String name) throws PortalException, SystemException
44. 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
RE: Check if User has Custom Organization Role
17 de Maio de 2012 03:24
Resposta

Guru k

Ranking: Junior Member

Mensagens: 64

Data de entrada: 7 de Fevereiro de 2012

Mensagens recentes

Hi Paul,

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

Thanks
Jitendra Rajput
RE: Check if User has Custom Organization Role
17 de Maio de 2012 04:04
Resposta

Jitendra Rajput

Ranking: Liferay Master

Mensagens: 858

Data de entrada: 7 de Janeiro de 2011

Mensagens recentes

Even you can check with below method also .
It will check for the current user is having specified role or not .
1portletRequest.isUserInRole("roleName")
Bart Simpson
RE: Check if User has Custom Organization Role
17 de Maio de 2012 04:43
Resposta

Bart Simpson

Ranking: Liferay Master

Mensagens: 524

Data de entrada: 29 de Agosto de 2011

Mensagens 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.