Skip to content

Commit b5ffa37

Browse files
authored
Merge pull request #3125 from guusdk/OF-3168_Admin-console-default-url-for-tab
OF-3168: Fix default tab URL resolution after ordered menu reordering
2 parents 7964d33 + dd44f19 commit b5ffa37

3 files changed

Lines changed: 65 additions & 11 deletions

File tree

‎xmppserver/src/main/java/org/jivesoftware/admin/AdminConsole.java‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2004-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2004-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -368,15 +368,6 @@ private static synchronized void rebuildModel() {
368368
Element existingTab = getElemnetByID(id);
369369
// Simple case, there is no existing tab with the same id.
370370
if (existingTab == null) {
371-
// Make sure that the URL on the tab is set. If not, default to the
372-
// url of the first item.
373-
if (tab.attributeValue("url") == null) {
374-
Element firstItem = (Element) tab.selectSingleNode(
375-
"//item[@url]");
376-
if (firstItem != null) {
377-
tab.addAttribute("url", firstItem.attributeValue("url"));
378-
}
379-
}
380371
generatedModel.add(tab.createCopy());
381372
}
382373
// More complex case -- a tab with the same id already exists.
@@ -390,6 +381,23 @@ private static synchronized void rebuildModel() {
390381

391382
// OF-1484: Order everything explicitly.
392383
orderModel();
384+
385+
// Only after explicit ordering is applied (OF-3168), make sure that the URL on every tab is set. If not,
386+
// default to the url of the first item.
387+
for (Object o : generatedModel.selectNodes("//adminconsole//tab")) {
388+
Element tab = (Element) o;
389+
if (tab.attributeValue("url") == null) {
390+
final List<Element> sidebars = tab.elements("sidebar");
391+
if (!sidebars.isEmpty()) {
392+
sidebars.sort(new ElementByOrderAttributeComparator());
393+
final List<Element> items = sidebars.get(0).elements("item");
394+
if (!items.isEmpty()) {
395+
items.sort(new ElementByOrderAttributeComparator());
396+
tab.addAttribute("url", items.get(0).attributeValue("url"));
397+
}
398+
}
399+
}
400+
}
393401
}
394402

395403
/**

‎xmppserver/src/test/java/org/jivesoftware/util/AdminConsoleTest.java‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2004-2008 Jive Software. 2017-2025 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2004-2008 Jive Software. 2017-2026 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,4 +91,34 @@ public void testTabOverwrite() throws Exception {
9191
}
9292
assertTrue(found, "Failed to overwrite 'server' tab with new properties.");
9393
}
94+
95+
/**
96+
* Verifies that a tab without an explicit {@code url} attribute resolves its default URL
97+
* to the first item based on the effective ordering, not the XML definition order.
98+
*
99+
* In the admin console, tabs, side menus, and items can define an {@code order} attribute
100+
* that determines their display order. When a tab does not explicitly define a default
101+
* {@code url}, the admin console is expected to open the first item after applying this
102+
* ordering logic.
103+
*
104+
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-3168">OF-3168</a>
105+
*/
106+
@Test
107+
public void testDefaultUrlUsesOrderedFirstItem() throws Exception
108+
{
109+
// Setup test fixture.
110+
try (InputStream in = getClass().getResourceAsStream(
111+
"/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-04.xml")) {
112+
113+
// Execute system under test.
114+
AdminConsole.addModel("test4", in);
115+
}
116+
117+
// Verify result.
118+
final Element testTab = (Element) AdminConsole.getModel().selectSingleNode("//tab[@id='testtab']");
119+
final String actualUrl = testTab.attributeValue("url");
120+
final String expectedUrl = AdminConsole.getModel().valueOf("//item[@id='item1-1']/@url");
121+
assertNotNull(actualUrl, "Tab should have a resolved default URL");
122+
assertEquals(expectedUrl, actualUrl, "Tab default URL should match the first ordered item");
123+
}
94124
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
3+
<adminconsole>
4+
<tab id="testtab" name="A Test Tab" description="Testing 1 2 3">
5+
<sidebar id="sidebar2" order="20" name="Sidebar B">
6+
<item id="item2-3" name="Item C of Sidebar B" url="item2-3.jsp" order="3"/>
7+
<item id="item2-1" name="Item A of Sidebar B" url="item2-1.jsp" order="1"/>
8+
<item id="item2-2" name="Item B of Sidebar B" url="item2-2.jsp" order="2"/>
9+
</sidebar>
10+
<sidebar id="sidebar1" order="10" name="Sidebar A">
11+
<item id="item1-3" name="Item C of Sidebar A" url="item1-3.jsp" order="3"/>
12+
<item id="item1-1" name="Item A of Sidebar A" url="item1-1.jsp" order="1"/>
13+
<item id="item1-2" name="Item B of Sidebar A" url="item1-2.jsp" order="2"/>
14+
</sidebar>
15+
</tab>
16+
</adminconsole>

0 commit comments

Comments
 (0)