Resource resource = ResourceLocalServiceUtil.getResource(group.getCompanyId(), Group.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(group.getGroupId()));
System.out.println("resourceId : "+resource.getResourceId());
/*Listactions =
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.
I want to know what version of Liferay are you using.
ReplyDeleteI'm using Liferay 6, and I'm always getting resource.getResourceId() = 0. May it's a LR6 bug.
Thanks! Nice Blog!
In LR6 I solved it using
ReplyDeleteResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, name,scope, primKey, roleId, actionIds);
istead of
PermissionLocalServiceUtil.setRolePermissions
Thank you very much for comments.
ReplyDeleteThe above solution is for LR5.2.3.
Thanks,
S Mohammed Zaheer