From fc6322d3d966c7f5f5175e8831dfdb8c336b8061 Mon Sep 17 00:00:00 2001 From: Daniel David <114867882+pigrammer3@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:10:44 -0500 Subject: [PATCH 1/2] add scouter names to export (access control ofc) --- primary/src/routes/reports.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/primary/src/routes/reports.ts b/primary/src/routes/reports.ts index 720dcac5..ef71c7a8 100644 --- a/primary/src/routes/reports.ts +++ b/primary/src/routes/reports.ts @@ -1496,6 +1496,7 @@ router.get('/exportdata', wrap(async (req, res) => { } let pivotDataKeys = pivotDataCols.split(','); let isFirstRow = true; + const isAuthorized = req._user.role.access_level >= Permissions.ACCESS_SCOUTER; for (let i in scored) { if (scored[i].data) { let thisScored = scored[i]; @@ -1504,6 +1505,10 @@ router.get('/exportdata', wrap(async (req, res) => { isFirstRow = false; // initialize header row with particular columns let headerRow = pivotDataCols; + // add scouter name if authorized + if (isAuthorized) { + headerRow += ',scouter'; + } // add on metric IDs for (let thisItem of matchLayout) { // 2022-04-04 JL: If the user is not logged in as a scouter, then don't include otherNotes in the export @@ -1540,6 +1545,18 @@ router.get('/exportdata', wrap(async (req, res) => { dataRow += thisVal.replace(/(\r\n|\n|\r)/gm,''); } + // add scouter name if authorized + if (isAuthorized) { + if ('actual_scorer' in thisScored) + dataRow += ',' + (thisScored.actual_scorer?.name ?? ''); + + else if ('actual_scouter' in thisScored) + dataRow += ',' + (thisScored.actual_scouter?.name ?? ''); + + else + dataRow += ','; + } + // cycle through the metrics for (let thisItem of matchLayout) { // 2022-04-04 JL: If the user is not logged in as a scouter, then don't include otherNotes in the export @@ -1559,7 +1576,7 @@ router.get('/exportdata', wrap(async (req, res) => { // If the layout item is otherNotes and the user is unauthorized to view it, return false. function isOtherNotesAndUnauthorized(thisItem: Layout) { - return (thisItem.id === 'otherNotes' && req._user.role.access_level < Permissions.ACCESS_SCOUTER); + return (thisItem.id === 'otherNotes' && !isAuthorized); } logger.info('EXIT returning ' + scored.length + ' rows of CSV'); From ada680f24f98bb077fca6507741c9408d9fc3f9a Mon Sep 17 00:00:00 2001 From: Daniel David <114867882+pigrammer3@users.noreply.github.com> Date: Sun, 22 Dec 2024 15:59:44 -0500 Subject: [PATCH 2/2] add super scout notes to exported CSV --- primary/src/routes/reports.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/primary/src/routes/reports.ts b/primary/src/routes/reports.ts index ef71c7a8..1079912c 100644 --- a/primary/src/routes/reports.ts +++ b/primary/src/routes/reports.ts @@ -1515,6 +1515,10 @@ router.get('/exportdata', wrap(async (req, res) => { if (matchDataHelper.isMetric(thisItem.type) && !isOtherNotesAndUnauthorized(thisItem)) headerRow += ',' + thisItem.id; } + // add super notes if authorized + if (isAuthorized) { + headerRow += ',superNotes'; + } //logger.debug("headerRow=" + headerRow); fullCSVoutput = headerRow; } @@ -1548,10 +1552,10 @@ router.get('/exportdata', wrap(async (req, res) => { // add scouter name if authorized if (isAuthorized) { if ('actual_scorer' in thisScored) - dataRow += ',' + (thisScored.actual_scorer?.name ?? ''); + dataRow += ',"' + (thisScored.actual_scorer?.name ?? '') + '"'; else if ('actual_scouter' in thisScored) - dataRow += ',' + (thisScored.actual_scouter?.name ?? ''); + dataRow += ',"' + (thisScored.actual_scouter?.name ?? '') + '"'; else dataRow += ','; @@ -1569,6 +1573,9 @@ router.get('/exportdata', wrap(async (req, res) => { } } } + if (isAuthorized) { + dataRow += ',"' + ('' + (thisScored.super_data?.otherNotes ?? '')).replace(/(\r\n|\n|\r)/gm,'') + '"'; + } //logger.debug("dataRow=" + dataRow); fullCSVoutput += '\n' + dataRow; }