My requirement is such that I have to programmatically create organization pages and set permission to them. So far I created organization public pages
layout = LayoutLocalServiceUtil.addLayout(_defaultUserId, _groupId, PRIVATE_LAYOUT, PARENT_LAYOUT_ID, pageSetting.name, pageSetting.title, description, TYPE, pageSetting.hidden, pageSetting.url, serviceContext);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
But the public pages has guest
view permission. I want to remove that view
permission from guest user programmatically.
First of all you need to find role "Guest" for current Liferay instance (company):
long userRoleId = RoleLocalServiceUtil.getRole(_companyId, "Guest").getRoleId();
Afterwards you need to remove a permission:
ResourcePermissionLocalServiceUtil.removeResourcePermissions(
_companyId,
layout.getModelClassName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(layout.getPrimaryKey()),
userRoleId,
new String[]{ActionKeys.VIEW}
);
EDIT: updated according comment