From fd457cd933ade344d19b0a17d40b6cd47d9214e3 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Tue, 26 Mar 2024 03:35:19 +0530 Subject: [PATCH] show notes violation for only admins and approvers in a paid policy. Signed-off-by: Krishna Gupta --- .../ReportActionItem/MoneyRequestView.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 7fd5fec6d2b9..f17f635f3260 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -41,6 +41,9 @@ import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; import ReportActionItemImage from './ReportActionItemImage'; type MoneyRequestViewTransactionOnyxProps = { + /** Session info for the currently logged in user. */ + session: OnyxEntry; + /** The transaction associated with the transactionThread */ transaction: OnyxEntry; @@ -85,6 +88,7 @@ function MoneyRequestView({ policyTagList, policy, transactionViolations, + session, }: MoneyRequestViewProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -131,6 +135,10 @@ function MoneyRequestView({ const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); + const isActionOwner = typeof parentReportAction?.actorAccountID === 'number' && typeof session?.accountID === 'number' && parentReportAction.actorAccountID === session?.accountID; + const isPolicyAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; + const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID; + // A flag for verifying that the current report is a sub-report of a workspace chat // if the policy of the report is either Collect or Control, then this report must be tied to workspace chat const isPolicyExpenseChat = ReportUtils.isGroupPolicy(report); @@ -152,7 +160,7 @@ function MoneyRequestView({ [canUseViolations, getViolationsForField], ); const noteTypeViolations = transactionViolations?.filter((violation) => violation.type === 'notice').map((v) => ViolationsUtils.getViolationTranslation(v, translate)); - const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && hasReceipt; + const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report) && (isActionOwner || isPolicyAdmin || isApprover); let amountDescription = `${translate('iou.amount')}`; @@ -487,5 +495,8 @@ export default withOnyx