diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java new file mode 100644 index 000000000000..76b4011c0685 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java @@ -0,0 +1,5 @@ +package com.appsmith.server.helpers; + +import com.appsmith.server.helpers.ce.ActionExecutionSolutionHelperCE; + +public interface ActionExecutionSolutionHelper extends ActionExecutionSolutionHelperCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java new file mode 100644 index 000000000000..b0dcc2884c3a --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java @@ -0,0 +1,8 @@ +package com.appsmith.server.helpers; + +import com.appsmith.server.helpers.ce.ActionExecutionSolutionHelperCEImpl; +import org.springframework.stereotype.Component; + +@Component +public class ActionExecutionSolutionHelperImpl extends ActionExecutionSolutionHelperCEImpl + implements ActionExecutionSolutionHelper {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java new file mode 100644 index 000000000000..6f48c5a8a05e --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java @@ -0,0 +1,8 @@ +package com.appsmith.server.helpers.ce; + +import com.appsmith.external.dtos.ExecuteActionDTO; +import reactor.core.publisher.Mono; + +public interface ActionExecutionSolutionHelperCE { + Mono populateExecuteActionDTOWithSystemInfo(ExecuteActionDTO executeActionDTO); +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java new file mode 100644 index 000000000000..69df9c328280 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java @@ -0,0 +1,13 @@ +package com.appsmith.server.helpers.ce; + +import com.appsmith.external.dtos.ExecuteActionDTO; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@Component +public class ActionExecutionSolutionHelperCEImpl implements ActionExecutionSolutionHelperCE { + @Override + public Mono populateExecuteActionDTOWithSystemInfo(ExecuteActionDTO executeActionDTO) { + return Mono.just(executeActionDTO); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java index de3ae719512c..1412bd1b6e70 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java @@ -4,6 +4,7 @@ import com.appsmith.server.configurations.CommonConfig; import com.appsmith.server.datasources.base.DatasourceService; import com.appsmith.server.datasourcestorages.base.DatasourceStorageService; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; @@ -40,7 +41,8 @@ public ActionExecutionSolutionImpl( EnvironmentPermission environmentPermission, ConfigService configService, TenantService tenantService, - CommonConfig commonConfig) { + CommonConfig commonConfig, + ActionExecutionSolutionHelper actionExecutionSolutionHelper) { super( newActionService, actionPermission, @@ -60,6 +62,7 @@ public ActionExecutionSolutionImpl( environmentPermission, configService, tenantService, - commonConfig); + commonConfig, + actionExecutionSolutionHelper); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java index fa8172f2fd04..c8db695056cf 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java @@ -34,6 +34,7 @@ import com.appsmith.server.dtos.ExecuteActionMetaDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.DatasourceAnalyticsUtils; import com.appsmith.server.helpers.DateUtils; import com.appsmith.server.helpers.PluginExecutorHelper; @@ -119,6 +120,7 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE private final EnvironmentPermission environmentPermission; private final ConfigService configService; private final TenantService tenantService; + private final ActionExecutionSolutionHelper actionExecutionSolutionHelper; private final CommonConfig commonConfig; static final String PARAM_KEY_REGEX = "^k\\d+$"; @@ -147,7 +149,8 @@ public ActionExecutionSolutionCEImpl( EnvironmentPermission environmentPermission, ConfigService configService, TenantService tenantService, - CommonConfig commonConfig) { + CommonConfig commonConfig, + ActionExecutionSolutionHelper actionExecutionSolutionHelper) { this.newActionService = newActionService; this.actionPermission = actionPermission; this.observationRegistry = observationRegistry; @@ -167,6 +170,7 @@ public ActionExecutionSolutionCEImpl( this.configService = configService; this.tenantService = tenantService; this.commonConfig = commonConfig; + this.actionExecutionSolutionHelper = actionExecutionSolutionHelper; this.patternList.add(Pattern.compile(PARAM_KEY_REGEX)); this.patternList.add(Pattern.compile(BLOB_KEY_REGEX)); @@ -245,15 +249,29 @@ private Mono populateExecuteActionDTO(ExecuteActionDTO execute Mono instanceIdMono = configService.getInstanceId(); Mono defaultTenantIdMono = tenantService.getDefaultTenantId(); - return Mono.zip(instanceIdMono, defaultTenantIdMono).map(tuple -> { - String instanceId = tuple.getT1(); - String tenantId = tuple.getT2(); - executeActionDTO.setActionId(newAction.getId()); - executeActionDTO.setWorkspaceId(newAction.getWorkspaceId()); - executeActionDTO.setInstanceId(instanceId); - executeActionDTO.setTenantId(tenantId); - return executeActionDTO; - }); + Mono systemInfoPopulatedExecuteActionDTOMono = + actionExecutionSolutionHelper.populateExecuteActionDTOWithSystemInfo(executeActionDTO); + + return systemInfoPopulatedExecuteActionDTOMono.flatMap( + populatedExecuteActionDTO -> Mono.zip(instanceIdMono, defaultTenantIdMono) + .map(tuple -> { + String instanceId = tuple.getT1(); + String tenantId = tuple.getT2(); + populatedExecuteActionDTO.setActionId(newAction.getId()); + populatedExecuteActionDTO.setWorkspaceId(newAction.getWorkspaceId()); + populatedExecuteActionDTO.setInstanceId(instanceId); + populatedExecuteActionDTO.setTenantId(tenantId); + return populatedExecuteActionDTO; + })); + } + + /** + * Populates the requestParams with logged in userId. + * If the user is not logged in, set the parameter as anonymousUserId + * + */ + protected Mono populateExecuteActionDTOWithUserId(ExecuteActionDTO executeActionDTO) { + return Mono.just(executeActionDTO); } /** diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java index 9aac576ae4bd..c6c1eb95610a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java @@ -15,6 +15,7 @@ import com.appsmith.server.domains.NewAction; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; @@ -132,6 +133,9 @@ class ActionExecutionSolutionCEImplTest { @SpyBean CommonConfig commonConfig; + @SpyBean + ActionExecutionSolutionHelper actionExecutionSolutionHelper; + @Autowired EnvironmentPermission environmentPermission; @@ -162,7 +166,8 @@ public void beforeEach() { environmentPermission, configService, tenantService, - commonConfig); + commonConfig, + actionExecutionSolutionHelper); ObservationRegistry.ObservationConfig mockObservationConfig = Mockito.mock(ObservationRegistry.ObservationConfig.class);