chore: Added check for non-existent storage while importing and exporting (#25729)

This commit is contained in:
Nidhi 2023-07-26 15:35:27 +05:30 committed by GitHub
parent dd9dd5c9a2
commit 2878e1381d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -515,8 +515,7 @@ public class ApplicationServiceCEImpl extends BaseService<ApplicationRepository,
// Update the datasource policies without permission since the applications and datasources are at
// the same level in the hierarchy. A user may have permission to change view on application, but
// may
// not have explicit permissions on the datasource.
// may not have explicit permissions on the datasource.
Mono<Void> updatedDatasourcesMono1 = policySolution
.updateWithNewPoliciesToDatasourcesByDatasourceIdsWithoutPermission(
datasourceIds, datasourcePolicyMap, addViewAccess)

View File

@ -310,6 +310,12 @@ public class DatasourceStorageServiceCEImpl implements DatasourceStorageServiceC
}
DatasourceStorageDTO datasourceStorageDTO =
this.getDatasourceStorageDTOFromDatasource(datasource, environmentId);
if (datasourceStorageDTO == null) {
// If this environment does not have a storage configured, return null
return null;
}
DatasourceStorage datasourceStorage = new DatasourceStorage(datasourceStorageDTO);
datasourceStorage.prepareTransientFields(datasource);

View File

@ -396,8 +396,22 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
datasourceList.forEach(datasource ->
datasourceIdToNameMap.put(datasource.getId(), datasource.getName()));
List<DatasourceStorage> storageList = datasourceList.stream()
.map(datasource -> datasourceStorageService.getDatasourceStorageFromDatasource(
datasource, environmentId))
.map(datasource -> {
DatasourceStorage storage =
datasourceStorageService.getDatasourceStorageFromDatasource(
datasource, environmentId);
if (storage == null) {
// This means we were unable to find a storage for default environment
// We still need the user to be able to configure this datasource in a
// new workspace,
// So we will create a fallback storage using transient fields from the
// datasource
storage = new DatasourceStorage();
storage.prepareTransientFields(datasource);
}
return storage;
})
.collect(Collectors.toList());
applicationJson.setDatasourceList(storageList);
@ -2073,6 +2087,11 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
Boolean isUnConfiguredDatasource = datasources.stream().anyMatch(datasource -> {
DatasourceStorageDTO datasourceStorageDTO =
datasource.getDatasourceStorages().get(environmentId);
if (datasourceStorageDTO == null) {
// If this environment has not been configured,
// We do not expect to find a storage, user will have to reconfigure
return Boolean.FALSE;
}
return Boolean.FALSE.equals(datasourceStorageDTO.getIsConfigured());
});
if (Boolean.TRUE.equals(isUnConfiguredDatasource)) {

View File

@ -120,6 +120,7 @@ import static com.appsmith.server.constants.FieldName.DEFAULT_PAGE_LAYOUT;
import static com.appsmith.server.dtos.CustomJSLibApplicationDTO.getDTOFromCustomJSLib;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@Slf4j
@ExtendWith(SpringExtension.class)
@ -2559,6 +2560,7 @@ public class ImportExportApplicationServiceTests {
DEFAULT_PAGE_LAYOUT, new TypeReference<HashMap<String, Object>>() {}));
} catch (JsonProcessingException e) {
e.printStackTrace();
fail();
}
ArrayList children = (ArrayList) dsl.get("children");