We ran into a use case where we need to automate creation of custom roles having several hundreds of permission keys.
It's kind of tire some to grab each & every one either by looking into source code or grabbing using some browser tools.
I wrote a simple java script to grab keys for each portlet. We need to go to each portlet level to grab exact keys.
It will print in console relevant permissions for that particular portlet. I am using 6.2 for you reference
HOW TO TEST
>> After you navigation to your custom role, particular portlet - CTRL+SHIFT+J (in chrome)
>> paste below code & hit enter - it will spill relevant keys on console.
/*
Start
*/
var topPortletTxt = AUI().one('#_128_permissionContentContainer').one('h3').text();
var topGeneralNode = AUI().one('#_128_permissionContentContainer').one('h4');
var topGeneralTxt;
if(topGeneralNode != null){
topGeneralTxt = topGeneralNode.get('firstChild').get('textContent');
}
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + topGeneralTxt + ' > ' + topPortletTxt + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<');
var resourcePermissionsFull = "";
var resourcePermissionStartOpen = '
';
var resourcePermissionEnd = "
";
var resourcePermissionActionStart = "
";
var resourcePermissionActionClose = "
";
var topLevelResourceId = AUI().one('#_128_portletResource').val();
var commentStart = '';
resourcePermissionsFull = resourcePermissionsFull + commentStart + topGeneralTxt + ' > ' + topPortletTxt + commentEnd + '\n';
resourcePermissionsFull = resourcePermissionsFull + resourcePermissionStartOpen + topLevelResourceId + resourcePermissionStartClose;
var generalResourcePermissionsAll = "";
topGeneralNode.get('nextElementSibling').all(':checked').each(function(node1) {
console.log(node1.val());
if (node1.val().indexOf(topLevelResourceId) != -1) {
generalResourcePermissionsAll = generalResourcePermissionsAll + resourcePermissionActionStart + node1.val().replace(topLevelResourceId, '') + resourcePermissionActionClose;
}
}
);
resourcePermissionsFull = resourcePermissionsFull + generalResourcePermissionsAll + resourcePermissionEnd;
console.log("resourcePermissionsFull : Top > \n\n" + resourcePermissionsFull);
// Related portlet permissions
/*
var relatedPortletsTxt = AUI().one('#_128_relatedPortletResources').ancestor().get('previousElementSibling').get('textContent');
var resourcePermissionsFull = resourcePermissionsFull + commentStart + topPortletTxt + ' > ' + relatedPortletsTxt + commentEnd + '\n';
var resourcePermissionsAll2 = "";
AUI().one('#_128_relatedPortletResources').get('nextElementSibling').all(':checked').each(function(node2) {
console.log(">>" + node2.val());
var resourceId = parseInt(node2.val(), 10);
var resourcePermissionStartTemp = resourcePermissionStartOpen + resourceId + resourcePermissionStartClose;
resourcePermissionsAll2 = resourcePermissionsAll2 + resourcePermissionStartTemp;
resourcePermissionsAll2 = resourcePermissionsAll2 + resourcePermissionActionStart + node2.val().replace(resourceId, '') + resourcePermissionActionClose;
resourcePermissionsAll2 = resourcePermissionsAll2 + resourcePermissionEnd;
}
);
console.log("resourcePermissionsAll2" + resourcePermissionsAll2)
resourcePermissionsFull = resourcePermissionsFull + resourcePermissionsAll2;
console.log("resourcePermissionsFull : After Related portlet permissions > \n\n" + resourcePermissionsFull);
*/
// Resource permissions
var topResourceTxt = AUI().all('.permission-group').get('previousElementSibling').get('firstChild').get('textContent');
AUI().all('.permission-group h5').each(
function(node) {
console.log(topResourceTxt + ' > ' + node.html());
resourcePermissionsFull = resourcePermissionsFull + commentStart + topResourceTxt + ' > ' + node.html() + commentEnd + '\n';
var nodeIdPackageConv = node.get('id').replace('resource_', '').replace(/_/g, ".");
console.log(nodeIdPackageConv);
var resourcePermissionStartTemp = resourcePermissionStartOpen + nodeIdPackageConv + resourcePermissionStartClose;
var resourcePermissionsAll = "";
node.get('nextElementSibling').all(':checked').each(function(node2) {
console.log(">>" + node2.val().replace(nodeIdPackageConv, ''));
resourcePermissionsAll = resourcePermissionsAll + resourcePermissionActionStart + node2.val().replace(nodeIdPackageConv, '') + resourcePermissionActionClose;
})
resourcePermissionsFull = resourcePermissionsFull + resourcePermissionStartTemp + resourcePermissionsAll + resourcePermissionEnd;
}
);
console.log("resourcePermissionsFull : Final > \n\n" + resourcePermissionsFull);
/*
End
*/
Hope it helps some body :)
Thanks.