From e59ec2a8a94c50b0afc3f00b3cf8eb292d6e0144 Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Thu, 27 Aug 2020 15:29:57 +0530 Subject: [PATCH] Use a new API to set (unset) execute on load for an action. (#443) --- .../com/appsmith/server/constants/FieldName.java | 1 + .../server/controllers/ActionController.java | 7 +++++++ .../java/com/appsmith/server/domains/Action.java | 4 ++++ .../appsmith/server/services/ActionService.java | 2 ++ .../server/services/ActionServiceImpl.java | 14 +++++++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java index ea50cca00c..2cd1231f31 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java @@ -52,4 +52,5 @@ public class FieldName { "}"; public static String ANONYMOUS_USER = "anonymousUser"; public static String USERNAMES = "usernames"; + public static String ACTION = "action"; } 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 79b6578b54..d9e6b7ccaf 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 @@ -89,4 +89,11 @@ public class ActionController extends BaseController new ResponseDTO<>(HttpStatus.OK.value(), actions, null)); } + + @PutMapping("/executeOnLoad/{id}") + public Mono> setExecuteOnLoad(@PathVariable String id, @RequestParam Boolean flag) { + log.debug("Going to set execute on load for action id {} to {}", id, flag); + return service.setExecuteOnLoad(id, flag) + .map(action -> new ResponseDTO<>(HttpStatus.OK.value(), action, null)); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java index 5f0aa950bd..788aa25f07 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java @@ -3,6 +3,7 @@ package com.appsmith.server.domains; import com.appsmith.external.models.ActionConfiguration; import com.appsmith.external.models.BaseDomain; import com.appsmith.external.models.Property; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import lombok.NoArgsConstructor; @@ -67,6 +68,9 @@ public class Action extends BaseDomain { @Transient String pluginId; + @JsonIgnore + Boolean userSetOnLoad = false; + Documentation documentation; /** 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 4300aad505..cb5b971833 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 @@ -33,4 +33,6 @@ public interface ActionService extends CrudService { Flux getActionsForViewMode(String applicationId); + Mono setExecuteOnLoad(String id, Boolean isExecuteOnLoad); + } 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 a71ba20197..98e7aeda1c 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 @@ -60,6 +60,7 @@ import java.util.stream.Collectors; import static com.appsmith.server.acl.AclPermission.EXECUTE_ACTIONS; import static com.appsmith.server.acl.AclPermission.EXECUTE_DATASOURCES; +import static com.appsmith.server.acl.AclPermission.MANAGE_ACTIONS; import static com.appsmith.server.acl.AclPermission.MANAGE_DATASOURCES; import static com.appsmith.server.acl.AclPermission.MANAGE_PAGES; import static com.appsmith.server.acl.AclPermission.READ_ACTIONS; @@ -584,10 +585,21 @@ public class ActionServiceImpl extends BaseService setExecuteOnLoad(String id, Boolean isExecuteOnLoad) { + return repository.findById(id, MANAGE_ACTIONS) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id))) + .flatMap(action -> { + action.setUserSetOnLoad(true); + action.setExecuteOnLoad(isExecuteOnLoad); + return repository.save(action); + }); + } + @Override public Mono delete(String id) { Mono actionMono = repository.findById(id) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "action", id))); + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id))); return actionMono .flatMap(toDelete -> repository.delete(toDelete).thenReturn(toDelete)) .flatMap(analyticsService::sendDeleteEvent);