Skip to content

Commit

Permalink
fix(ExpensePage): error with valid parent account slug (#10769)
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree authored Oct 28, 2024
1 parent 9d2a9f6 commit e915a39
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pages/expense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const getPageMetadata = (intl, legacyExpenseId, expense) => {
}
};

const isValidCollectiveSlug = (collectiveSlug: string, expense) => {
return [expense.account.slug, expense.account.parent?.slug].filter(Boolean).includes(collectiveSlug);
};

// next.js export
// ts-unused-exports:disable-next-line
export default function ExpensePage(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
Expand Down Expand Up @@ -106,7 +110,7 @@ export default function ExpensePage(props: InferGetServerSidePropsType<typeof ge
return <ErrorPage data={data} />;
} else if (!data.expense) {
return <ErrorPage error={generateNotFoundError(null)} log={false} />;
} else if (!data.expense.account || props.collectiveSlug !== data.expense.account.slug) {
} else if (!data.expense.account || !isValidCollectiveSlug(collectiveSlug, data.expense)) {
return <ErrorPage error={generateNotFoundError(collectiveSlug)} log={false} />;
}
}
Expand Down

0 comments on commit e915a39

Please sign in to comment.