如何在Liferay中以编程方式为用户组分配站点角色 [英] How to assign site roles for user group programatically in liferay
问题描述
通过以下API调用,我可以以编程方式为用户分配站点角色,
I am able to assign the site roles for user programatically by following API call,
UserGroupRoleLocalServiceUtil.addUserGroupRoles(userIds, mySite, SiteroleIds);
任何人都可以以类似的方式告诉我如何以编程方式为UserGroup分配站点角色吗?
In the similar fashion can any one tell me that how can I assign the site roles for UserGroup programatically?
我的方法中同时包含usergroupID和SiteRoleId,所以我需要调用哪种API方法来为用户组分配站点角色?
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?
推荐答案
您可以使用UserGroupGroupRoleLocalServiceUtil
中的addUserGroupGroupRoles(long userGroupId, long groupId, long[] roleIds)
将SiteRoleId分配给userGroup.但是您也将需要groupId.
You can use addUserGroupGroupRoles(long userGroupId, long groupId, long[] roleIds)
of UserGroupGroupRoleLocalServiceUtil
to assign SiteRoleId to userGroup. But you will need groupId as well.
示例代码:
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);
这篇关于如何在Liferay中以编程方式为用户组分配站点角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!