From 713ed766762fd44f399df0c2567b3e3695346435 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Thu, 30 Sep 2021 19:04:33 +0530 Subject: [PATCH] Fixed check for missing action collections (#8006) --- .../ImportExportApplicationService.java | 6 +- .../ImportExportApplicationServiceTests.java | 85 +++ ...application-without-action-collection.json | 555 ++++++++++++++++++ 3 files changed, 643 insertions(+), 3 deletions(-) create mode 100644 app/server/appsmith-server/src/test/resources/test_assets/ImportExportServiceTest/valid-application-without-action-collection.json diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationService.java index 0017185f86..25b7f84777 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationService.java @@ -418,8 +418,6 @@ public class ImportExportApplicationService { errorField = FieldName.ACTIONS; } else if (importedDatasourceList == null) { errorField = FieldName.DATASOURCE; - } else if (importedActionCollectionList == null) { - errorField = FieldName.ACTION_COLLECTION; } if (!errorField.isEmpty()) { @@ -676,7 +674,9 @@ public class ImportExportApplicationService { .collectList()); }) .flatMap(existingActionCollections -> { - assert importedActionCollectionList != null; + if (importedActionCollectionList == null) { + return Mono.just(true); + } return Flux.fromIterable(importedActionCollectionList) .flatMap(actionCollection -> { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java index 0e13a5a631..742f14b17d 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java @@ -706,6 +706,91 @@ public class ImportExportApplicationServiceTests { .verifyComplete(); } + @Test + @WithUserDetails(value = "api_user") + public void importApplication_withoutActionCollection_succeedsWithoutError() { + + FilePart filePart = createFilePart("test_assets/ImportExportServiceTest/valid-application-without-action-collection.json"); + + Organization newOrganization = new Organization(); + newOrganization.setName("Template Organization"); + + Policy manageAppPolicy = Policy.builder().permission(MANAGE_APPLICATIONS.getValue()) + .users(Set.of("api_user")) + .build(); + Policy readAppPolicy = Policy.builder().permission(READ_APPLICATIONS.getValue()) + .users(Set.of("api_user")) + .build(); + + final Mono resultMono = organizationService + .create(newOrganization) + .flatMap(organization -> importExportApplicationService + .extractFileAndSaveApplication(organization.getId(), filePart) + ); + + StepVerifier + .create(resultMono + .flatMap(application -> Mono.zip( + Mono.just(application), + datasourceService.findAllByOrganizationId(application.getOrganizationId(), MANAGE_DATASOURCES).collectList(), + getActionsInApplication(application).collectList(), + newPageService.findByApplicationId(application.getId(), MANAGE_PAGES, false).collectList(), + actionCollectionService.findAllByApplicationIdAndViewMode(application.getId(), false, MANAGE_ACTIONS, null).collectList() + ))) + .assertNext(tuple -> { + final Application application = tuple.getT1(); + final List datasourceList = tuple.getT2(); + final List actionDTOS = tuple.getT3(); + final List pageList = tuple.getT4(); + final List actionCollectionList = tuple.getT5(); + + assertThat(application.getName()).isEqualTo("valid_application"); + assertThat(application.getOrganizationId()).isNotNull(); + assertThat(application.getPages()).hasSize(2); + assertThat(application.getPolicies()).containsAll(Set.of(manageAppPolicy, readAppPolicy)); + assertThat(application.getPublishedPages()).hasSize(1); + assertThat(application.getModifiedBy()).isEqualTo("api_user"); + assertThat(application.getUpdatedAt()).isNotNull(); + + assertThat(datasourceList).isNotEmpty(); + datasourceList.forEach(datasource -> { + assertThat(datasource.getOrganizationId()).isEqualTo(application.getOrganizationId()); + if (datasource.getName().contains("wo-auth")) { + assertThat(datasource.getDatasourceConfiguration().getAuthentication()).isNull(); + } else if (datasource.getName().contains("db")) { + DBAuth auth = (DBAuth) datasource.getDatasourceConfiguration().getAuthentication(); + assertThat(auth).isNotNull(); + assertThat(auth.getPassword()).isNotNull(); + assertThat(auth.getUsername()).isNotNull(); + } + }); + + assertThat(actionDTOS).isNotEmpty(); + actionDTOS.forEach(actionDTO -> { + assertThat(actionDTO.getPageId()).isNotEqualTo(pageList.get(0).getName()); + + }); + + assertThat(actionCollectionList).isEmpty(); + + assertThat(pageList).hasSize(2); + + ApplicationPage defaultAppPage = application.getPages() + .stream() + .filter(ApplicationPage::getIsDefault) + .findFirst() + .orElse(null); + assertThat(defaultAppPage).isNotNull(); + + PageDTO defaultPageDTO = pageList.stream() + .filter(pageDTO -> pageDTO.getId().equals(defaultAppPage.getId())).findFirst().orElse(null); + + assertThat(defaultPageDTO).isNotNull(); + assertThat(defaultPageDTO.getLayouts().get(0).getLayoutOnLoadActions()).isNotEmpty(); + }) + .verifyComplete(); + } + private FilePart createFilePart(String filePath) { FilePart filepart = Mockito.mock(FilePart.class, Mockito.RETURNS_DEEP_STUBS); Flux dataBufferFlux = DataBufferUtils diff --git a/app/server/appsmith-server/src/test/resources/test_assets/ImportExportServiceTest/valid-application-without-action-collection.json b/app/server/appsmith-server/src/test/resources/test_assets/ImportExportServiceTest/valid-application-without-action-collection.json new file mode 100644 index 0000000000..86f401aec7 --- /dev/null +++ b/app/server/appsmith-server/src/test/resources/test_assets/ImportExportServiceTest/valid-application-without-action-collection.json @@ -0,0 +1,555 @@ +{ + "exportedApplication": { + "userPermissions": [ + "canComment:applications", + "manage:applications", + "read:applications", + "publish:applications", + "makePublic:applications" + ], + "name": "valid_application", + "isPublic": false, + "appIsExample": false, + "color": "#EA6179", + "icon": "medical", + "new": true + }, + "datasourceList": [ + { + "userPermissions": [ + "execute:datasources", + "manage:datasources", + "read:datasources" + ], + "name": "db-auth", + "pluginId": "mongo-plugin", + "gitSyncId": "datasource1_git", + "datasourceConfiguration": { + "connection": { + "mode": "READ_WRITE", + "type": "REPLICA_SET", + "ssl": { + "authType": "DEFAULT" + } + }, + "endpoints": [ + { + "host": "db-auth-uri.net" + } + ], + "sshProxyEnabled": false, + "properties": [ + { + "key": "Use Mongo Connection String URI", + "value": "No" + } + ] + }, + "invalids": [], + "isValid": true, + "new": true + }, + { + "userPermissions": [ + "execute:datasources", + "manage:datasources", + "read:datasources" + ], + "name": "api_ds_wo_auth", + "pluginId": "restapi-plugin", + "gitSyncId": "datasource2_git", + "datasourceConfiguration": { + "sshProxyEnabled": false, + "properties": [ + { + "key": "isSendSessionEnabled", + "value": "N" + }, + { + "key": "sessionSignatureKey", + "value": "" + } + ], + "url": "https://api-ds-wo-auth-uri.com", + "headers": [] + }, + "invalids": [], + "isValid": true, + "new": true + } + ], + "pageList": [ + { + "userPermissions": [ + "read:pages", + "manage:pages" + ], + "gitSyncId": "page1_git", + "applicationId": "valid_application", + "unpublishedPage": { + "name": "Page1", + "layouts": [ + { + "id": "60aca056136c4b7178f67906", + "userPermissions": [], + "dsl": { + "widgetName": "MainContainer", + "backgroundColor": "none", + "rightColumn": 1280, + "snapColumns": 16, + "detachFromLayout": true, + "widgetId": "0", + "topRow": 0, + "bottomRow": 800, + "containerStyle": "none", + "snapRows": 33, + "parentRowSpace": 1, + "type": "CANVAS_WIDGET", + "canExtend": true, + "version": 4, + "minHeight": 840, + "parentColumnSpace": 1, + "dynamicTriggerPathList": [], + "dynamicBindingPathList": [], + "leftColumn": 0, + "children": [ + { + "widgetName": "Table1", + "columnOrder": [ + "_id", + "username", + "active" + ], + "dynamicPropertyPathList": [], + "topRow": 4, + "bottomRow": 15, + "parentRowSpace": 40, + "type": "TABLE_WIDGET", + "parentColumnSpace": 77.5, + "dynamicTriggerPathList": [], + "dynamicBindingPathList": [ + { + "key": "tableData" + }, + { + "key": "primaryColumns._id.computedValue" + }, + { + "key": "primaryColumns.username.computedValue" + }, + { + "key": "primaryColumns.active.computedValue" + } + ], + "leftColumn": 0, + "primaryColumns": { + "appsmith_mongo_escape_id": { + "isDerived": false, + "computedValue": "{{Table1.sanitizedTableData.map((currentRow) => ( currentRow._id ))}}", + "textSize": "PARAGRAPH", + "index": 4, + "isVisible": true, + "label": "_id", + "columnType": "text", + "horizontalAlignment": "LEFT", + "width": 150, + "enableFilter": true, + "enableSort": true, + "id": "_id", + "verticalAlignment": "CENTER" + }, + "active": { + "isDerived": false, + "computedValue": "{{Table1.sanitizedTableData.map((currentRow) => ( currentRow.active ))}}", + "textSize": "PARAGRAPH", + "index": 8, + "isVisible": true, + "label": "active", + "columnType": "text", + "horizontalAlignment": "LEFT", + "width": 150, + "enableFilter": true, + "enableSort": true, + "id": "active", + "verticalAlignment": "CENTER" + }, + "username": { + "isDerived": false, + "computedValue": "{{Table1.sanitizedTableData.map((currentRow) => ( currentRow.username ))}}", + "textSize": "PARAGRAPH", + "index": 7, + "isVisible": true, + "label": "username", + "columnType": "text", + "horizontalAlignment": "LEFT", + "width": 150, + "enableFilter": true, + "enableSort": true, + "id": "username", + "verticalAlignment": "CENTER" + } + }, + "derivedColumns": {}, + "rightColumn": 8, + "textSize": "PARAGRAPH", + "widgetId": "aisibaxwhb", + "tableData": "{{get_users.data}}", + "isVisible": true, + "label": "Data", + "searchKey": "", + "version": 1, + "parentId": "0", + "isLoading": false, + "horizontalAlignment": "LEFT", + "verticalAlignment": "CENTER", + "columnSizeMap": { + "task": 245, + "step": 62, + "status": 75 + } + }, + { + "widgetName": "Form1", + "backgroundColor": "white", + "rightColumn": 16, + "widgetId": "ut3l54pzqw", + "topRow": 4, + "bottomRow": 11, + "parentRowSpace": 40, + "isVisible": true, + "type": "FORM_WIDGET", + "parentId": "0", + "isLoading": false, + "parentColumnSpace": 77.5, + "leftColumn": 9, + "children": [ + { + "widgetName": "Canvas1", + "rightColumn": 542.5, + "detachFromLayout": true, + "widgetId": "mcsltg1l0j", + "containerStyle": "none", + "topRow": 0, + "bottomRow": 320, + "parentRowSpace": 1, + "isVisible": true, + "canExtend": false, + "type": "CANVAS_WIDGET", + "version": 1, + "parentId": "ut3l54pzqw", + "minHeight": 520, + "isLoading": false, + "parentColumnSpace": 1, + "leftColumn": 0, + "children": [ + { + "widgetName": "Text1", + "rightColumn": 6, + "textAlign": "LEFT", + "widgetId": "7b4x786lxp", + "topRow": 0, + "bottomRow": 1, + "isVisible": true, + "fontStyle": "BOLD", + "type": "TEXT_WIDGET", + "textColor": "#231F20", + "version": 1, + "parentId": "mcsltg1l0j", + "isLoading": false, + "leftColumn": 0, + "fontSize": "HEADING1", + "text": "Form" + }, + { + "widgetName": "Text2", + "rightColumn": 16, + "textAlign": "LEFT", + "widgetId": "d0axuxiosp", + "topRow": 3, + "bottomRow": 6, + "parentRowSpace": 40, + "isVisible": true, + "fontStyle": "BOLD", + "type": "TEXT_WIDGET", + "textColor": "#231F20", + "version": 1, + "parentId": "mcsltg1l0j", + "isLoading": false, + "parentColumnSpace": 31.40625, + "dynamicTriggerPathList": [], + "leftColumn": 0, + "dynamicBindingPathList": [ + { + "key": "text" + } + ], + "fontSize": "PARAGRAPH2", + "text": "{{api_wo_auth.data.body}}" + }, + { + "widgetName": "Text3", + "rightColumn": 4, + "textAlign": "LEFT", + "widgetId": "lmfer0622c", + "topRow": 2, + "bottomRow": 3, + "parentRowSpace": 40, + "isVisible": true, + "fontStyle": "BOLD", + "type": "TEXT_WIDGET", + "textColor": "#231F20", + "version": 1, + "parentId": "mcsltg1l0j", + "isLoading": false, + "parentColumnSpace": 31.40625, + "dynamicTriggerPathList": [], + "leftColumn": 0, + "dynamicBindingPathList": [ + { + "key": "text" + } + ], + "fontSize": "PARAGRAPH", + "text": "{{api_wo_auth.data.id}}" + } + ] + } + ] + } + ] + }, + "layoutOnLoadActions": [ + [ + { + "id": "60aca24c136c4b7178f6790d", + "name": "api_wo_auth", + "pluginType": "API", + "jsonPathKeys": [], + "timeoutInMillisecond": 10000 + }, + { + "id": "60aca092136c4b7178f6790a", + "name": "get_users", + "pluginType": "DB", + "jsonPathKeys": [], + "timeoutInMillisecond": 10000 + } + ] + ], + "new": false + } + ], + "userPermissions": [] + }, + "publishedPage": { + "name": "Page1", + "layouts": [ + { + "id": "60aca056136c4b7178f67906", + "userPermissions": [], + "dsl": { + "widgetName": "MainContainer", + "backgroundColor": "none", + "rightColumn": 1224, + "snapColumns": 16, + "detachFromLayout": true, + "widgetId": "0", + "topRow": 0, + "bottomRow": 1254, + "containerStyle": "none", + "snapRows": 33, + "parentRowSpace": 1, + "type": "CANVAS_WIDGET", + "canExtend": true, + "version": 4, + "minHeight": 1292, + "parentColumnSpace": 1, + "dynamicBindingPathList": [], + "leftColumn": 0, + "children": [] + }, + "new": false + } + ], + "userPermissions": [] + }, + "new": true + }, + { + "userPermissions": [ + "read:pages", + "manage:pages" + ], + "gitSyncId": "page2_git", + "applicationId": "valid_application", + "unpublishedPage": { + "name": "Page2", + "layouts": [ + { + "id": "60aca056136c4b7178f67999", + "userPermissions": [], + "dsl": { + "widgetName": "MainContainer", + "backgroundColor": "none", + "rightColumn": 1280, + "snapColumns": 16, + "detachFromLayout": true, + "widgetId": "0", + "topRow": 0, + "bottomRow": 800, + "containerStyle": "none", + "snapRows": 33, + "parentRowSpace": 1, + "type": "CANVAS_WIDGET", + "canExtend": true, + "version": 4, + "minHeight": 840, + "parentColumnSpace": 1, + "dynamicTriggerPathList": [], + "dynamicBindingPathList": [], + "leftColumn": 0, + "children": [] + }, + "layoutOnLoadActions": [ + [] + ], + "new": false + } + ], + "userPermissions": [] + }, + "new": true + } + ], + "actionList": [ + { + "id": "60aca092136c4b7178f6790a", + "userPermissions": [], + "applicationId": "valid_application", + "pluginType": "DB", + "pluginId": "mongo-plugin", + "gitSyncId": "action1_git", + "unpublishedAction": { + "name": "get_users", + "datasource": { + "id": "db-auth", + "userPermissions": [], + "isValid": true, + "new": false + }, + "pageId": "Page1", + "actionConfiguration": { + "timeoutInMillisecond": 10000, + "paginationType": "NONE", + "encodeParamsToggle": true, + "body": "{\n \"find\": \"users\",\n \"sort\": {\n \"id\": 1\n },\n \"limit\": 10\n}", + "pluginSpecifiedTemplates": [ + { + "value": false + } + ] + }, + "executeOnLoad": true, + "dynamicBindingPathList": [], + "isValid": true, + "invalids": [], + "jsonPathKeys": [], + "confirmBeforeExecute": false, + "userPermissions": [] + }, + "publishedAction": { + "datasource": { + "userPermissions": [], + "isValid": true, + "new": true + }, + "confirmBeforeExecute": false, + "userPermissions": [] + }, + "new": false + }, + { + "id": "60aca24c136c4b7178f6790d", + "userPermissions": [], + "applicationId": "valid_application", + "pluginType": "API", + "pluginId": "restapi-plugin", + "gitSyncId": "action2_git", + "unpublishedAction": { + "name": "api_wo_auth", + "datasource": { + "id": "api_ds_wo_auth", + "userPermissions": [], + "isValid": true, + "new": false + }, + "pageId": "Page1", + "actionConfiguration": { + "timeoutInMillisecond": 10000, + "paginationType": "NONE", + "path": "/params", + "headers": [ + { + "key": "", + "value": "" + }, + { + "key": "", + "value": "" + } + ], + "encodeParamsToggle": true, + "queryParameters": [], + "body": "", + "httpMethod": "GET", + "pluginSpecifiedTemplates": [ + { + "value": false + } + ] + }, + "executeOnLoad": true, + "dynamicBindingPathList": [], + "isValid": true, + "invalids": [], + "jsonPathKeys": [], + "confirmBeforeExecute": false, + "userPermissions": [] + }, + "publishedAction": { + "datasource": { + "userPermissions": [], + "isValid": true, + "new": true + }, + "confirmBeforeExecute": false, + "userPermissions": [] + }, + "new": false + } + ], + "decryptedFields": { + "db-auth": { + "password": "CreativePassword", + "authType": "com.appsmith.external.models.DBAuth", + "dbAuth": { + "authenticationType": "dbAuth", + "authType": "SCRAM_SHA_1", + "username": "CreativeUser", + "databaseName": "db-name" + } + } + }, + "publishedDefaultPageName": "Page1", + "unpublishedDefaultPageName": "Page1", + "publishedLayoutmongoEscapedWidgets": { + "60aca056136c4b7178f67906": [ + "Table1" + ] + }, + "unpublishedLayoutmongoEscapedWidgets": { + "60aca056136c4b7178f67906": [ + "Table1" + ] + } +} \ No newline at end of file