Skip to content

Commit

Permalink
do not show export to integration button if user not an admin or manager
Browse files Browse the repository at this point in the history
  • Loading branch information
lakchote committed Jul 17, 2024
1 parent a8b76fa commit 68ab5c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ type MoneyReportHeaderProps = {
/** Whether we should display the header as in narrow layout */
shouldUseNarrowLayout?: boolean;

/** The accountID of the current user */
currentUserAccountID: number;

/** Method to trigger when pressing close button of the header */
onBackButtonPress: () => void;
};

function MoneyReportHeader({policy, report: moneyRequestReport, transactionThreadReportID, reportActions, shouldUseNarrowLayout = false, onBackButtonPress}: MoneyReportHeaderProps) {
function MoneyReportHeader({
policy,
report: moneyRequestReport,
transactionThreadReportID,
reportActions,
shouldUseNarrowLayout = false,
onBackButtonPress,
currentUserAccountID,
}: MoneyReportHeaderProps) {
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport.chatReportID}`);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport.reportID}`);
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);
Expand Down Expand Up @@ -118,7 +129,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea

const shouldShowSubmitButton = isDraft && reimbursableSpend !== 0 && !allHavePendingRTERViolation;

const shouldShowExportIntegrationButton = !shouldShowPayButton && !shouldShowSubmitButton && connectedIntegration && !!policy;
const isManager = currentUserAccountID === moneyRequestReport?.managerID;
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const shouldShowExportIntegrationButton = !shouldShowPayButton && !shouldShowSubmitButton && connectedIntegration && (isManager || isAdmin);

const shouldShowSettlementButton = (shouldShowPayButton || shouldShowApproveButton) && !allHavePendingRTERViolation && !shouldShowExportIntegrationButton;

Expand Down
13 changes: 11 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, Report, ReportAction, Transaction, TransactionViolations, UserWallet} from '@src/types/onyx';
import type {Policy, Report, ReportAction, Session, Transaction, TransactionViolations, UserWallet} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import ExportWithDropdownMenu from './ExportWithDropdownMenu';
import type {PendingMessageProps} from './MoneyRequestPreview/types';
Expand All @@ -47,6 +47,8 @@ type ReportPreviewOnyxProps = {
/** The policy tied to the expense report */
policy: OnyxEntry<Policy>;

session: OnyxEntry<Session>;

/** ChatReport associated with iouReport */
chatReport: OnyxEntry<Report>;

Expand Down Expand Up @@ -96,6 +98,7 @@ function ReportPreview({
iouReport,
policy,
iouReportID,
session,
policyID,
chatReportID,
chatReport,
Expand All @@ -115,6 +118,7 @@ function ReportPreview({
const {canUseViolations} = usePermissions();
const {isOffline} = useNetwork();

const currentUserAccountID = session?.accountID;
const {hasMissingSmartscanFields, areAllRequestsBeingSmartScanned, hasOnlyTransactionsWithPendingRoutes, hasNonReimbursableTransactions} = useMemo(
() => ({
hasMissingSmartscanFields: ReportUtils.hasMissingSmartscanFields(iouReportID),
Expand Down Expand Up @@ -341,7 +345,9 @@ function ReportPreview({
*/
const connectedIntegration = PolicyUtils.getConnectedIntegration(policy);

const shouldShowExportIntegrationButton = !shouldShowPayButton && !shouldShowSubmitButton && connectedIntegration;
const isManager = currentUserAccountID === iouReport?.managerID;
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const shouldShowExportIntegrationButton = !shouldShowPayButton && !shouldShowSubmitButton && connectedIntegration && (isManager || isAdmin);

return (
<OfflineWithFeedback
Expand Down Expand Up @@ -511,4 +517,7 @@ export default withOnyx<ReportPreviewProps, ReportPreviewOnyxProps>({
userWallet: {
key: ONYXKEYS.USER_WALLET,
},
session: {
key: ONYXKEYS.SESSION,
},
})(ReportPreview);

0 comments on commit 68ab5c6

Please sign in to comment.