Skip to content

Commit

Permalink
fix: Fix access to site navigation having deleted pages - MEED-6510 - M…
Browse files Browse the repository at this point in the history
…eeds-io/meeds#1921 (#877)

Prior to this change, when the administration has the node navigation
which references a non existing page, then the administration link isn't
displayed and an NPE is thrown. This change will ensure to not consider
the navigations which doesn't have an accessible page in the list of
available navigation nodes of user.
  • Loading branch information
boubaker committed Apr 29, 2024
1 parent 15eb1c3 commit fc22e82
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public Collection<UserNode> getPortalSiteNavigations(String siteName, String por
return Collections.emptyList();
}
UserNodeFilterConfig builder = UserNodeFilterConfig.builder()
.withReadWriteCheck()
.withReadCheck()
.withVisibility(Visibility.DISPLAYED, Visibility.TEMPORAL)
.withTemporalCheck()
.build();
Expand All @@ -648,7 +648,7 @@ public UserNode getPortalSiteRootNode(String siteName,String siteType, HttpServl
public UserNode getFirstAllowedPageNode(Collection<UserNode> userNodes) {
UserNode userNode = null;
for (UserNode node : userNodes) {
if (node.getPageRef() != null) {
if (node.getPageRef() != null && layoutService.getPage(node.getPageRef()) != null) {
userNode = node;
break;
} else if (node.getChildren() != null && !node.getChildren().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand All @@ -35,6 +36,8 @@
import org.exoplatform.component.test.ConfiguredBy;
import org.exoplatform.component.test.ContainerScope;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.ApplicationState;
import org.exoplatform.portal.config.model.ApplicationType;
Expand All @@ -47,6 +50,8 @@
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.mop.page.PageKey;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.portal.mop.service.NavigationService;
import org.exoplatform.portal.mop.storage.DescriptionStorage;
import org.exoplatform.portal.mop.storage.PageStorage;
import org.exoplatform.portal.mop.storage.SiteStorage;
import org.exoplatform.portal.mop.user.UserNavigation;
Expand All @@ -62,9 +67,11 @@
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.UserHandler;
import org.exoplatform.services.resources.LocaleConfigService;
import org.exoplatform.services.security.Authenticator;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.services.test.mock.MockHttpServletRequest;
import org.exoplatform.test.mocks.servlet.MockServletRequest;

import jakarta.servlet.http.HttpServletRequest;
import junit.framework.AssertionFailedError;
Expand Down Expand Up @@ -156,6 +163,58 @@ private static Map<String, UserNavigation> toMap(List<UserNavigation> navigation
return map;
}

public void testComputePortalSitePath() {
new UnitTest() {
public void execute() throws Exception {
NewPortalConfig config = new NewPortalConfig("classpath:/org/exoplatform/portal/config/conf");
config.setOwnerType("portal");
config.setOverrideMode(true);
config.setImportMode("merge");
HashSet<String> owners = new HashSet<>();
owners.add("test2");
config.setPredefinedOwner(owners);
NewPortalConfigListener newPortalConfigListener = new NewPortalConfigListener(userPortalConfigSer_,
layoutService,
getContainer().getComponentInstanceOfType(ConfigurationManager.class),
new InitParams(),
getContainer().getComponentInstanceOfType(NavigationService.class),
getContainer().getComponentInstanceOfType(DescriptionStorage.class),
getContainer().getComponentInstanceOfType(UserACL.class),
getContainer().getComponentInstanceOfType(LocaleConfigService.class));
newPortalConfigListener.initPortalConfigDB(config);
newPortalConfigListener.initPageDB(config);
newPortalConfigListener.initPageNavigationDB(config);

UserPortalConfig userPortalCfg = userPortalConfigSer_.getUserPortalConfig("test2", "root");
assertNotNull(userPortalCfg);
PortalConfig portalCfg = userPortalCfg.getPortalConfig();
assertNotNull(portalCfg);
assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
assertEquals("test2", portalCfg.getName());

String path = userPortalConfigSer_.computePortalSitePath("test2", new MockServletRequest(null, Locale.ENGLISH) {
@Override
public String getRemoteUser() {
return "root";
}
});
assertEquals("/portal/test2/test", path);

restartTransaction();
layoutService.remove(PageKey.parse("portal::test2::test"));
restartTransaction();

path = userPortalConfigSer_.computePortalSitePath("test2", new MockServletRequest(null, Locale.ENGLISH) {
@Override
public String getRemoteUser() {
return "root";
}
});
assertEquals("/portal/test2/home/page", path);
}
}.execute("root");
}

public void testUpdatePortalConfig() {
new UnitTest() {
public void execute() throws Exception {
Expand Down Expand Up @@ -246,13 +305,14 @@ public void testGetSites() {
new UnitTest() {
public void execute() throws Exception {
userPortalConfigSer_.removeUserPortalConfig("jazz");
assertEquals(5, userPortalConfigSer_.getUserPortalSites().size());
int size = userPortalConfigSer_.getUserPortalSites().size();
assertTrue(size >= 5);

String originalGlobalPortal = userPortalConfigSer_.globalPortal_;
userPortalConfigSer_.globalPortal_ = "system";
userPortalConfigSer_.siteFilter.setExcludedSiteName(userPortalConfigSer_.getGlobalPortal());
try {
assertEquals(4, userPortalConfigSer_.getUserPortalSites().size());
assertEquals(size - 1, userPortalConfigSer_.getUserPortalSites().size());
} finally {
userPortalConfigSer_.globalPortal_ = originalGlobalPortal;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<node-navigation
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_6 http://www.gatein.org/xml/ns/gatein_objects_1_6"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_6">
<priority>1</priority>

<page-nodes>
<node>
<uri>test</uri>
<name>test</name>
<label>Test</label>
<page-reference>portal::test2::test</page-reference>
</node>
<node>
<uri>home</uri>
<name>home</name>
<label>Home</label>
<node>
<uri>page</uri>
<name>page</name>
<label>Page</label>
<page-reference>portal::test2::homepage</page-reference>
</node>
</node>
</page-nodes>
</node-navigation>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<page-set
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_6 http://www.gatein.org/xml/ns/gatein_objects_1_6"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_6">

<page>
<name>homepage</name>
<title>Home Page</title>
<access-permissions>Everyone</access-permissions>
<edit-permission>*:/platform/administrators</edit-permission>
</page>

<page>
<name>test</name>
<title>test</title>
<access-permissions>*:/platform/users</access-permissions>
<edit-permission>*:/platform/administrators</edit-permission>
</page>

</page-set>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<portal-config
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_10 http://www.gatein.org/xml/ns/gatein_objects_1_10"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_10">
<portal-name>test2</portal-name>
<label>test2</label>
<locale>en</locale>
<access-permissions>Everyone</access-permissions>
<edit-permission>*:/platform/administrators</edit-permission>
<portal-layout>
<page-body></page-body>
</portal-layout>
</portal-config>

0 comments on commit fc22e82

Please sign in to comment.