Search

Thursday, June 17, 2010

Community Roles for User Groups in Liferay

I have done massive investigation on User Group Roles and Permission. I have using same community roles for User Group to make working like community.
Resource resource = ResourceLocalServiceUtil.getResource(group.getCompanyId(), Group.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(group.getGroupId()));
System.out.println("resourceId : "+resource.getResourceId());
/*List actions =
ResourceActionsUtil.getModelResourceCommunityDefaultActions(
Group.class.getName());
String[] actionIds = actions.toArray(new String[actions.size()]);*/

String[] actionIds = new String[7];
actionIds[0] = "ASSIGN_MEMBERS";
actionIds[1] = "DELETE";
actionIds[2] = "MANAGE_ANNOUNCEMENTS";
actionIds[3] = "PERMISSIONS";
actionIds[4] = "MANAGE_LAYOUTS";
actionIds[5] = "UPDATE";
actionIds[6] = "VIEW";

PermissionLocalServiceUtil.setUserPermissions(group.getCreatorUserId(), actionIds, resource.getResourceId());

//PermissionLocalServiceUtil.addPermissions(group.getCompanyId(), actions, resource.getResourceId());

Role roleAdmin = RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.COMMUNITY_ADMINISTRATOR);

PermissionLocalServiceUtil.setRolePermissions(roleAdmin.getRoleId(), actionIds, resource.getResourceId());

Role roleOwner = RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.COMMUNITY_OWNER);

PermissionLocalServiceUtil.setRolePermissions(roleOwner.getRoleId(), actionIds, resource.getResourceId());

Added this code in EditUserGroupAction.java at the time of creating User Group.

With this User Group is start behaving like Community.