Skip to content

Instantly share code, notes, and snippets.

@bmvakili
Created October 10, 2012 19:54
Show Gist options
  • Save bmvakili/3867998 to your computer and use it in GitHub Desktop.
Save bmvakili/3867998 to your computer and use it in GitHub Desktop.
Liferay scripts - check every page permission in a group to see which roles have VIEW access
// ## CHANGE THESE ##
var largestLayoutId = 99999;
var groupName = "[group name]";
var showPublic = false;
var companyId = 10153;
var siteMemberRoleId= 10169;
var className = "com.liferay.portal.model.Layout";
//var groupId = Packages.com.liferay.portal.service.GroupLocalServiceUtil.getGroup(companyId, groupName).getGroupId();
var groupId = 10179;
var count = 0;
var rolesList = Packages.com.liferay.portal.service.RoleLocalServiceUtil.getRoles(companyId);
out.println(rolesList.size());
// ## get all layouts containing custom portlets (that is, ones whose ID is not numeric) and print their URLs
var layouts = Packages.com.liferay.portal.service.LayoutLocalServiceUtil.getLayouts(0,largestLayoutId);
number = layouts.size();
var names = "";
var portletNum = 0;
var dashes = 0;
function getDashes(i) {
ret = "";
for (x = 0; x < i; x++) {
ret += "-";
}
return ret;
}
for ( i = 0; i < number; i++) {
var layout = layouts.get(i);
var viewPerms = "";
layoutName = "";
if (layout.isTypePortlet()) {
layoutName = layout.getName();
var layoutTypePortlet = layout.getLayoutType();
var layoutTemplate = layoutTypePortlet.getLayoutTemplate();
var columns = layoutTemplate.getColumns();
defaultPortletCount = 0;
totalPortletCount = 0;
portletNum++;
if (layout.getGroupId() == groupId) {
var ind = 0;
var permsSize = 0;
var primaryKey = layout.getPlid()+"";
var resource = Packages.com.liferay.portal.service.ResourceLocalServiceUtil.getResource(companyId, className, Packages.com.liferay.portal.model.ResourceConstants.SCOPE_INDIVIDUAL, primaryKey) ;
var permissionsList = Packages.com.liferay.portal.service.ResourcePermissionLocalServiceUtil.getResourcePermissions(companyId, className, Packages.com.liferay.portal.model.ResourceConstants.SCOPE_INDIVIDUAL, layout.getPlid());
for ( ind = 0; ind < permissionsList.size(); ind++) {
var resourcePermission = permissionsList.get(ind);
var actionId = resourcePermission.getActionIds();
var roleId = resourcePermission.getRoleId();
var aRole = Packages.com.liferay.portal.service.RoleLocalServiceUtil.getRole(roleId);
var text = " rid: " + roleId + " " + aRole.getName() + " has access? ";
try{
var resourceAction = Packages.com.liferay.portal.service.ResourceActionLocalServiceUtil.getResourceAction(actionId);
var resourceActionId = resourceAction.getResourceActionId();
if (resourceActionId %2 == 1) {
if (viewPerms.length != 0) {
viewPerms += ", ";
}
viewPerms += aRole.getName();
}
/**
if ( "Sit" + "e" + " Member".equalsIgnoreCase(aRole.getName())) {
if (resourceActionId %2 ==1) {
out.println(text + "Yes, also has " + resourceActionId);
} else {
out.print(text);
if ( resourceAction > 0) {
out.println(" does not have view permission but has: " + resourceAction);
} else {
out.println(" does not have any permissions");
}
}
} else {
out.println(aRole.getName());
}
**/
} catch(e) {
}
}
permsSize += permissionsList.size();
if ( (showPublic && layout.isPublicLayout()) || (!showPublic && layout.isPrivateLayout()) ) {
out.println(layoutName + " in " + layout.getGroupId() + " ( " + (!layout.isPublicLayout()? "private" : "public") + " ) " + viewPerms);
count++;
}
}
}
}
out.println(count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment