use of com.liferay.portal.kernel.util.UniqueList in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doGetPermissionQuery.
protected Query doGetPermissionQuery(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext) throws Exception {
Indexer indexer = IndexerRegistryUtil.getIndexer(className);
if (!indexer.isPermissionAware()) {
return query;
}
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
AdvancedPermissionChecker advancedPermissionChecker = null;
if ((permissionChecker != null) && (permissionChecker instanceof AdvancedPermissionChecker)) {
advancedPermissionChecker = (AdvancedPermissionChecker) permissionChecker;
}
if (advancedPermissionChecker == null) {
return query;
}
PermissionCheckerBag permissionCheckerBag = getPermissionCheckerBag(advancedPermissionChecker, userId);
if (permissionCheckerBag == null) {
return query;
}
List<Group> groups = new UniqueList<Group>();
List<Role> roles = new UniqueList<Role>();
List<UserGroupRole> userGroupRoles = new UniqueList<UserGroupRole>();
Map<Long, List<Role>> groupIdsToRoles = new HashMap<Long, List<Role>>();
roles.addAll(permissionCheckerBag.getRoles());
if (ArrayUtil.isEmpty(groupIds)) {
groups.addAll(GroupLocalServiceUtil.getUserGroups(userId, true));
groups.addAll(permissionCheckerBag.getGroups());
userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);
} else {
groups.addAll(permissionCheckerBag.getGroups());
for (long groupId : groupIds) {
if (GroupLocalServiceUtil.hasUserGroup(userId, groupId)) {
Group group = GroupLocalServiceUtil.getGroup(groupId);
groups.add(group);
}
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId, groupId));
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRolesByUserUserGroupAndGroup(userId, groupId));
}
}
if (advancedPermissionChecker.isSignedIn()) {
roles.add(RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST));
}
for (Group group : groups) {
PermissionCheckerBag userBag = advancedPermissionChecker.getUserBag(userId, group.getGroupId());
List<Role> groupRoles = userBag.getRoles();
groupIdsToRoles.put(group.getGroupId(), groupRoles);
roles.addAll(groupRoles);
}
return doGetPermissionQuery_6(companyId, groupIds, userId, className, query, searchContext, advancedPermissionChecker, groups, roles, userGroupRoles, groupIdsToRoles);
}
Aggregations