留言板
RE: Bulk assignment of members to organisations and bulk role assignement
Paul Robinson,修改在12 年前。
Bulk assignment of members to organisations and bulk role assignement
Junior Member 帖子: 46 加入日期: 08-12-30 最近的帖子
This may be of value to the community, I found this useful today for completing approximately 3000 member and role assignment transactions. In summary, We had some 300 users that needed to be assigned to approximately 6 organisations each e.g. students assigned as members to a class. Once they were members we needed to assign them a organisation role.
Obviously there are far better ways to do this level of integration e..g IDM, LDAP etc but in our current situation this is a work in progress. We created a simple beanshell script that took a CSV list of User and Organisation and completed the task for us rather than the manual assignment. The beanshell script was executed via the normal method in Control Panel, and I guess could be extended if required for additional role assignments.
Obviously there are far better ways to do this level of integration e..g IDM, LDAP etc but in our current situation this is a work in progress. We created a simple beanshell script that took a CSV list of User and Organisation and completed the task for us rather than the manual assignment. The beanshell script was executed via the normal method in Control Panel, and I guess could be extended if required for additional role assignments.
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
companyId = COMPANYID;
studentOrgRoleName = "ROLENAME";
userToGrps = new String[] { "ORGNAME,SCREENNAME","ORGNAME,SCREENNAME",};
studentOrgRole = RoleLocalServiceUtil.getRole(companyId, studentOrgRoleName);
for(int i=0; i<usertogrps.length; i++) { usertogrp="userToGrps[i];" usergrpdetail="userToGrp.split(",");" out.println("user: " + usergrpdetail[0] ", grp: usergrpdetail[1]); try user org usergrpdetail[0]); add as member to if(!userlocalserviceutil.hasorganizationuser(org.getorganizationid(), user.getuserid())) userlocalserviceutil.addorganizationusers(org.getorganizationid(), new long[] {user.getuserid()}); out.println("adding user: } role if(!usergrouprolelocalserviceutil.hasusergrouprole(user.getuserid(), org.getgroup().getgroupid(), studentorgrole.getroleid())) usergrouprolelocalserviceutil.addusergrouproles(user.getuserid(), {studentorgrole.getroleid(),}); role: +studentorgrolename+ catch(exception e) out.println(e.getmessage()); < code></usertogrps.length;>
Hitoshi Ozawa,修改在12 年前。
RE: Bulk assignment of members to organisations and bulk role assignement
Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Thanks for the information.
Marcos Laurito,修改在10 年前。
RE: Bulk assignment of members to organisations and bulk role assignement
Junior Member 帖子: 99 加入日期: 13-4-18 最近的帖子
I'm trying to use this script but is not working.
I've got a few questions.
Where is the CSV file used? Is any modification needed to make this work??
Sorry for my english and thanks.
I've got a few questions.
Where is the CSV file used? Is any modification needed to make this work??
Sorry for my english and thanks.