diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java index 7cf487081c..af52100b94 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.Sort; import org.springframework.util.MultiValueMap; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; import java.util.List; import java.util.Map; @@ -42,6 +43,9 @@ public interface NewActionServiceCE extends CrudService { Mono updateUnpublishedAction(String id, ActionDTO action); + Mono> updateUnpublishedActionWithoutAnalytics( + String id, ActionDTO action, Optional permission); + Mono findByUnpublishedNameAndPageId(String name, String pageId, AclPermission permission); Mono findActionDTObyIdAndViewMode(String id, Boolean viewMode, AclPermission permission); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index b56531662f..053baf8d8f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -113,7 +113,7 @@ public class NewActionServiceCEImpl extends BaseService updateUnpublishedAction(String id, ActionDTO action) { - if (id == null) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID)); - } - - // The client does not know about this field. Hence the default value takes over. Set this to null to ensure - // the update doesn't lead to resetting of this field. - action.setUserSetOnLoad(null); - - Mono updatedActionMono = repository - .findById(id, actionPermission.getEditPermission()) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id))) - .map(dbAction -> { - final ActionDTO unpublishedAction = dbAction.getUnpublishedAction(); - copyNewFieldValuesIntoOldObject(action, unpublishedAction); - return dbAction; - }) - .flatMap(this::extractAndSetNativeQueryFromFormData) - .cache(); - - return updatedActionMono - .flatMap(savedNewAction -> - this.validateAndSaveActionToRepository(savedNewAction).zipWith(Mono.just(savedNewAction))) + return updateUnpublishedActionWithoutAnalytics(id, action, Optional.of(actionPermission.getEditPermission())) .zipWith(Mono.defer(() -> { if (action.getDatasource() != null && action.getDatasource().getId() != null) { return datasourceService.findById(action.getDatasource().getId()); @@ -603,6 +582,47 @@ public class NewActionServiceCEImpl extends BaseService> updateUnpublishedActionWithoutAnalytics( + String id, ActionDTO action, Optional permission) { + if (id == null) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID)); + } + + // The client does not know about this field. Hence, the default value takes over. Set this to null to ensure + // the update doesn't lead to resetting of this field. + action.setUserSetOnLoad(null); + + Mono updatedActionMono = repository + .findById(id, permission) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id))) + .map(dbAction -> { + final ActionDTO unpublishedAction = dbAction.getUnpublishedAction(); + copyNewFieldValuesIntoOldObject(action, unpublishedAction); + return dbAction; + }) + .flatMap(this::extractAndSetNativeQueryFromFormData) + .cache(); + + return updatedActionMono.flatMap(savedNewAction -> + this.validateAndSaveActionToRepository(savedNewAction).zipWith(Mono.just(savedNewAction))); + } + private Mono extractAndSetNativeQueryFromFormData(NewAction action) { Mono pluginMono = pluginService.getById(action.getPluginId()); Mono pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginMono);