How to assign site roles for user group programatically in liferay

折月煮酒 提交于 2020-01-16 00:35:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!