From b44f555a7f66e0d128742d5b1a532603c4fce514 Mon Sep 17 00:00:00 2001 From: Nayan Date: Thu, 11 Nov 2021 17:30:57 +0600 Subject: [PATCH] fix: application edit date is updated when an user is added or removed from org (#8984) Last edit time of an application was updated when a new user is added or existing user is removed from the corresponding organization. --- .../appsmith/server/domains/Application.java | 17 ++++++++++-- .../services/ApplicationPageServiceImpl.java | 9 +++++-- .../services/ApplicationServiceImpl.java | 3 +++ .../ImportExportApplicationService.java | 2 ++ .../services/ApplicationPageServiceTest.java | 26 +++++++++++++++++++ .../ImportExportApplicationServiceTests.java | 1 + 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Application.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Application.java index c9bf2b0b12..9f1b09b176 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Application.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Application.java @@ -75,13 +75,26 @@ public class Application extends BaseDomain { @JsonProperty(access = JsonProperty.Access.READ_ONLY) Integer evaluationVersion; + /* + Changing name, change in pages, widgets and datasources will set lastEditedAt. + Other activities e.g. changing policy will not change this property. + We're adding JsonIgnore here because it'll be exposed as modifiedAt to keep it backward compatible + */ + @JsonIgnore + Instant lastEditedAt; + /** - * This method has been added because the updatedAt property in base domain has @JsonIgnore annotation + * Earlier this was returning value of the updatedAt property in the base domain. + * As this property is modified by the framework when there is any change in domain, + * a new property lastEditedAt has been added to track the edit actions from users. + * This method exposes that property. * @return updated time as a string */ @JsonProperty(value = "modifiedAt", access = JsonProperty.Access.READ_ONLY) public String getLastUpdateTime() { - if(updatedAt != null) { + if(lastEditedAt != null) { + return ISO_FORMATTER.format(lastEditedAt); + } else if (updatedAt != null) { // last edit is null, return updatedAt in this case return ISO_FORMATTER.format(updatedAt); } return null; 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 7d974069cd..f45a832045 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 @@ -505,7 +505,7 @@ public class ApplicationPageServiceImpl implements ApplicationPageService { // Create a new clone application object without the pages using the parameterized Application constructor Application newApplication = new Application(sourceApplication); newApplication.setName(newName); - + newApplication.setLastEditedAt(Instant.now()); Mono userMono = sessionUserService.getCurrentUser().cache(); // First set the correct policies for the new cloned application return setApplicationPolicies(userMono, sourceApplication.getOrganizationId(), newApplication) @@ -618,7 +618,12 @@ public class ApplicationPageServiceImpl implements ApplicationPageService { Application application = tuple.getT4(); log.debug("Archived pageId: {} , {} actions and {} action collections for applicationId: {}", page1.getId(), actions.size(), actionCollections.size(), application.getId()); return page1; - }); + }) + .flatMap(pageDTO -> + // save the last edit information as page is deleted from application + applicationService.saveLastEditInformation(pageDTO.getApplicationId()) + .thenReturn(pageDTO) + ); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationServiceImpl.java index 5fcedec6d7..baa3d40bcf 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ApplicationServiceImpl.java @@ -162,12 +162,14 @@ public class ApplicationServiceImpl extends BaseService createDefault(Application application) { application.setSlug(TextUtils.makeSlug(application.getName())); + application.setLastEditedAt(Instant.now()); return super.create(application); } @Override public Mono update(String id, Application application) { application.setIsPublic(null); + application.setLastEditedAt(Instant.now()); if(!StringUtils.isEmpty(application.getName())) { application.setSlug(TextUtils.makeSlug(application.getName())); } @@ -459,6 +461,7 @@ public class ApplicationServiceImpl extends BaseService applicationMono = createPageMono(UUID.randomUUID().toString()) + .flatMap(pageDTO -> { + Application application = new Application(); + application.setLastEditedAt(Instant.now().minus(10, ChronoUnit.DAYS)); + return applicationRepository.updateById(pageDTO.getApplicationId(), application, AclPermission.MANAGE_APPLICATIONS) + .then(applicationPageService.deleteUnpublishedPage(pageDTO.getId())) + .then(applicationRepository.findById(pageDTO.getApplicationId())); + }); + + StepVerifier.create(applicationMono).assertNext(application -> { + assertThat(application.getLastEditedAt()).isNotNull(); + Instant yesterday = Instant.now().minus(1, ChronoUnit.DAYS); + assertThat(application.getLastEditedAt()).isAfter(yesterday); + }).verifyComplete(); + } } 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 03776beb4e..31415fe624 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 @@ -225,6 +225,7 @@ public class ImportExportApplicationServiceTests { Application exportedApplication = applicationJson.getExportedApplication(); assertThat(exportedApplication.getModifiedBy()).isNull(); assertThat(exportedApplication.getLastUpdateTime()).isNull(); + assertThat(exportedApplication.getLastEditedAt()).isNull(); assertThat(exportedApplication.getLastDeployedAt()).isNull(); assertThat(exportedApplication.getGitApplicationMetadata()).isNull(); })