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.
This commit is contained in:
Nayan 2021-11-11 17:30:57 +06:00 committed by GitHub
parent 4b2c1fc316
commit b44f555a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 4 deletions

View File

@ -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;

View File

@ -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<User> 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)
);
});
}

View File

@ -162,12 +162,14 @@ public class ApplicationServiceImpl extends BaseService<ApplicationRepository, A
@Override
public Mono<Application> createDefault(Application application) {
application.setSlug(TextUtils.makeSlug(application.getName()));
application.setLastEditedAt(Instant.now());
return super.create(application);
}
@Override
public Mono<Application> 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<ApplicationRepository, A
Application application = new Application();
// need to set isPublic=null because it has a `false` as it's default value in domain class
application.setIsPublic(null);
application.setLastEditedAt(Instant.now());
/*
We're not setting updatedAt and modifiedBy fields to the application DTO because these fields will be set
by the updateById method of the BaseAppsmithRepositoryImpl

View File

@ -159,6 +159,8 @@ public class ImportExportApplicationService {
application.setModifiedBy(null);
application.setUpdatedAt(null);
application.setLastDeployedAt(null);
application.setLastEditedAt(null);
application.setUpdatedAt(null);
application.setGitApplicationMetadata(null);
examplesOrganizationCloner.makePristine(application);
applicationJson.setExportedApplication(application);

View File

@ -1,5 +1,6 @@
package com.appsmith.server.services;
import com.appsmith.server.acl.AclPermission;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Comment;
import com.appsmith.server.domains.CommentMode;
@ -7,6 +8,7 @@ import com.appsmith.server.domains.CommentThread;
import com.appsmith.server.domains.Organization;
import com.appsmith.server.dtos.CommentThreadFilterDTO;
import com.appsmith.server.dtos.PageDTO;
import com.appsmith.server.repositories.ApplicationRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -18,6 +20,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;
@ -37,6 +41,9 @@ public class ApplicationPageServiceTest {
@Autowired
CommentService commentService;
@Autowired
ApplicationRepository applicationRepository;
private CommentThread createCommentThread(CommentMode commentMode, PageDTO pageDTO) {
CommentThread commentThread = new CommentThread();
commentThread.setPageId(pageDTO.getId());
@ -122,4 +129,23 @@ public class ApplicationPageServiceTest {
assertThat(commentThreads.size()).isEqualTo(0);
}).verifyComplete();
}
@Test
@WithUserDetails("api_user")
public void deleteUnpublishedPage_WhenPageDeleted_ApplicationEditDateSet() {
Mono<Application> 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();
}
}

View File

@ -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();
})