问题
I am able to assign the site roles for user programatically by following API call,
UserGroupRoleLocalServiceUtil.addUserGroupRoles(userIds, mySite, SiteroleIds);
In the similar fashion can any one tell me that how can I assign the site roles for UserGroup programatically?
I have both usergroupID and SiteRoleId in my method so what API method should I need to call to assign the site roles for the user group?
回答1:
You can use addUserGroupGroupRoles(long userGroupId, long groupId, long[] roleIds)
of UserGroupGroupRoleLocalServiceUtil
to assign SiteRoleId to userGroup. But you will need groupId as well.
Sample Code:
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);
来源:https://stackoverflow.com/questions/29645490/how-to-assign-site-roles-for-user-group-programatically-in-liferay