Search in sources :

Example 1 with ResourceBlockIdsBag

use of com.liferay.portal.security.permission.ResourceBlockIdsBag in project liferay-ide by liferay.

the class SearchPermissionCheckerImpl method doAddPermissionFields_6.

protected void doAddPermissionFields_6(long companyId, long groupId, String className, String classPK, Document doc) throws Exception {
    Group group = null;
    if (groupId > 0) {
        group = GroupLocalServiceUtil.getGroup(groupId);
    }
    List<Role> roles = ListUtil.copy(ResourceActionsUtil.getRoles(companyId, group, className, null));
    if (groupId > 0) {
        List<Role> teamRoles = RoleLocalServiceUtil.getTeamRoles(groupId);
        roles.addAll(teamRoles);
    }
    long[] roleIdsArray = new long[roles.size()];
    for (int i = 0; i < roleIdsArray.length; i++) {
        Role role = roles.get(i);
        roleIdsArray[i] = role.getRoleId();
    }
    boolean[] hasResourcePermissions = null;
    if (ResourceBlockLocalServiceUtil.isSupported(className)) {
        ResourceBlockIdsBag resourceBlockIdsBag = ResourceBlockLocalServiceUtil.getResourceBlockIdsBag(companyId, groupId, className, roleIdsArray);
        long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW);
        List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId);
        hasResourcePermissions = new boolean[roleIdsArray.length];
        for (long resourceBlockId : resourceBlockIds) {
            for (int i = 0; i < roleIdsArray.length; i++) {
                int count = ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount(resourceBlockId, roleIdsArray[i]);
                hasResourcePermissions[i] = (count > 0);
            }
        }
    } else {
        hasResourcePermissions = ResourcePermissionLocalServiceUtil.hasResourcePermissions(companyId, className, ResourceConstants.SCOPE_INDIVIDUAL, classPK, roleIdsArray, ActionKeys.VIEW);
    }
    List<Long> roleIds = new ArrayList<Long>();
    List<String> groupRoleIds = new ArrayList<String>();
    for (int i = 0; i < hasResourcePermissions.length; i++) {
        if (!hasResourcePermissions[i]) {
            continue;
        }
        Role role = roles.get(i);
        if ((role.getType() == RoleConstants.TYPE_ORGANIZATION) || (role.getType() == RoleConstants.TYPE_SITE)) {
            groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId());
        } else {
            roleIds.add(role.getRoleId());
        }
    }
    doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()]));
    doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()]));
}
Also used : Group(com.liferay.portal.model.Group) ArrayList(java.util.ArrayList) UserGroupRole(com.liferay.portal.model.UserGroupRole) Role(com.liferay.portal.model.Role) ResourceBlockIdsBag(com.liferay.portal.security.permission.ResourceBlockIdsBag)

Aggregations

Group (com.liferay.portal.model.Group)1 Role (com.liferay.portal.model.Role)1 UserGroupRole (com.liferay.portal.model.UserGroupRole)1 ResourceBlockIdsBag (com.liferay.portal.security.permission.ResourceBlockIdsBag)1 ArrayList (java.util.ArrayList)1