From 2fd2f11bf99adea69822d61624c7706bda127db3 Mon Sep 17 00:00:00 2001
From: Rieven
Date: Wed, 3 Jul 2024 16:35:05 +0200
Subject: [PATCH 01/10] changes for post request for the rest of the report
flow
---
.../templates/forms/report_form_fields.html | 11 +-
.../templates/partials/report_setup_scan.html | 2 +
.../partials/report_types_selection.html | 3 +-
rocky/reports/views/aggregate_report.py | 89 +--------
rocky/reports/views/base.py | 15 +-
rocky/reports/views/generate_report.py | 125 +------------
rocky/reports/views/mixins.py | 175 ++++++++++++++++++
rocky/reports/views/multi_report.py | 2 +-
8 files changed, 215 insertions(+), 207 deletions(-)
create mode 100644 rocky/reports/views/mixins.py
diff --git a/rocky/reports/templates/forms/report_form_fields.html b/rocky/reports/templates/forms/report_form_fields.html
index b6fd8ed360f..461594e93b4 100644
--- a/rocky/reports/templates/forms/report_form_fields.html
+++ b/rocky/reports/templates/forms/report_form_fields.html
@@ -1,7 +1,7 @@
-{% for ooi in selected_oois %}{% endfor %}
+{% for ooi in selected_oois %}{% endfor %}
{% for ooi_type in ooi_types_selection %}{% endfor %}
{% for clearance_level in clearance_levels_selection %}
@@ -9,9 +9,14 @@
{% for clearance_type in clearance_types_selection %}
{% endfor %}
+{% if selected_report_types %}
+ {% for report_type in selected_report_types %}
+
+ {% endfor %}
+{% endif %}
{% if plugins.required %}
{% for required_plugin in plugins.required %}
-
+
{% endfor %}
{% endif %}
-{% if request.GET.page %}{% endif %}
+{% if request.GET.page %}{% endif %}
diff --git a/rocky/reports/templates/partials/report_setup_scan.html b/rocky/reports/templates/partials/report_setup_scan.html
index 8984a4809c7..3977c812500 100644
--- a/rocky/reports/templates/partials/report_setup_scan.html
+++ b/rocky/reports/templates/partials/report_setup_scan.html
@@ -94,6 +94,8 @@ {% translate "Suggested plugins" %}
{% endif %}
{% if not selected_oois %}
-
- {% translate "Go back" %}
-
+ {% include "partials/return_button.html" with btn_text="Go back" %}
+
{% else %}
{% blocktranslate trimmed count counter=oois|length %}
diff --git a/rocky/reports/templates/partials/report_types_tiles.html b/rocky/reports/templates/partials/report_types_tiles.html
index c74c1566dd1..c757622d991 100644
--- a/rocky/reports/templates/partials/report_types_tiles.html
+++ b/rocky/reports/templates/partials/report_types_tiles.html
@@ -5,7 +5,7 @@
+ {% if report_type.id in selected_report_types %}checked{% endif %} />
{{ report_type.description }}
diff --git a/rocky/reports/templates/partials/report_types_tiles_required_optional.html b/rocky/reports/templates/partials/report_types_tiles_required_optional.html
index 833b8358a39..0a7581b6e3f 100644
--- a/rocky/reports/templates/partials/report_types_tiles_required_optional.html
+++ b/rocky/reports/templates/partials/report_types_tiles_required_optional.html
@@ -7,7 +7,7 @@
+ {% if report_type.id in selected_report_types %}checked{% endif %} />
{% else %}
{% endif %}
diff --git a/rocky/reports/templates/partials/return_button.html b/rocky/reports/templates/partials/return_button.html
new file mode 100644
index 00000000000..ed038f61bd1
--- /dev/null
+++ b/rocky/reports/templates/partials/return_button.html
@@ -0,0 +1,14 @@
+{% load i18n %}
+
+
From 37195886cfdd4fe2d43ad83c555ed69aa0355ca0 Mon Sep 17 00:00:00 2001
From: Rieven
Date: Mon, 5 Aug 2024 16:54:39 +0200
Subject: [PATCH 10/10] fix lang and tests
---
rocky/reports/views/aggregate_report.py | 8 ------
rocky/reports/views/mixins.py | 4 +++
rocky/rocky/locale/django.pot | 28 +++++++++----------
.../reports/test_aggregate_report_flow.py | 7 +++--
.../reports/test_generate_report_flow.py | 14 ++++++++--
rocky/tests/reports/test_plugins.py | 2 +-
6 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/rocky/reports/views/aggregate_report.py b/rocky/reports/views/aggregate_report.py
index 41e34ca43a2..2b7c82a37e3 100644
--- a/rocky/reports/views/aggregate_report.py
+++ b/rocky/reports/views/aggregate_report.py
@@ -150,14 +150,6 @@ class SetupScanAggregateReportView(
breadcrumbs_step = 5
current_step = 3
- def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
- if not self.report_has_required_plugins() or self.plugins_enabled():
- return redirect(self.get_next())
- if not self.plugins:
- return redirect(self.get_previous())
-
- return super().get(request, *args, **kwargs)
-
def post(self, request, *args, **kwargs):
if not self.selected_report_types:
messages.error(request, self.NONE_REPORT_TYPE_SELECTION_MESSAGE)
diff --git a/rocky/reports/views/mixins.py b/rocky/reports/views/mixins.py
index cb044f242c7..99a8e5f37bf 100644
--- a/rocky/reports/views/mixins.py
+++ b/rocky/reports/views/mixins.py
@@ -78,8 +78,12 @@ def save_report(self, report_names: list) -> ReportOOI:
if ooi_name in default_name and report_type_name in default_name:
name = updated_name
break
+ else:
+ name = default_name
+ break
raw_id = self.save_report_raw(data={"report_data": data["data"]})
+
self.save_report_ooi(
report_data_raw_id=raw_id,
report_type=get_report_by_id(report_type),
diff --git a/rocky/rocky/locale/django.pot b/rocky/rocky/locale/django.pot
index fc689523bb1..ba70cbfca1d 100644
--- a/rocky/rocky/locale/django.pot
+++ b/rocky/rocky/locale/django.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2024-08-05 09:27+0000\n"
+"POT-Creation-Date: 2024-08-05 13:42+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -811,9 +811,6 @@ msgid ""
msgstr ""
#: katalogus/templates/katalogus_settings.html
-#: reports/templates/partials/export_report_settings.html
-#: reports/templates/partials/report_setup_scan.html
-#: reports/templates/partials/report_types_selection.html
#: rocky/templates/two_factor/core/otp_required.html
msgid "Go back"
msgstr ""
@@ -3580,11 +3577,6 @@ msgstr ""
msgid "Set up the required plugins for this report."
msgstr ""
-#: reports/templates/partials/report_setup_scan.html
-#: reports/templates/partials/report_types_selection.html
-msgid "Change selection"
-msgstr ""
-
#: reports/templates/partials/report_setup_scan.html
msgid "Plugins"
msgstr ""
@@ -3703,6 +3695,10 @@ msgid_plural "You have selected %(total_oois)s objects in previous step."
msgstr[0] ""
msgstr[1] ""
+#: reports/templates/partials/report_types_selection.html
+msgid "Change selection"
+msgstr ""
+
#: reports/templates/partials/report_types_selection.html
msgid "Available report types"
msgstr ""
@@ -3715,6 +3711,11 @@ msgstr ""
msgid "Toggle all report types"
msgstr ""
+#: reports/templates/partials/return_button.html
+#, python-format
+msgid "%(btn_text)s"
+msgstr ""
+
#: reports/templates/report_overview/report_history.html
#: reports/views/report_overview.py
msgid "Reports history"
@@ -3909,15 +3910,14 @@ msgstr ""
msgid "Save report"
msgstr ""
-#: reports/views/aggregate_report.py reports/views/base.py
-#: reports/views/generate_report.py reports/views/multi_report.py
-msgid "Select at least one report type to proceed."
-msgstr ""
-
#: reports/views/base.py
msgid "Select at least one OOI to proceed."
msgstr ""
+#: reports/views/base.py reports/views/multi_report.py
+msgid "Select at least one report type to proceed."
+msgstr ""
+
#: reports/views/base.py
#, python-format
msgid "Report type '%s' does not exist."
diff --git a/rocky/tests/reports/test_aggregate_report_flow.py b/rocky/tests/reports/test_aggregate_report_flow.py
index a24458a9f2b..f3c6610cbf8 100644
--- a/rocky/tests/reports/test_aggregate_report_flow.py
+++ b/rocky/tests/reports/test_aggregate_report_flow.py
@@ -218,8 +218,9 @@ def test_report_types_selection(
response = SetupScanAggregateReportView.as_view()(request, organization_code=client_member.organization.code)
- assert response.status_code == 302 # if all plugins are enabled the view will auto redirect to generate report
- assert "report_id=Report" in response.url
+ assert response.status_code == 200 # if all plugins are enabled the view will auto redirect to generate report
+
+ assertContains(response, '', html=True)
def test_save_aggregate_report_view(
@@ -256,6 +257,8 @@ def test_save_aggregate_report_view(
"observed_at": valid_time.strftime("%Y-%m-%d"),
"ooi": "all",
"report_type": ["systems-report", "dns-report"],
+ "old_report_name": ["Aggregate Report"],
+ "report_name": ["Testing a new name for Aggregate Report"],
},
),
client_member.user,
diff --git a/rocky/tests/reports/test_generate_report_flow.py b/rocky/tests/reports/test_generate_report_flow.py
index ec9a6213c5d..1271a69bff7 100644
--- a/rocky/tests/reports/test_generate_report_flow.py
+++ b/rocky/tests/reports/test_generate_report_flow.py
@@ -214,8 +214,8 @@ def test_report_types_selection(
response = SetupScanGenerateReportView.as_view()(request, organization_code=client_member.organization.code)
- assert response.status_code == 302 # plugin is enabled so redirect to generate report view
- assert "report_id=Report" in response.url
+ assert response.status_code == 200
+ assertContains(response, '', html=True)
def test_save_generate_report_view(
@@ -241,10 +241,18 @@ def test_save_generate_report_view(
count=len(listed_hostnames), items=listed_hostnames
)
+ old_report_names = [f"DNS report for {ooi.name}" for ooi in listed_hostnames]
+
request = setup_request(
rf.post(
"generate_report_view",
- {"observed_at": valid_time.strftime("%Y-%m-%d"), "ooi": "all", "report_type": "dns-report"},
+ {
+ "observed_at": valid_time.strftime("%Y-%m-%d"),
+ "ooi": "all",
+ "report_type": "dns-report",
+ "old_report_name": old_report_names,
+ "report_name": [f"DNS report for {len(listed_hostnames)} objects"],
+ },
),
client_member.user,
)
diff --git a/rocky/tests/reports/test_plugins.py b/rocky/tests/reports/test_plugins.py
index d699d616260..9343f181931 100644
--- a/rocky/tests/reports/test_plugins.py
+++ b/rocky/tests/reports/test_plugins.py
@@ -41,5 +41,5 @@ def test_generate_report_setup_scan_wrong_plugin_id(
response = SetupScanGenerateReportView.as_view()(request, organization_code=client_member.organization.code)
- assert response.status_code == 302
+ assert response.status_code == 200
assert list(request._messages)[0].message == "A HTTP error occurred. Check logs for more info."