Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Morad Ahmad
How to check if a user has a role within current community/site (Liferay 6.
9 de enero de 2012 12:04
Respuesta

Morad Ahmad

Ranking: Junior Member

Mensajes: 35

Fecha de incorporación: 16 de junio de 2010

Mensajes recientes

I defined a community role "SiteContentManager" which allows users to add specific content to a site, where they have this role. I need to check if the user has this role in a portlet. I tried different ways without success:

1. List<Role> userGroupRoles = RoleServiceUtil.getUserGroupRoles(user.getUserId(), communityId);
if (userGroupRoles != null) {
for (Role role : userGroupRoles) {
System.out.println(role.getName());
if (role.getName().equals(SITE_ADMIN_ROLE))
return true;
}
}

2. groupRoles = RoleLocalServiceUtil.getGroupRoles(communityId);
System.out.println("group roles: ");
if (groupRoles != null) {...}

3. RoleServiceUtil.hasUserRole(user.getUserId(), communityId, SITE_ADMIN_ROLE, true);

???

Thanks.
Jitendra Rajput
RE: How to check if a user has a role within current community/site (Lifera
9 de enero de 2012 21:20
Respuesta

Jitendra Rajput

Ranking: Liferay Master

Mensajes: 709

Fecha de incorporación: 7 de enero de 2011

Mensajes recientes

Have you tried by passing false in second approach .?

1RoleServiceUtil.hasUserRole(user.getUserId(), communityId, SITE_ADMIN_ROLE, false);


Similar kind of problem encountered in below thread ..look into it ..May help you.

http://www.liferay.com/community/forums/-/message_boards/message/4002510
Ricardo Piccoli
RE: How to check if a user has a role within current community/site (Lifera
12 de marzo de 2013 7:43
Respuesta

Ricardo Piccoli

Ranking: New Member

Mensajes: 6

Fecha de incorporación: 14 de febrero de 2013

Mensajes recientes

Any success?
Ricardo Piccoli
RE: How to check if a user has a role within current community/site (Lifera
13 de marzo de 2013 11:15
Respuesta

Ricardo Piccoli

Ranking: New Member

Mensajes: 6

Fecha de incorporación: 14 de febrero de 2013

Mensajes recientes

I was able to do that using:

UserGroupRoleLocalServiceUtil.hasUserGroupRole(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), "my-custom-role", true);

or

UserGroupRoleLocalServiceUtil.hasUserGroupRole(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), RoleConstants.SITE_ADMINISTRATOR, true);

This last "true", is because I don't add users but groups to sites.