diff --git a/modules/dxp/apps/analytics/analytics-reports-web/src/main/java/com/liferay/analytics/reports/web/internal/product/navigation/control/menu/AnalyticsReportsProductNavigationControlMenuEntry.java b/modules/dxp/apps/analytics/analytics-reports-web/src/main/java/com/liferay/analytics/reports/web/internal/product/navigation/control/menu/AnalyticsReportsProductNavigationControlMenuEntry.java index 0ebff3c1b2620a..f093121dc5d6f0 100644 --- a/modules/dxp/apps/analytics/analytics-reports-web/src/main/java/com/liferay/analytics/reports/web/internal/product/navigation/control/menu/AnalyticsReportsProductNavigationControlMenuEntry.java +++ b/modules/dxp/apps/analytics/analytics-reports-web/src/main/java/com/liferay/analytics/reports/web/internal/product/navigation/control/menu/AnalyticsReportsProductNavigationControlMenuEntry.java @@ -55,10 +55,12 @@ import java.io.Writer; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; +import java.util.Set; import javax.portlet.PortletRequest; @@ -325,14 +327,32 @@ private InfoItemReference _getInfoItemReference( return infoItemReference; } + private String _getResourceName( + String portletId, Map> resourceNames) { + + for (Map.Entry> entry : resourceNames.entrySet()) { + if (portletId.contains(entry.getKey())) { + return entry.getKey(); + } + } + + return null; + } + private boolean _hasResourcePermission( - String actionId, long groupId, String plid, - Map> resourceNames) { + String actionId, String plid, Map> resourceNames, + ThemeDisplay themeDisplay) { + + if (!themeDisplay.isSignedIn()) { + return false; + } if (Validator.isNotNull(plid)) { PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); + Set resourceNamesSet = new HashSet<>(); + List portletPreferencesList = _portletPreferencesLocalService.getPortletPreferencesByPlid( GetterUtil.getLong(plid)); @@ -340,20 +360,19 @@ private boolean _hasResourcePermission( for (PortletPreferences portletPreferences : portletPreferencesList) { - String portletId = portletPreferences.getPortletId(); - - for (Map.Entry> entry : - resourceNames.entrySet()) { + String resourceName = _getResourceName( + portletPreferences.getPortletId(), resourceNames); - if (portletId.contains(entry.getKey())) { - for (String resourceName : entry.getValue()) { - if (permissionChecker.hasPermission( - groupId, resourceName, "0", actionId)) { + if (resourceName != null) { + resourceNamesSet.add(resourceName); + } + } - return true; - } - } - } + for (String resourceName : resourceNamesSet) { + if (permissionChecker.hasPermission( + themeDisplay.getScopeGroupId(), resourceName, "0", + actionId)) { + return true; } } }