INFRA-4079 | Harinder | While approving the change request, context is set to approver. Changing the same to the person who raised the request

This commit is contained in:
Harinder Singh
2024-12-23 20:48:23 +05:30
parent 7cd54e0460
commit 53cf71dcaf

View File

@@ -258,22 +258,20 @@ public class ChangeRequestServiceImpl implements ChangeRequestService {
"Change request: {} is approved. Initiated merging with current version of the manifest",
changeRequestId);
final var manifest = manifestService.fetchByIdWithoutAuthorization(
changeRequest.getManifestId());
try {
changeRequestSlackService.handleChangeRequestUpdate(manifest, changeRequest);
} catch (Exception e) {
log.error("Error updating slack message while mering CR id:{} of manifest:{} : {}",
changeRequestId, manifest.fullName(), e.getMessage());
}
final var manifestMap = manifest.convertToMap();
mergeCr(manifestMap, changeRequest);
final var mergedManifest = objectMapper.convertValue(manifestMap, Manifest.class);
SecurityContext originalContext = SecurityContextHolder.getContext();
var crCreatorContext = authUtil.getSecurityContextForUser(changeRequest.getCreatedBy());
try {
SecurityContextHolder.setContext(crCreatorContext);
final var manifest = manifestService.fetchById(changeRequest.getManifestId());
try {
changeRequestSlackService.handleChangeRequestUpdate(manifest, changeRequest);
} catch (Exception e) {
log.error("Error updating slack message while mering CR id:{} of manifest:{} : {}",
changeRequestId, manifest.fullName(), e.getMessage());
}
final var manifestMap = manifest.convertToMap();
mergeCr(manifestMap, changeRequest);
final var mergedManifest = objectMapper.convertValue(manifestMap, Manifest.class);
manifestService.createOrUpdate(mergedManifest, true);
} finally {
SecurityContextHolder.setContext(originalContext);