From 4a25d76be9505387f44b1ea05145399c43c3be12 Mon Sep 17 00:00:00 2001 From: Almir Ferreira Date: Thu, 25 Apr 2024 15:36:29 -0300 Subject: [PATCH] LPD-2249 portal-search: If groupIds list is empty, check resourcePermission for all available groups https://liferay.atlassian.net/browse/LPD-2249 --- .../internal/SearchPermissionCheckerImpl.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/apps/portal-search/portal-search/src/main/java/com/liferay/portal/search/internal/SearchPermissionCheckerImpl.java b/modules/apps/portal-search/portal-search/src/main/java/com/liferay/portal/search/internal/SearchPermissionCheckerImpl.java index 3141ef4f89f1c0..db0f1ac2d2eb88 100644 --- a/modules/apps/portal-search/portal-search/src/main/java/com/liferay/portal/search/internal/SearchPermissionCheckerImpl.java +++ b/modules/apps/portal-search/portal-search/src/main/java/com/liferay/portal/search/internal/SearchPermissionCheckerImpl.java @@ -34,6 +34,7 @@ import com.liferay.portal.kernel.security.permission.PermissionCheckerFactory; import com.liferay.portal.kernel.security.permission.PermissionThreadLocal; import com.liferay.portal.kernel.security.permission.UserBag; +import com.liferay.portal.kernel.service.GroupLocalService; import com.liferay.portal.kernel.service.ResourcePermissionLocalService; import com.liferay.portal.kernel.service.RoleLocalService; import com.liferay.portal.kernel.service.UserLocalService; @@ -519,16 +520,18 @@ private BooleanFilter _getPermissionFilter( } } - if (ArrayUtil.isNotEmpty(groupIds)) { - for (long searchGroupId : groupIds) { - if (!searchPermissionContext.containsGroupId(searchGroupId) && - _resourcePermissionLocalService.hasResourcePermission( - companyId, className, ResourceConstants.SCOPE_GROUP, - String.valueOf(searchGroupId), roleIds, - ActionKeys.VIEW)) { + if (ArrayUtil.isEmpty(groupIds)) { + groupIds = ArrayUtil.toLongArray( + _groupLocalService.getGroupIds(companyId, true)); + } - groupsTermsFilter.addValue(String.valueOf(searchGroupId)); - } + for (long searchGroupId : groupIds) { + if (!searchPermissionContext.containsGroupId(searchGroupId) && + _resourcePermissionLocalService.hasResourcePermission( + companyId, className, ResourceConstants.SCOPE_GROUP, + String.valueOf(searchGroupId), roleIds, ActionKeys.VIEW)) { + + groupsTermsFilter.addValue(String.valueOf(searchGroupId)); } } @@ -564,6 +567,9 @@ private String _getPermissionName( private static final Log _log = LogFactoryUtil.getLog( SearchPermissionCheckerImpl.class); + @Reference + private GroupLocalService _groupLocalService; + @Reference private IndexerRegistry _indexerRegistry;