fix: Created at field in action is set again during import (#30177)

## Description
Skips `createdAt` field of unpublished action from being reset when
application is imported.

#### PR fixes following issue(s)
Fixes #30178
This commit is contained in:
Nayan 2024-01-11 10:52:55 +06:00 committed by GitHub
parent ecfa5eba78
commit 4ac06937f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -206,7 +206,16 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
action.setId(newAction.getId());
action.setUserPermissions(newAction.getUserPermissions());
action.setPolicies(newAction.getPolicies());
action.setCreatedAt(newAction.getCreatedAt());
/*
* Important: This null check before setting the createdAt field to ActionDTO is temporary.
* createdAt is part of exported JSON, and we used to import actions with the same value from JSON.
* It's wrong but if we fix this, the existing Git connected applications will show a diff for all actions.
* We want to avoid this and hence this null check is there.
* We're going to remove the createdAt field from JSON and post that this null check will be removed.
*/
if (action.getCreatedAt() == null) {
action.setCreatedAt(newAction.getCreatedAt());
}
}
@Override

View File

@ -1077,6 +1077,7 @@ public class ImportApplicationServiceTests {
ActionDTO actionDTO = newAction.getUnpublishedAction();
assertThat(actionDTO.getPageId())
.isNotEqualTo(pageList.get(0).getName());
if (StringUtils.equals(actionDTO.getName(), "api_wo_auth")) {
ActionDTO publishedAction = newAction.getPublishedAction();
assertThat(publishedAction).isNotNull();
@ -1084,6 +1085,8 @@ public class ImportApplicationServiceTests {
// Test the fallback page ID from the unpublishedAction is copied to published version when
// published version does not have pageId
assertThat(actionDTO.getPageId()).isEqualTo(publishedAction.getPageId());
// check that createAt field is getting populated from JSON
assertThat(actionDTO.getCreatedAt()).isEqualTo("2023-12-13T12:10:02Z");
}
if (!StringUtils.isEmpty(actionDTO.getCollectionId())) {

View File

@ -84,6 +84,9 @@ public class ImportApplicationTransactionServiceTest {
@MockBean
ImportableService<NewAction> newActionImportableService;
@Autowired
private Gson gson;
Long applicationCount = 0L, pageCount = 0L, actionCount = 0L, actionCollectionCount = 0L;
private ApplicationJson applicationJson = new ApplicationJson();
@ -123,7 +126,6 @@ public class ImportApplicationTransactionServiceTest {
return stringifiedFile
.map(data -> {
Gson gson = new Gson();
return gson.fromJson(data, ApplicationJson.class);
})
.map(JsonSchemaMigration::migrateApplicationToLatestSchema);

View File

@ -519,7 +519,8 @@
"invalids": [],
"jsonPathKeys": [],
"confirmBeforeExecute": false,
"userPermissions": []
"userPermissions": [],
"createdAt": "2023-12-13T12:10:02Z"
},
"publishedAction": {
"name": "api_wo_auth",