How to assign site roles for user group programatically in liferay
Asked Answered
D

1

1

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?

Dewey answered 15/4, 2015 at 8:39 Comment(0)
L
4

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);
Luminal answered 15/4, 2015 at 9:0 Comment(1)
Yes, group basically refers to site in Liferay.Luminal

© 2022 - 2024 — McMap. All rights reserved.