Merge pull request #4103 from Infisical/allow-users-to-cancel-access-requests

improvement(access-approval): allow all users to reject their own access requests
This commit is contained in:
Scott Wilson
2025-07-14 16:36:17 -07:00
committed by GitHub
2 changed files with 18 additions and 14 deletions

View File

@@ -354,11 +354,17 @@ export const accessApprovalRequestServiceFactory = ({
status === ApprovalStatus.APPROVED;
const isApprover = policy.approvers.find((approver) => approver.userId === actorId);
// If user is (not an approver OR cant self approve) AND can't bypass policy
if ((!isApprover || (!policy.allowedSelfApprovals && isSelfApproval)) && cannotBypassUnderSoftEnforcement) {
throw new BadRequestError({
message: "Failed to review access approval request. Users are not authorized to review their own request."
});
const isSelfRejection = isSelfApproval && status === ApprovalStatus.REJECTED;
// users can always reject (cancel) their own requests
if (!isSelfRejection) {
// If user is (not an approver OR cant self approve) AND can't bypass policy
if ((!isApprover || (!policy.allowedSelfApprovals && isSelfApproval)) && cannotBypassUnderSoftEnforcement) {
throw new BadRequestError({
message: "Failed to review access approval request. Users are not authorized to review their own request."
});
}
}
if (
@@ -414,7 +420,7 @@ export const accessApprovalRequestServiceFactory = ({
);
// Only throw if actor is not the approver and not bypassing
if (!isApproverOfTheSequence && !isBreakGlassApprovalAttempt) {
if (!isApproverOfTheSequence && !isBreakGlassApprovalAttempt && !isSelfRejection) {
throw new BadRequestError({ message: "You are not a reviewer in this step" });
}
}

View File

@@ -255,6 +255,11 @@ export const ReviewAccessRequestModal = ({
return "You are not the reviewer in this step.";
};
// users can always reject (cancel) their own request
const isRejectionDisabled = request.isRequestedByCurrentUser
? false
: !(request.isApprover && request.isSelfApproveAllowed) && !bypassApproval;
return (
<Modal isOpen={isOpen} onOpenChange={onOpenChange}>
<ModalContent
@@ -489,14 +494,7 @@ export const ReviewAccessRequestModal = ({
</Button>
<Button
isLoading={isLoading === "rejected"}
isDisabled={
!!isLoading ||
(!(
request.isApprover &&
(!request.isRequestedByCurrentUser || request.isSelfApproveAllowed)
) &&
!bypassApproval)
}
isDisabled={!!isLoading || isRejectionDisabled}
onClick={() => handleReview("rejected")}
className="mt-4 border-transparent bg-transparent text-mineshaft-200 hover:border-red hover:bg-red/20 hover:text-mineshaft-200"
size="sm"