fix: Set default theme when application is exported (#13321)
When application is exported and it does not have a theme set, a NullPointerException was raised in that case. This PR fixes that by returning the default theme when theme is missing.
This commit is contained in:
parent
c6f3f356e6
commit
e9b1108e47
|
|
@ -186,6 +186,8 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
|
|||
applicationJson.setServerSchemaVersion(JsonSchemaVersions.serverVersion);
|
||||
applicationJson.setClientSchemaVersion(JsonSchemaVersions.clientVersion);
|
||||
|
||||
Mono<Theme> defaultThemeMono = themeService.getSystemTheme(Theme.DEFAULT_THEME_NAME).cache();
|
||||
|
||||
return pluginRepository
|
||||
.findAll()
|
||||
.map(plugin -> {
|
||||
|
|
@ -194,10 +196,10 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
|
|||
})
|
||||
.then(applicationMono)
|
||||
.flatMap(application -> themeService.getThemeById(application.getEditModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.THEME, application.getEditModeThemeId())))
|
||||
.switchIfEmpty(defaultThemeMono) // setting default theme if theme is missing
|
||||
.zipWith(themeService
|
||||
.getThemeById(application.getPublishedModeThemeId(), READ_THEMES)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.THEME, application.getPublishedModeThemeId())))
|
||||
.switchIfEmpty(defaultThemeMono)// setting default theme if theme is missing
|
||||
)
|
||||
.map(themesTuple -> {
|
||||
Theme editModeTheme = exportTheme(themesTuple.getT1());
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.appsmith.server.acl.AclPermission.MANAGE_ACTIONS;
|
||||
|
|
@ -2523,5 +2524,28 @@ public class ImportExportApplicationServiceTests {
|
|||
.verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void exportApplicationById_WhenThemeDoesNotExist_ExportedWithDefaultTheme() {
|
||||
Theme customTheme = new Theme();
|
||||
customTheme.setName("my-custom-theme");
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Application testApplication = new Application();
|
||||
testApplication.setName("Application_" + randomId);
|
||||
Mono<ApplicationJson> exportedAppJson = applicationPageService.createApplication(testApplication, orgId)
|
||||
.flatMap(application -> {
|
||||
application.setEditModeThemeId("invalid-theme-id");
|
||||
application.setPublishedModeThemeId("invalid-theme-id");
|
||||
String branchName = null;
|
||||
return applicationService.save(application)
|
||||
.then(importExportApplicationService.exportApplicationById(application.getId(), branchName));
|
||||
});
|
||||
|
||||
StepVerifier.create(exportedAppJson).assertNext(applicationJson -> {
|
||||
assertThat(applicationJson.getEditModeTheme().getName()).isEqualTo(Theme.DEFAULT_THEME_NAME);
|
||||
assertThat(applicationJson.getPublishedTheme().getName()).isEqualTo(Theme.DEFAULT_THEME_NAME);
|
||||
}).verifyComplete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user