diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/webmodules/WebModule.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/webmodules/WebModule.java index e9a3811229da..e132ae06111c 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/webmodules/WebModule.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/webmodules/WebModule.java @@ -82,12 +82,14 @@ public static WebModule getModule(App app) { String defaultAction = app.getLaunchUrl(); - String icon = hasIcon ? app.getBaseUrl() + "/" + app.getIcons().getIcon48() : null; - String description = subString(app.getDescription(), 0, 80); String displayDescription = subString(app.getDisplayDescription(), 0, 80); String key = app.isBundled() ? AppManager.BUNDLED_APP_PREFIX + app.getKey() : app.getKey(); + String icon = + hasIcon + ? app.getBaseUrl() + "/" + app.getIcons().getIcon48() + : app.getBaseUrl() + "/icons/" + key + ".png"; WebModule module = new WebModule(key, app.getBasePath(), defaultAction); module.setIcon(icon); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AppControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AppControllerTest.java index bfc7b9804830..f0ba7c9721a8 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AppControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AppControllerTest.java @@ -60,6 +60,8 @@ import org.hisp.dhis.http.HttpStatus; import org.hisp.dhis.jsontree.JsonArray; import org.hisp.dhis.jsontree.JsonMixed; +import org.hisp.dhis.jsontree.JsonObject; +import org.hisp.dhis.jsontree.JsonString; import org.hisp.dhis.security.Authorities; import org.hisp.dhis.test.config.TestDhisConfigurationProvider; import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase; @@ -117,6 +119,25 @@ void cleanUp() { DELETE("/userSettings/keyUiLocale/?userId=" + ADMIN_USER_UID); } + @Test + void testGetAppMenuWhenInstalledAppWithoutIconInManifest() throws IOException { + appManager.installApp(new ClassPathResource("app/test-app-wihout-icon.zip").getFile()); + + HttpResponse response = GET("/apps/menu"); + JsonArray apps = response.content(HttpStatus.OK); + String icon = + apps.asObject() + .get("modules") + .asList(JsonObject.class) + .get(0) + .get("icon") + .as(JsonString.class) + .string(); + assertTrue( + icon.equals("http://localhost/api/apps/test/icons/test.png") + || icon.equals("http://localhost/api/apps/myapp/dhis2-app-icon.png")); + } + @Test void testGetInstalledAppIndexHtml() throws IOException { appManager.installApp(new ClassPathResource("app/test-app-with-index-html.zip").getFile()); diff --git a/dhis-2/dhis-test-web-api/src/test/resources/app/test-app-wihout-icon.zip b/dhis-2/dhis-test-web-api/src/test/resources/app/test-app-wihout-icon.zip new file mode 100644 index 000000000000..90f8e3b1df05 Binary files /dev/null and b/dhis-2/dhis-test-web-api/src/test/resources/app/test-app-wihout-icon.zip differ