Created
November 2, 2012 17:23
-
-
Save bmvakili/4002911 to your computer and use it in GitHub Desktop.
Liferay scripts - check permissions on CalEvent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ### Javascript Sample ### | |
companyId = 10153; | |
model = "com.liferay.portlet.calendar.model.CalEvent"; | |
portletId = "8"; | |
folder = Packages.com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getEvent(137535); | |
resource = Packages.com.liferay.portal.service.ResourceLocalServiceUtil.getResource(companyId, model, Packages.com.liferay.portal.model.ResourceConstants.SCOPE_INDIVIDUAL, folder.getPrimaryKey()); | |
resourceActions = Packages.com.liferay.portal.security.permission.ResourceActionsUtil.getResourceActions(portletId, model); | |
administrator = Packages.com.liferay.portal.service.RoleLocalServiceUtil.getRole(folder.getCompanyId(), Packages.com.liferay.portal.model.RoleConstants.ADMINISTRATOR); | |
roleTypes = [] | |
group = Packages.com.liferay.portal.service.GroupLocalServiceUtil.getGroup(folder.getGroupId()); | |
roles = Packages.com.liferay.portal.security.permission.ResourceActionsUtil.getRoles(folder.getCompanyId(), group, model); | |
roles.remove(administrator); | |
itr = roles.iterator(); | |
permissionChecker = Packages.com.liferay.portal.security.permission.PermissionThreadLocal.getPermissionChecker(); | |
guestUnsupportedActions = Packages.com.liferay.portal.security.permission.ResourceActionsUtil.getResourceGuestUnsupportedActions(portletId, model ); | |
out.println("Guest"); | |
out.println("Unsupported Actions : " + guestUnsupportedActions); | |
while(itr.hasNext()) { | |
role = itr.next(); | |
name = role.getName(); | |
currentIndividualActions = Packages.com.liferay.portal.service.ResourcePermissionLocalServiceUtil.getAvailableResourcePermissionActionIds(resource.getCompanyId(), resource.getName(), resource.getScope(), resource.getPrimKey(), role.getRoleId(), resourceActions); | |
currentGroupActions = Packages.com.liferay.portal.service.ResourcePermissionLocalServiceUtil.getAvailableResourcePermissionActionIds(resource.getCompanyId(), resource.getName(), Packages.com.liferay.portal.model.ResourceConstants.SCOPE_GROUP, folder.getGroupId(), role.getRoleId(), resourceActions); | |
currentGroupTemplateActions = Packages.com.liferay.portal.service.ResourcePermissionLocalServiceUtil.getAvailableResourcePermissionActionIds(resource.getCompanyId(), resource.getName(), Packages.com.liferay.portal.model.ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", role.getRoleId(), resourceActions); | |
currentCompanyActions = Packages.com.liferay.portal.service.ResourcePermissionLocalServiceUtil.getAvailableResourcePermissionActionIds(resource.getCompanyId(), resource.getName(), Packages.com.liferay.portal.model.ResourceConstants.SCOPE_COMPANY, ""+resource.getCompanyId(), role.getRoleId(), resourceActions); | |
//var resourceActionOne = resourceActions[0]; | |
//out.println("R1" + resourceActionOne); | |
for ( ind = 0; ind < resourceActions.length; ind++) { | |
resourceAction = resourceActions[ind]; | |
out.println(resourceAction); | |
if (currentIndividualActions.contains(resourceAction)) { | |
out.println("Individual Actions : "+ resourceAction); | |
} | |
} | |
out.println(role.getName() + " : "); | |
out.println("Individual Actions : "+ currentIndividualActions); | |
out.println("Group Actions : "+ currentGroupActions); | |
out.println("Group Template Actions: " + currentGroupTemplateActions); | |
out.println("Company Actions : " + currentCompanyActions); | |
out.println("----"); | |
} | |
out.println(roles); | |
out.println(resourceActions); | |
out.println(folder); | |
out.println(resource); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment