diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationPageServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationPageServiceImpl.java index b647f2edfa..4e2d6b808e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationPageServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationPageServiceImpl.java @@ -240,7 +240,12 @@ public class ApplicationPageServiceImpl implements ApplicationPageService { Mono applicationWithPoliciesMono = setApplicationPolicies(userMono, orgId, application); return applicationWithPoliciesMono - .flatMap(applicationService::createDefault) + .zipWith(userMono) + .flatMap(tuple -> { + Application application1 = tuple.getT1(); + application1.setModifiedBy(tuple.getT2().getUsername()); // setting modified by to current user + return applicationService.createDefault(application1); + }) .flatMap(savedApplication -> { PageDTO page = new PageDTO(); @@ -464,7 +469,12 @@ public class ApplicationPageServiceImpl implements ApplicationPageService { // First set the correct policies for the new cloned application return setApplicationPolicies(userMono, sourceApplication.getOrganizationId(), newApplication) // Create the cloned application with the new name and policies before proceeding further. - .flatMap(applicationService::createDefault) + .zipWith(userMono) + .flatMap(applicationUserTuple2 -> { + Application application1 = applicationUserTuple2.getT1(); + application1.setModifiedBy(applicationUserTuple2.getT2().getUsername()); // setting modified by to current user + return applicationService.createDefault(application1); + }) // Now fetch the pages of the source application, clone and add them to this new application .flatMap(savedApplication -> Flux.fromIterable(sourceApplication.getPages()) .flatMap(applicationPage -> { 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 467c8ae12b..c1211c4c1e 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 @@ -364,7 +364,7 @@ public class ImportExportApplicationService { List importedNewPageList = importedDoc.getPageList(); List importedNewActionList = importedDoc.getActionList(); - Mono currUserMono = sessionUserService.getCurrentUser(); + Mono currUserMono = sessionUserService.getCurrentUser().cache(); final Flux existingDatasourceFlux = datasourceRepository .findAllByOrganizationId(organizationId, AclPermission.MANAGE_DATASOURCES) .cache(); @@ -450,6 +450,12 @@ public class ImportExportApplicationService { // 2. Check for possible duplicate names, // 3. Save the updated application applicationPageService.setApplicationPolicies(currUserMono, organizationId, importedApplication) + .zipWith(currUserMono) + .map(objects -> { + Application application = objects.getT1(); + application.setModifiedBy(objects.getT2().getUsername()); + return application; + }) .flatMap(application -> { if (applicationId != null) { return applicationService.findById(applicationId, AclPermission.MANAGE_APPLICATIONS) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java index c823c26977..9cf90502d7 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java @@ -166,6 +166,8 @@ public class ApplicationServiceTest { assertThat(application.getPolicies()).isNotEmpty(); assertThat(application.getPolicies()).containsAll(Set.of(manageAppPolicy, readAppPolicy)); assertThat(application.getOrganizationId().equals(orgId)); + assertThat(application.getModifiedBy()).isEqualTo("api_user"); + assertThat(application.getUpdatedAt()).isNotNull(); }) .verifyComplete(); } @@ -625,7 +627,7 @@ public class ApplicationServiceTest { @Test @WithUserDetails(value = "api_user") - public void createCloneApplication() { + public void cloneApplicationTest() { Application testApplication = new Application(); testApplication.setName("ApplicationServiceTest Clone Source TestApp"); @@ -658,7 +660,7 @@ public class ApplicationServiceTest { StepVerifier .create(Mono.zip(applicationMono, pageListMono)) .assertNext(tuple -> { - Application application = tuple.getT1(); + Application application = tuple.getT1(); // cloned application List pageList = tuple.getT2(); assertThat(application).isNotNull(); assertThat(application.isAppIsExample()).isFalse(); @@ -666,6 +668,8 @@ public class ApplicationServiceTest { assertThat(application.getName().equals("ApplicationServiceTest Clone Source TestApp Copy")); assertThat(application.getPolicies()).containsAll(Set.of(manageAppPolicy, readAppPolicy)); assertThat(application.getOrganizationId().equals(orgId)); + assertThat(application.getModifiedBy()).isEqualTo("api_user"); + assertThat(application.getUpdatedAt()).isNotNull(); List pages = application.getPages(); Set pageIdsFromApplication = pages.stream().map(page -> page.getId()).collect(Collectors.toSet()); Set pageIdsFromDb = pageList.stream().map(page -> page.getId()).collect(Collectors.toSet()); 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 5442c561b7..7979156b4d 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 @@ -608,6 +608,8 @@ public class ImportExportApplicationServiceTests { 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 -> {