Vinod
Vinod

Reputation: 2311

How to assign a Site Administration role for a user in liferay programatically?

I am creating the user programatically by calling the UserLocalServiceUtil.addUser(....) and able to assign the site for the created user by calling UserLocalServiceUtil.addRoleUser(userSiteId, userId) It is working fine. I am able to assign the site membership for the user. But how can I assign the Site Administration permission for creates user. (So for I am able to assign user as site member but I need to assign user as a site administrator)

Any suggestions please..

Upvotes: 2

Views: 984

Answers (2)

Prasad
Prasad

Reputation: 686

Use UserGroupRoleLocalServiceUtil to assign "Site Administration" role under the Site roles.

Role role = RoleLocalServiceUtil.getRole(companyId, "Site Administrator");
long[] SiteroleIds = {role.getRoleId()};
UserGroupRoleLocalServiceUtil.addUserGroupRoles(userId, siteId, SiteroleIds);

Upvotes: 4

Bhavin Panchani
Bhavin Panchani

Reputation: 1352

You can use RoleLocalServiceUtil to get object of any role.

Role role = RoleLocalServiceUtil.getRole(roleId);
UserLocalServiceUtil.addRoleUser(role.getRoleId(), user.getUserId());
UserLocalServiceUtil.updateUser(user);

Upvotes: 2

Related Questions