How to assign site roles to a group of users programmatically in liferay

I can assign site roles to the user programmatically by following an API call,

UserGroupRoleLocalServiceUtil.addUserGroupRoles(userIds, mySite, SiteroleIds); 

Similarly, can someone tell me how to programmatically assign site roles to UserGroup?

I have both usergroupID and SiteRoleId in my method, so which API method do I need to call to assign site roles to a group of users?

+1
source share
1 answer

You can use addUserGroupGroupRoles(long userGroupId, long groupId, long[] roleIds) for UserGroupGroupRoleLocalServiceUtil to assign SiteRoleId to userGroup. But you will also need groupId.

Code example:

 UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId); Role role = RoleLocalServiceUtil.getRole(companyId, "role name"); long[] roles = new long[] {role.getRoleId()}; UserGroupGroupRoleLocalServiceUtil.addUserGroupGroupRoles(userGroup.getUserGroupId(), site.getGroupId(), roles); 
+3
source

Source: https://habr.com/ru/post/1238862/


All Articles