From 30650bc853fc89b1a4a176fe9014099891c6d0d1 Mon Sep 17 00:00:00 2001 From: kiblik <5609770+kiblik@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:17:37 +0200 Subject: [PATCH] fix rendering of disc. in report --- .../0218_system_settings_disclaimer_notif.py | 38 ------------------- .../0219_system_settings_disclaimer_notif.py | 37 +++++++++++++----- .../0220_system_settings_disclaimer_notif.py | 21 ++++++++++ dojo/reports/views.py | 9 ++++- dojo/templates/dojo/custom_html_report.html | 6 +++ dojo/templates/dojo/endpoint_pdf_report.html | 2 +- .../templates/dojo/engagement_pdf_report.html | 2 +- dojo/templates/dojo/finding_pdf_report.html | 2 +- .../dojo/product_endpoint_pdf_report.html | 2 +- dojo/templates/dojo/product_pdf_report.html | 2 +- .../dojo/product_type_pdf_report.html | 2 +- dojo/templates/dojo/test_pdf_report.html | 2 +- 12 files changed, 69 insertions(+), 56 deletions(-) delete mode 100644 dojo/db_migrations/0218_system_settings_disclaimer_notif.py create mode 100644 dojo/db_migrations/0220_system_settings_disclaimer_notif.py diff --git a/dojo/db_migrations/0218_system_settings_disclaimer_notif.py b/dojo/db_migrations/0218_system_settings_disclaimer_notif.py deleted file mode 100644 index 6d966e414a0..00000000000 --- a/dojo/db_migrations/0218_system_settings_disclaimer_notif.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 5.0.8 on 2024-09-12 18:22 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('dojo', '0217_jira_project_enabled'), - ] - - operations = [ - migrations.RenameField( - model_name='system_settings', - old_name='disclaimer', - new_name='disclaimer_notifications', - ), - migrations.AlterField( - model_name='system_settings', - name='disclaimer_notifications', - field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer on all notifications', max_length=3000, verbose_name='Custom Disclaimer for Notifications'), - ), - migrations.AddField( - model_name='system_settings', - name='disclaimer_reports', - field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer on generated reports', max_length=5000, verbose_name='Custom Disclaimer for Reports'), - ), - migrations.AddField( - model_name='system_settings', - name='disclaimer_notes', - field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer next to input form for notes', max_length=3000, verbose_name='Custom Disclaimer for Notes'), - ), - migrations.AddField( - model_name='system_settings', - name='disclaimer_reports_forced', - field=models.BooleanField(default=False, help_text="Disclaimer will be added to all reports even if user didn't selected 'Include disclaimer'.", verbose_name='Force to add disclaimer reports'), - ), - ] diff --git a/dojo/db_migrations/0219_system_settings_disclaimer_notif.py b/dojo/db_migrations/0219_system_settings_disclaimer_notif.py index 84aeffe4b03..4f57cad2f13 100644 --- a/dojo/db_migrations/0219_system_settings_disclaimer_notif.py +++ b/dojo/db_migrations/0219_system_settings_disclaimer_notif.py @@ -1,21 +1,38 @@ # Generated by Django 5.0.8 on 2024-09-12 18:22 -from django.db import migrations - - -def copy_notif_field(apps, schema_editor): - system_settings_model = apps.get_model('dojo', 'System_Settings').objects.get() - if system_settings_model.disclaimer_notifications: - system_settings_model.disclaimer_reports = system_settings_model.disclaimer_notifications - system_settings_model.save() +from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('dojo', '0218_system_settings_disclaimer_notif'), + ('dojo', '0218_system_settings_enforce_verified_status_and_more'), ] operations = [ - migrations.RunPython(copy_notif_field), + migrations.RenameField( + model_name='system_settings', + old_name='disclaimer', + new_name='disclaimer_notifications', + ), + migrations.AlterField( + model_name='system_settings', + name='disclaimer_notifications', + field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer on all notifications', max_length=3000, verbose_name='Custom Disclaimer for Notifications'), + ), + migrations.AddField( + model_name='system_settings', + name='disclaimer_reports', + field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer on generated reports', max_length=5000, verbose_name='Custom Disclaimer for Reports'), + ), + migrations.AddField( + model_name='system_settings', + name='disclaimer_notes', + field=models.TextField(blank=True, default='', help_text='Include this custom disclaimer next to input form for notes', max_length=3000, verbose_name='Custom Disclaimer for Notes'), + ), + migrations.AddField( + model_name='system_settings', + name='disclaimer_reports_forced', + field=models.BooleanField(default=False, help_text="Disclaimer will be added to all reports even if user didn't selected 'Include disclaimer'.", verbose_name='Force to add disclaimer reports'), + ), ] diff --git a/dojo/db_migrations/0220_system_settings_disclaimer_notif.py b/dojo/db_migrations/0220_system_settings_disclaimer_notif.py new file mode 100644 index 00000000000..ceb126d6ab3 --- /dev/null +++ b/dojo/db_migrations/0220_system_settings_disclaimer_notif.py @@ -0,0 +1,21 @@ +# Generated by Django 5.0.8 on 2024-09-12 18:22 + +from django.db import migrations + + +def copy_notif_field(apps, schema_editor): + system_settings_model = apps.get_model('dojo', 'System_Settings').objects.get() + if system_settings_model.disclaimer_notifications: + system_settings_model.disclaimer_reports = system_settings_model.disclaimer_notifications + system_settings_model.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('dojo', '0219_system_settings_disclaimer_notif'), + ] + + operations = [ + migrations.RunPython(copy_notif_field), + ] diff --git a/dojo/reports/views.py b/dojo/reports/views.py index 0d6d571c38d..e5ae59a0020 100644 --- a/dojo/reports/views.py +++ b/dojo/reports/views.py @@ -132,6 +132,10 @@ def _set_state(self, request: HttpRequest): self.host = report_url_resolver(request) self.selected_widgets = self.get_selected_widgets(request) self.widgets = list(self.selected_widgets.values()) + self.include_disclaimer = get_system_setting("disclaimer_reports_forced", 0) + self.disclaimer = get_system_setting("disclaimer_reports") + if self.include_disclaimer and len(self.disclaimer) == 0: + self.disclaimer = "Please configure in System Settings." def get_selected_widgets(self, request): selected_widgets = report_widget_factory(json_data=request.POST["json"], request=request, host=self.host, @@ -164,7 +168,10 @@ def get_context(self): "host": self.host, "finding_notes": self.finding_notes, "finding_images": self.finding_images, - "user_id": self.request.user.id} + "user_id": self.request.user.id, + "include_disclaimer": self.include_disclaimer, + "disclaimer": self.disclaimer, + } def report_findings(request): diff --git a/dojo/templates/dojo/custom_html_report.html b/dojo/templates/dojo/custom_html_report.html index de89837f747..db7b4e3c070 100644 --- a/dojo/templates/dojo/custom_html_report.html +++ b/dojo/templates/dojo/custom_html_report.html @@ -3,6 +3,12 @@ {% block content %} {{ block.super }}
+ {% if include_disclaimer %} +
+ Disclaimer
+

{{ disclaimer | safe }}

+
+ {% endif %} {% for widget in widgets %} {{ widget.get_html }} {% endfor %} diff --git a/dojo/templates/dojo/endpoint_pdf_report.html b/dojo/templates/dojo/endpoint_pdf_report.html index b214afadb35..10cf2804c97 100644 --- a/dojo/templates/dojo/endpoint_pdf_report.html +++ b/dojo/templates/dojo/endpoint_pdf_report.html @@ -81,7 +81,7 @@
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/engagement_pdf_report.html b/dojo/templates/dojo/engagement_pdf_report.html index a9c8ac8101c..ff341274354 100644 --- a/dojo/templates/dojo/engagement_pdf_report.html +++ b/dojo/templates/dojo/engagement_pdf_report.html @@ -158,7 +158,7 @@
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/finding_pdf_report.html b/dojo/templates/dojo/finding_pdf_report.html index 6d376c15bcb..ea051d43d0e 100644 --- a/dojo/templates/dojo/finding_pdf_report.html +++ b/dojo/templates/dojo/finding_pdf_report.html @@ -57,7 +57,7 @@
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/product_endpoint_pdf_report.html b/dojo/templates/dojo/product_endpoint_pdf_report.html index 614fa0f00f4..0a1cb6e5237 100644 --- a/dojo/templates/dojo/product_endpoint_pdf_report.html +++ b/dojo/templates/dojo/product_endpoint_pdf_report.html @@ -119,7 +119,7 @@
Finding Age
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/product_pdf_report.html b/dojo/templates/dojo/product_pdf_report.html index b02b2609de6..25480502757 100644 --- a/dojo/templates/dojo/product_pdf_report.html +++ b/dojo/templates/dojo/product_pdf_report.html @@ -142,7 +142,7 @@
Finding Age
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/product_type_pdf_report.html b/dojo/templates/dojo/product_type_pdf_report.html index 4b0fc48d9fc..ec550d1524b 100644 --- a/dojo/templates/dojo/product_type_pdf_report.html +++ b/dojo/templates/dojo/product_type_pdf_report.html @@ -114,7 +114,7 @@

{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}
diff --git a/dojo/templates/dojo/test_pdf_report.html b/dojo/templates/dojo/test_pdf_report.html index e9ec79d6aa9..b1d1cd7b5fa 100644 --- a/dojo/templates/dojo/test_pdf_report.html +++ b/dojo/templates/dojo/test_pdf_report.html @@ -146,7 +146,7 @@
{% if include_disclaimer%}
Disclaimer
-

{{ disclaimer }}

+

{{ disclaimer | safe }}

{% endif %}