Skip to content

Commit ebde291

Browse files
committed
fix(DHIS2-21366): restore undefined app icon behaviour to prevent browser clients from breaking
1 parent 6eb91fd commit ebde291

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/webmodules/WebModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ public static WebModule getModule(App app) {
8282

8383
String defaultAction = app.getLaunchUrl();
8484

85-
String icon = hasIcon ? app.getBaseUrl() + "/" + app.getIcons().getIcon48() : null;
86-
8785
String description = subString(app.getDescription(), 0, 80);
8886
String displayDescription = subString(app.getDisplayDescription(), 0, 80);
8987

9088
String key = app.isBundled() ? AppManager.BUNDLED_APP_PREFIX + app.getKey() : app.getKey();
89+
String icon =
90+
hasIcon
91+
? app.getBaseUrl() + "/" + app.getIcons().getIcon48()
92+
: app.getBaseUrl() + "/icons/" + key + ".png";
9193

9294
WebModule module = new WebModule(key, app.getBasePath(), defaultAction);
9395
module.setIcon(icon);

dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AppControllerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import org.hisp.dhis.http.HttpStatus;
6161
import org.hisp.dhis.jsontree.JsonArray;
6262
import org.hisp.dhis.jsontree.JsonMixed;
63+
import org.hisp.dhis.jsontree.JsonObject;
64+
import org.hisp.dhis.jsontree.JsonString;
6365
import org.hisp.dhis.security.Authorities;
6466
import org.hisp.dhis.test.config.TestDhisConfigurationProvider;
6567
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
@@ -117,6 +119,23 @@ void cleanUp() {
117119
DELETE("/userSettings/keyUiLocale/?userId=" + ADMIN_USER_UID);
118120
}
119121

122+
@Test
123+
void testGetAppMenuWhenInstalledAppWithoutIconInManifest() throws IOException {
124+
appManager.installApp(new ClassPathResource("app/test-app-wihout-icon.zip").getFile());
125+
126+
HttpResponse response = GET("/apps/menu");
127+
JsonArray apps = response.content(HttpStatus.OK);
128+
assertEquals(
129+
"http://localhost/api/apps/test/icons/test.png",
130+
apps.asObject()
131+
.get("modules")
132+
.asList(JsonObject.class)
133+
.get(0)
134+
.get("icon")
135+
.as(JsonString.class)
136+
.string());
137+
}
138+
120139
@Test
121140
void testGetInstalledAppIndexHtml() throws IOException {
122141
appManager.installApp(new ClassPathResource("app/test-app-with-index-html.zip").getFile());
Binary file not shown.

0 commit comments

Comments
 (0)