From 56acb5c9fd72fd34c9ba98b2271766f8ce3ac330 Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Mon, 13 Jul 2020 23:27:49 +0530 Subject: [PATCH 1/2] New endpoint added to get actions by applicationId in view mode. (#88) * New endpoint added to get actions by applicationId in view mode. Only id, name and jsonPathKeys are returned in view mode. --- .../server/controllers/ActionController.java | 10 ++++++ .../appsmith/server/dtos/ActionViewDTO.java | 16 +++++++++ .../server/services/ActionService.java | 4 +++ .../server/services/ActionServiceImpl.java | 28 ++++++++++++++++ .../server/services/ActionServiceTest.java | 33 +++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionViewDTO.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java index a3baea84aa..fe1edeb87f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java @@ -5,6 +5,7 @@ import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Action; import com.appsmith.server.domains.Layout; import com.appsmith.server.dtos.ActionMoveDTO; +import com.appsmith.server.dtos.ActionViewDTO; import com.appsmith.server.dtos.ExecuteActionDTO; import com.appsmith.server.dtos.RefactorNameDTO; import com.appsmith.server.dtos.ResponseDTO; @@ -14,17 +15,20 @@ import com.appsmith.server.services.LayoutActionService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono; import javax.validation.Valid; +import java.util.List; @RestController @RequestMapping(Url.ACTION_URL) @@ -77,4 +81,10 @@ public class ActionController extends BaseController new ResponseDTO<>(HttpStatus.OK.value(), created, null)); } + + @GetMapping("/view") + public Mono>> getActionsForViewMode(@RequestParam String applicationId) { + return service.getActionsForViewMode(applicationId).collectList() + .map(actions -> new ResponseDTO<>(HttpStatus.OK.value(), actions, null)); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionViewDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionViewDTO.java new file mode 100644 index 0000000000..22b8f13ab2 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionViewDTO.java @@ -0,0 +1,16 @@ +package com.appsmith.server.dtos; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Set; + +@Getter +@Setter +@NoArgsConstructor +public class ActionViewDTO { + String id; + String name; + Set jsonPathKeys; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java index 73efae0719..78b5ed17dc 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java @@ -3,10 +3,12 @@ package com.appsmith.server.services; import com.appsmith.external.models.ActionExecutionResult; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.domains.Action; +import com.appsmith.server.dtos.ActionViewDTO; import com.appsmith.server.dtos.ExecuteActionDTO; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.util.List; import java.util.Map; import java.util.Set; @@ -30,4 +32,6 @@ public interface ActionService extends CrudService { Flux findByPageId(String pageId, AclPermission permission); + Flux getActionsForViewMode(String applicationId); + } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index d0171a6693..1cc73cadf5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -23,6 +23,7 @@ import com.appsmith.server.domains.Page; import com.appsmith.server.domains.Plugin; import com.appsmith.server.domains.PluginType; import com.appsmith.server.domains.User; +import com.appsmith.server.dtos.ActionViewDTO; import com.appsmith.server.dtos.ExecuteActionDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; @@ -515,6 +516,33 @@ public class ActionServiceImpl extends BaseService getActionsForViewMode(String applicationId) { + Sort sort = Sort.by(FieldName.NAME); + if (applicationId == null || applicationId.isEmpty()) { + return Flux.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.APPLICATION_ID)); + } + + return pageService + .findNamesByApplicationId(applicationId) + .switchIfEmpty(Mono.error(new AppsmithException( + AppsmithError.NO_RESOURCE_FOUND, "pages for application", applicationId)) + ) + .map(applicationPagesDTO -> applicationPagesDTO.getPages()) + .flatMapMany(Flux::fromIterable) + .map(pageNameIdDTO -> pageNameIdDTO.getId()) + .collectList() + .flatMapMany(pages -> repository.findAllActionsByNameAndPageIds(null, pages, READ_ACTIONS, sort)) + .map(action -> { + ActionViewDTO actionViewDTO = new ActionViewDTO(); + actionViewDTO.setId(action.getId()); + actionViewDTO.setName(action.getName()); + actionViewDTO.setJsonPathKeys(new HashSet<>()); + actionViewDTO.getJsonPathKeys().addAll(action.getJsonPathKeys()); + return actionViewDTO; + }); + } + @Override public Mono delete(String id) { Mono actionMono = repository.findById(id) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionServiceTest.java index c8039a5254..6aec5f0292 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionServiceTest.java @@ -17,6 +17,7 @@ import com.appsmith.server.domains.Page; import com.appsmith.server.domains.Plugin; import com.appsmith.server.domains.User; import com.appsmith.server.dtos.ActionMoveDTO; +import com.appsmith.server.dtos.ActionViewDTO; import com.appsmith.server.dtos.ExecuteActionDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; @@ -43,8 +44,10 @@ import reactor.test.StepVerifier; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.stream.Stream; import static com.appsmith.server.acl.AclPermission.MANAGE_ACTIONS; import static com.appsmith.server.acl.AclPermission.READ_ACTIONS; @@ -454,6 +457,36 @@ public class ActionServiceTest { .verifyComplete(); } + @Test + @WithUserDetails(value = "api_user") + public void checkActionInViewMode() { + Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(new MockPluginExecutor())); + + String key = "bodyMustacheKey"; + Action action = new Action(); + action.setName("actionInViewMode"); + action.setPageId(testPage.getId()); + ActionConfiguration actionConfiguration = new ActionConfiguration(); + actionConfiguration.setHttpMethod(HttpMethod.GET); + actionConfiguration.setBody("{{"+key+"}}"); + action.setActionConfiguration(actionConfiguration); + action.setDatasource(datasource); + + Mono> actionsListMono = actionService.create(action) + .then(actionService.getActionsForViewMode(testApp.getId()).collectList()); + + StepVerifier + .create(actionsListMono) + .assertNext(actionsList -> { + assertThat(actionsList.size()).isGreaterThan(0); + ActionViewDTO actionViewDTO = actionsList.stream().filter(action1 -> action1.getName().equals(action.getName())).findFirst().get(); + + assertThat(actionViewDTO).isNotNull(); + assertThat(actionViewDTO.getJsonPathKeys()).containsAll(Set.of(key)); + }) + .verifyComplete(); + } + private void executeAndAssertAction(ExecuteActionDTO executeActionDTO, ActionConfiguration actionConfiguration, ActionExecutionResult mockResult) { Mono actionExecutionResultMono = executeAction(executeActionDTO, actionConfiguration, mockResult); From 2c15487d1bbfb669e735f41e169d3841262f24fb Mon Sep 17 00:00:00 2001 From: Manish Date: Mon, 13 Jul 2020 23:29:37 +0530 Subject: [PATCH 2/2] Deployment script now works on Mac OS X (#86) --- deploy/install.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/deploy/install.sh b/deploy/install.sh index 4eca6edcbb..0e11ad43b4 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -52,6 +52,7 @@ declare -A osInfo; osInfo[/etc/debian_version]="apt-get" osInfo[/etc/centos-release]="yum" osInfo[/etc/redhat-release]="yum" +osInfo[/System/Library/CoreServices/SystemVersion.plist]="brew" # Checking OS and assiging package manager desired_os=0 @@ -105,6 +106,8 @@ if [ $setup_domain == "Y" -o $setup_domain == "y" -o $setup_domain == "yes" -o $ echo "Would you like to provision an SSL certificate for your custom domain / subdomain?" read -p '(Your DNS records must be updated for us to provision SSL) [Y/n]: ' setup_ssl setup_ssl=${setup_ssl:-Y} +else + setup_ssl="n" fi if [ $setup_ssl == "Y" -o $setup_ssl == "y" -o $setup_ssl == "yes" -o $setup_ssl == "Yes" ];then @@ -127,11 +130,18 @@ cd .. # Role - Docker if ! is_command_present docker ;then - install_docker + if [ $package_manager == "apt-get" -o $package_manager == "yum" ];then + install_docker + else + echo "Please follow below link to Install Docker Desktop on Mac:" + echo "https://docs.docker.com/docker-for-mac/install/" + fi fi # Starting docker service -start_docker +if [ $package_manager == "yum" -o $package_manager == "apt-get" ];then + start_docker +fi # Role - Folder for directory_name in nginx certbot mongo/db opa/config appsmith-server/config @@ -202,4 +212,4 @@ echo " cd $install_dir && sudo docker-compose ps -a" echo -e "Peace out \U1F596" echo "" echo "Need help troubleshooting?" -echo "Join our discord server https://discord.com/invite/rBTTVJp" \ No newline at end of file +echo "Join our discord server https://discord.com/invite/rBTTVJp"