Skip to content

Commit

Permalink
Merge pull request Expensify#54005 from Krishna2323/krishna2323/issue…
Browse files Browse the repository at this point in the history
…/53612

fix: Hide current user in approver selector when 'prevent self approvals' is enabled.
  • Loading branch information
marcaaron authored Dec 12, 2024
2 parents 6d22e7b + 55a9bb3 commit c59b04f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function WorkspaceWorkflowsApprovalsApproverPage({policy, personalDetails, isLoa
const employeeList = policy?.employeeList;
const approversFromWorkflow = approvalWorkflow?.approvers;
const isDefault = approvalWorkflow?.isDefault;
const membersEmail = useMemo(() => approvalWorkflow?.members.map((member) => member.email), [approvalWorkflow?.members]);
const sections: ApproverSection[] = useMemo(() => {
const approvers: SelectionListApprover[] = [];

Expand All @@ -89,6 +90,10 @@ function WorkspaceWorkflowsApprovalsApproverPage({policy, personalDetails, isLoa
return null;
}

if (policy?.preventSelfApproval && membersEmail?.includes(email)) {
return null;
}

// Do not allow the same email to be added twice
const isEmailAlreadyInApprovers = approversFromWorkflow?.some((approver, index) => approver?.email === email && index !== approverIndex);
if (isEmailAlreadyInApprovers && selectedApproverEmail !== email) {
Expand Down Expand Up @@ -138,7 +143,19 @@ function WorkspaceWorkflowsApprovalsApproverPage({policy, personalDetails, isLoa
shouldShow: true,
},
];
}, [approversFromWorkflow, isDefault, approverIndex, debouncedSearchTerm, defaultApprover, personalDetails, employeeList, selectedApproverEmail, translate]);
}, [
approversFromWorkflow,
isDefault,
approverIndex,
debouncedSearchTerm,
defaultApprover,
personalDetails,
employeeList,
selectedApproverEmail,
membersEmail,
policy?.preventSelfApproval,
translate,
]);

const shouldShowListEmptyContent = !debouncedSearchTerm && approvalWorkflow && !sections.at(0)?.data.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat
);
}, [approvalWorkflow?.members, policy?.employeeList, translate]);

const approversEmail = useMemo(() => approvalWorkflow?.approvers.map((member) => member?.email), [approvalWorkflow?.approvers]);
const sections: MembersSection[] = useMemo(() => {
const members: SelectionListMember[] = [...selectedMembers];

Expand All @@ -107,7 +108,9 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat
rightElement: isAdmin ? <Badge text={translate('common.admin')} /> : undefined,
};
})
.filter((member) => !selectedMembers.some((selectedOption) => selectedOption.login === member.login));
.filter(
(member) => (!policy?.preventSelfApproval || !approversEmail?.includes(member.login)) && !selectedMembers.some((selectedOption) => selectedOption.login === member.login),
);

members.push(...availableMembers);
}
Expand All @@ -128,7 +131,7 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat
shouldShow: true,
},
];
}, [approvalWorkflow?.availableMembers, debouncedSearchTerm, policy?.employeeList, selectedMembers, translate]);
}, [approvalWorkflow?.availableMembers, debouncedSearchTerm, policy?.preventSelfApproval, policy?.employeeList, selectedMembers, translate, approversEmail]);

const goBack = useCallback(() => {
let backTo;
Expand Down

0 comments on commit c59b04f

Please sign in to comment.