From 8647ab6a8a4aa33207fdf837ca8d1b3b67ca74a3 Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Sun, 1 Oct 2023 13:15:02 +0100 Subject: [PATCH 1/7] prevent OpenReport api call with "null" report --- src/libs/ReportUtils.js | 12 +++++++++++- src/pages/home/ReportScreen.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f41ad0b75b42..d999e9bad711 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3382,7 +3382,16 @@ function shouldReportShowSubscript(report) { * @returns {Boolean} */ function isReportDataReady() { - return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); + return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key] && allReports[key].reportID); +} + +/** + * Return true if reportID is valid + * @param {String} reportID + * @returns {Boolean} + */ +function isValidReportID(reportID) { + return typeof reportID === 'string' && !_.isEmpty(reportID) && reportID !== 'null' && reportID !== '0'; } /** @@ -3788,6 +3797,7 @@ export { isChildReport, shouldReportShowSubscript, isReportDataReady, + isValidReportID, isSettled, isAllowedToComment, getBankAccountRoute, diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index c30a8c7ed4a8..8fe6230630c4 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -241,7 +241,7 @@ function ReportScreen({ // Report ID will be empty when the reports collection is empty. // This could happen when we are loading the collection for the first time after logging in. - if (!reportIDFromPath) { + if (!ReportUtils.isValidReportID(reportIDFromPath)) { return; } From ceaa1f32a9163598a86b7ef482be7c506428dbf3 Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Sun, 1 Oct 2023 13:59:16 +0100 Subject: [PATCH 2/7] update isValidReportID function --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d999e9bad711..9265ebfc5269 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3391,7 +3391,7 @@ function isReportDataReady() { * @returns {Boolean} */ function isValidReportID(reportID) { - return typeof reportID === 'string' && !_.isEmpty(reportID) && reportID !== 'null' && reportID !== '0'; + return typeof reportID === 'string' && !['', 'null', '0'].includes(reportID); } /** From 028b7acded72c18bd997bddcce56122527e6e75a Mon Sep 17 00:00:00 2001 From: Mykhailo Khutornyi <97676131+mkhutornyi@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:42:20 -0600 Subject: [PATCH 3/7] Update src/libs/ReportUtils.js Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 9265ebfc5269..83cda26d4716 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3387,7 +3387,7 @@ function isReportDataReady() { /** * Return true if reportID is valid - * @param {String} reportID + * @param {String} reportIDFromPath * @returns {Boolean} */ function isValidReportID(reportID) { From 9dcfda90b0f4a68a4fcd86497efdf2c092d537c2 Mon Sep 17 00:00:00 2001 From: Mykhailo Khutornyi <97676131+mkhutornyi@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:42:31 -0600 Subject: [PATCH 4/7] Update src/libs/ReportUtils.js Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 83cda26d4716..8b19e2021ab1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3391,7 +3391,7 @@ function isReportDataReady() { * @returns {Boolean} */ function isValidReportID(reportID) { - return typeof reportID === 'string' && !['', 'null', '0'].includes(reportID); + return typeof reportIDFromPath === 'string' && !['', 'null', '0'].includes(reportIDFromPath); } /** From 488a6a3ba91a6b2e5357ff3662d5bb2b05578daf Mon Sep 17 00:00:00 2001 From: Mykhailo Khutornyi <97676131+mkhutornyi@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:42:37 -0600 Subject: [PATCH 5/7] Update src/libs/ReportUtils.js Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8b19e2021ab1..431ea595f1d0 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3390,7 +3390,7 @@ function isReportDataReady() { * @param {String} reportIDFromPath * @returns {Boolean} */ -function isValidReportID(reportID) { +function isValidReportIDFromPath(reportID) { return typeof reportIDFromPath === 'string' && !['', 'null', '0'].includes(reportIDFromPath); } From 71acee51161ca2fea4c9438de4a0dbdc291afd5a Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Mon, 2 Oct 2023 16:47:09 +0100 Subject: [PATCH 6/7] update isValidReportIDFromPath name --- src/libs/ReportUtils.js | 4 ++-- src/pages/home/ReportScreen.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 71be5dabede9..d1e94a18ea42 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3390,7 +3390,7 @@ function isReportDataReady() { * @param {String} reportIDFromPath * @returns {Boolean} */ -function isValidReportIDFromPath(reportID) { +function isValidReportIDFromPath(reportIDFromPath) { return typeof reportIDFromPath === 'string' && !['', 'null', '0'].includes(reportIDFromPath); } @@ -3773,7 +3773,7 @@ export { isChildReport, shouldReportShowSubscript, isReportDataReady, - isValidReportID, + isValidReportIDFromPath, isSettled, isAllowedToComment, getBankAccountRoute, diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 192d1d4b71ad..7a979ae18783 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -230,7 +230,7 @@ function ReportScreen({ // Report ID will be empty when the reports collection is empty. // This could happen when we are loading the collection for the first time after logging in. - if (!ReportUtils.isValidReportID(reportIDFromPath)) { + if (!ReportUtils.isValidReportIDFromPath(reportIDFromPath)) { return; } From 55407276418d59d3ffaa0eba0834e483f4424d0a Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Mon, 2 Oct 2023 16:49:14 +0100 Subject: [PATCH 7/7] update comment --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d1e94a18ea42..4a59e90380b1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3386,7 +3386,7 @@ function isReportDataReady() { } /** - * Return true if reportID is valid + * Return true if reportID from path is valid * @param {String} reportIDFromPath * @returns {Boolean} */