INFRA-3232 | Dhruv | Handles repeated action on same request by users
This commit is contained in:
@@ -3,7 +3,6 @@ package com.navi.infra.portal.v2.approvalflow.controller;
|
||||
import com.navi.infra.portal.security.authorization.AuthorizationContext;
|
||||
import com.navi.infra.portal.v2.approvalflow.entity.ApprovalRequest;
|
||||
import com.navi.infra.portal.v2.approvalflow.service.ApprovalRequestService;
|
||||
import java.io.IOException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -24,7 +23,7 @@ public class ApprovalRequestController {
|
||||
|
||||
@PutMapping("/{id}/approve")
|
||||
public ResponseEntity<ApprovalRequest> approveRequest(
|
||||
@PathVariable("id") Long approvalRequestId) throws IOException {
|
||||
@PathVariable("id") Long approvalRequestId) {
|
||||
final var userId = AuthorizationContext.getUserId();
|
||||
final var approvalRequest = service.allowApproveRequest(approvalRequestId, userId);
|
||||
return ResponseEntity.ok(approvalRequest);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.navi.infra.portal.v2.jit.controller;
|
||||
|
||||
import com.navi.infra.portal.v2.exception.NotFoundException;
|
||||
import com.navi.infra.portal.v2.jit.dto.JitUserDto;
|
||||
import com.navi.infra.portal.v2.jit.service.ChangeRequestSlackService;
|
||||
import java.io.IOException;
|
||||
import javax.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -25,15 +28,15 @@ public class JitChangeRequestController {
|
||||
private final ChangeRequestSlackService changeRequestSlackService;
|
||||
|
||||
@PostMapping("/approveRequest/{requestId}/approve")
|
||||
public void approveRequest(
|
||||
public ResponseEntity<HttpStatus> approveRequest(
|
||||
@Valid @RequestBody JitUserDto approver,
|
||||
@PathVariable Long requestId
|
||||
) {
|
||||
try {
|
||||
changeRequestSlackService.approveRequest(approver.getUser(), requestId);
|
||||
} catch (IOException e) {
|
||||
log.error("Error updating slack Approval request {} for user {}", requestId,
|
||||
approver.getUser(), e);
|
||||
return ResponseEntity.status(HttpStatus.OK).build();
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error approving Approval request {} for user {}", requestId,
|
||||
approver.getUser(), e);
|
||||
@@ -42,12 +45,15 @@ public class JitChangeRequestController {
|
||||
}
|
||||
|
||||
@PostMapping("/approveRequest/{requestId}/reject")
|
||||
public void rejectRequest(
|
||||
public ResponseEntity<HttpStatus> rejectRequest(
|
||||
@Valid @RequestBody JitUserDto approver,
|
||||
@PathVariable Long requestId
|
||||
) {
|
||||
try {
|
||||
changeRequestSlackService.rejectRequest(approver.getUser(), requestId);
|
||||
return ResponseEntity.status(HttpStatus.OK).build();
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error rejecting Approval request {} for user {}", requestId,
|
||||
approver.getUser(), e);
|
||||
@@ -56,12 +62,16 @@ public class JitChangeRequestController {
|
||||
}
|
||||
|
||||
@PostMapping("/changeRequest/{requestId}/close")
|
||||
public void closeRequest(
|
||||
public ResponseEntity<HttpStatus> closeRequest(
|
||||
@Valid @RequestBody JitUserDto approver,
|
||||
@PathVariable Long requestId
|
||||
) {
|
||||
try {
|
||||
changeRequestSlackService.closeRequest(approver.getUser(), requestId);
|
||||
return ResponseEntity.status(HttpStatus.OK).build();
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
log.info("Error closing Change request {} for user {}", requestId, approver.getUser());
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error closing Change request {} for user {}", requestId, approver.getUser(), e);
|
||||
throw e;
|
||||
|
||||
@@ -10,7 +10,7 @@ public interface ChangeRequestSlackService {
|
||||
void sendSlackApprovalMessages(Manifest manifest, ChangeRequest changeRequest,
|
||||
List<ApprovalRequest> approvalRequests) throws IOException;
|
||||
|
||||
void approveRequest(String userEmail, Long requestId) throws IOException;
|
||||
void approveRequest(String userEmail, Long requestId);
|
||||
|
||||
void handleApproveRequest(Long changeRequestId, Long approvalRequestId, Long userId,
|
||||
Long teamId) throws IOException;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.navi.infra.portal.v2.approvalflow.service.ApprovalRequestService;
|
||||
import com.navi.infra.portal.v2.changerequest.entity.ChangeRequest;
|
||||
import com.navi.infra.portal.v2.changerequest.entity.RequestStatus;
|
||||
import com.navi.infra.portal.v2.changerequest.service.ChangeRequestService;
|
||||
import com.navi.infra.portal.v2.exception.NotFoundException;
|
||||
import com.navi.infra.portal.v2.jit.entity.SlackChangeRequest;
|
||||
import com.navi.infra.portal.v2.jit.repository.ChangeRequestSlackRepository;
|
||||
import com.navi.infra.portal.v2.jit.utils.ChangeRequestSlackUtil;
|
||||
@@ -27,6 +28,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -319,22 +321,40 @@ public class ChangeRequestSlackServiceImpl implements ChangeRequestSlackService
|
||||
});
|
||||
}
|
||||
|
||||
public void approveRequest(String userEmail, Long requestId) throws IOException {
|
||||
public void approveRequest(String userEmail, Long requestId) {
|
||||
var user = userService.findUserByEmail(userEmail);
|
||||
setSecurityContextForSlackReviewer(user);
|
||||
approvalRequestService.allowApproveRequest(requestId, user.getId());
|
||||
try {
|
||||
approvalRequestService.allowApproveRequest(requestId, user.getId());
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
log.error("Error approving Approval request {} for user {}", requestId,
|
||||
userEmail, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void rejectRequest(String userEmail, Long requestId) {
|
||||
var user = userService.findUserByEmail(userEmail);
|
||||
setSecurityContextForSlackReviewer(user);
|
||||
approvalRequestService.reject(requestId, user.getId());
|
||||
try {
|
||||
approvalRequestService.reject(requestId, user.getId());
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
log.error("Error approving Approval request {} for user {}", requestId,
|
||||
userEmail, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeRequest(String userEmail, Long requestId) {
|
||||
var user = userService.findUserByEmail(userEmail);
|
||||
setSecurityContextForSlackReviewer(user);
|
||||
changeRequestService.close(requestId, user.getId());
|
||||
try {
|
||||
changeRequestService.close(requestId, user.getId());
|
||||
} catch (NotFoundException | AccessDeniedException e) {
|
||||
log.error("Error approving Approval request {} for user {}", requestId,
|
||||
userEmail, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user