From 9dd22de01c4cadffcfa15317df8ed2c0de7b2c3a Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 12 Dec 2024 14:33:53 +0530 Subject: [PATCH 1/3] fix: Hide current user in approver selector when 'prevent self approvals' is enabled. Signed-off-by: krishna2323 --- ...orkspaceWorkflowsApprovalsApproverPage.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index f41a8dd0ab4d..5a6dd3bf5981 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -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((mem) => mem.email), [approvalWorkflow?.members]); const sections: ApproverSection[] = useMemo(() => { const approvers: SelectionListApprover[] = []; @@ -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) { @@ -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; From 764e2866fbb3f6c7b0b836ebd41be2896df899fc Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 12 Dec 2024 15:10:38 +0530 Subject: [PATCH 2/3] minor update. Signed-off-by: krishna2323 --- .../approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index 5a6dd3bf5981..d9987ce6df8e 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -76,7 +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((mem) => mem.email), [approvalWorkflow?.members]); + const membersEmail = useMemo(() => approvalWorkflow?.members.map((member) => member.email), [approvalWorkflow?.members]); const sections: ApproverSection[] = useMemo(() => { const approvers: SelectionListApprover[] = []; From 55a9bb3944d0a576c6db9294f983c1d112f13380 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 12 Dec 2024 18:42:26 +0530 Subject: [PATCH 3/3] fix: filter approvers from submit to members page if preventSelfApproval is true. Signed-off-by: krishna2323 --- .../WorkspaceWorkflowsApprovalsExpensesFromPage.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx index 8f7553e97fe1..1e44135a6082 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx @@ -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]; @@ -107,7 +108,9 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat rightElement: isAdmin ? : 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); } @@ -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;