Foros de discusión

How to programatically assign existing user group as a site member

Lukas Barina, modificado hace 11 años.

How to programatically assign existing user group as a site member

New Member Mensajes: 8 Fecha de incorporación: 7/06/12 Mensajes recientes
Hi,
I cannot find a way how to programatically assign new members to a site.

Version of liferay used : 6.1.1

1, I am creating new site from a template - already ok - everything works

newSite = GroupLocalServiceUtil.addGroup(themeDisplay.getUserId(), Group.class.getName(), 0, myFirstSite,
"test site", GroupConstants.TYPE_SITE_OPEN, "/" + myFirstSite, true, true, serviceContext);
SitesUtil.applyLayoutSetPrototypes(newSite, 0, myLayoutPrototype.getLayoutSetPrototypeId(),
serviceContext);

2, I have existing user groups with users (imported automatically from ldap) - no problem all user groups and members visible in liferay

3, I want to assign existing user group to my freshly created site - I am lost how to do it , not sure about what API to use

Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), "Site Member");
long[] roles = new long[] { role.getRoleId() };

I tried this method but seems to not working:
UserGroupGroupRoleLocalServiceUtil.addUserGroupGroupRoles(myUserGroup.getUserGroupId(), newSite.getGroupId(), roles);

Thanks for your help here

-Lukas
Chintan Akhani, modificado hace 11 años.

RE: How to programatically assign existing user group as a site member

Regular Member Mensajes: 111 Fecha de incorporación: 13/03/08 Mensajes recientes
Hi Lukas,

As per my knowledge, you have used right API for assigning 'Site Member' role to user group. Only thing which might be a problem here is 'myUserGroup.getUserGroupId()', can you please check whether you are passing right user group id or not.
Lukas Barina, modificado hace 11 años.

RE: How to programatically assign existing user group as a site member

New Member Mensajes: 8 Fecha de incorporación: 7/06/12 Mensajes recientes
Hi Chintan,
I am 100% sure I am passing the correct user group id, because before this code I am printing
infomartions about all existing user groups and all their members.
And just before this code I am printing againg the user group id.

Just wondered if this method is the right one for assinging of a user group to a site...

In the below thread I found that there is some other possible way for assigning members to communities (old name of sites)
but it's a class from struts package not accessible in my portlet so I guess for me not usable at all:
EditGroupAssignmentsAction

http://www.liferay.com/community/forums/-/message_boards/view_message/4974302#_19_message_4954382

Thanks for any comments or if you have already done some assignments of users into the sites please send
your example code

--Lukas
Lukas Barina, modificado hace 11 años.

RE: How to programatically assign existing user group as a site member (Respuesta)

New Member Mensajes: 8 Fecha de incorporación: 7/06/12 Mensajes recientes
Hi again,
I found the solution, I just used not proper class from API
So to assign existing user group to a site you have to use following API code:

long[] groups = new long[] { userGroup.getUserGroupId() };

UserGroupLocalServiceUtil.addGroupUserGroups(newSite.getGroupId(), groups);

--Lukas