From 673110b32664d5d91ff085bbd927967c0d5c382e Mon Sep 17 00:00:00 2001 From: tdruez Date: Fri, 17 Jan 2025 17:35:52 +0400 Subject: [PATCH] Set the proper exclude for the report XLSX outputs #1524 Signed-off-by: tdruez --- scanpipe/management/commands/report.py | 1 + scanpipe/pipes/output.py | 19 +++++++++++-------- scanpipe/tests/test_commands.py | 3 +++ scanpipe/views.py | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/scanpipe/management/commands/report.py b/scanpipe/management/commands/report.py index 86744c5e5..f2912ae71 100644 --- a/scanpipe/management/commands/report.py +++ b/scanpipe/management/commands/report.py @@ -110,6 +110,7 @@ def handle(self, *args, **options): output.queryset_to_xlsx_worksheet( worksheet_queryset, workbook, + exclude_fields=output.XLSX_EXCLUDE_FIELDS, prepend_fields=["project"], worksheet_name="TODOS", ) diff --git a/scanpipe/pipes/output.py b/scanpipe/pipes/output.py index ad09cf3b8..84a795b09 100644 --- a/scanpipe/pipes/output.py +++ b/scanpipe/pipes/output.py @@ -474,6 +474,16 @@ def _adapt_value_for_xlsx(fieldname, value, maximum_length=32767, _adapt=True): return value, error +XLSX_EXCLUDE_FIELDS = [ + "extra_data", + "package_data", + "license_detections", + "other_license_detections", + "license_clues", + "affected_by_vulnerabilities", +] + + def to_xlsx(project): """ Generate output for the provided ``project`` in XLSX format. @@ -484,15 +494,8 @@ def to_xlsx(project): with possible error messages for a row when converting the data to XLSX exceed the limits of what can be stored in a cell. """ + exclude_fields = XLSX_EXCLUDE_FIELDS.copy() output_file = project.get_output_file_path("results", "xlsx") - exclude_fields = [ - "extra_data", - "package_data", - "license_detections", - "other_license_detections", - "license_clues", - "affected_by_vulnerabilities", - ] if not project.policies_enabled: exclude_fields.append("compliance_alert") diff --git a/scanpipe/tests/test_commands.py b/scanpipe/tests/test_commands.py index 937175806..3f3156dcd 100644 --- a/scanpipe/tests/test_commands.py +++ b/scanpipe/tests/test_commands.py @@ -1133,6 +1133,9 @@ def test_scanpipe_management_command_report(self): workbook = openpyxl.load_workbook(output_file, read_only=True, data_only=True) self.assertEqual(["TODOS"], workbook.get_sheet_names()) todos_sheet = workbook.get_sheet_by_name("TODOS") + header = list(todos_sheet.values)[0] + + self.assertNotIn("extra_data", header) row1 = list(todos_sheet.values)[1] expected = ("project1", "file.ext", "file", "file.ext", "requires-review") self.assertEqual(expected, row1[0:5]) diff --git a/scanpipe/views.py b/scanpipe/views.py index e47dfd919..9aafa2981 100644 --- a/scanpipe/views.py +++ b/scanpipe/views.py @@ -466,6 +466,7 @@ def export_xlsx_file_response(self): output.queryset_to_xlsx_worksheet( queryset, workbook, + exclude_fields=output.XLSX_EXCLUDE_FIELDS, prepend_fields=prepend_fields, worksheet_name=worksheet_name, )