Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change report flow to POST requests #3174

Merged
merged 29 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d3cb3b1
Add first changed to post request
Rieven Jun 24, 2024
2817427
Changes for selecting oois
Rieven Jul 1, 2024
5ff34bc
Post request for select oois and slect report type
Rieven Jul 2, 2024
68f3fe2
revert back part 2 changes
Rieven Jul 2, 2024
928b3b8
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Jul 3, 2024
6f78737
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Jul 3, 2024
07033e5
Changes to aggregate and multi report needed
Rieven Jul 3, 2024
dabe2fc
Fix test for onboarding
Rieven Jul 3, 2024
ea12f0e
Fixes for part 1 and review
Rieven Jul 3, 2024
46e7502
Add double quotes for value
Rieven Jul 3, 2024
cacab42
Set back disbaled state button onboarding
Rieven Jul 3, 2024
fb82600
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Jul 4, 2024
527b46c
fix test
Rieven Jul 4, 2024
a20d460
Merge branch 'feat/report-flow-post-request-part-1' of github.com:min…
Rieven Jul 4, 2024
7f8c172
add test
Rieven Jul 8, 2024
b92dd3a
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Jul 8, 2024
8719237
rename test file
Rieven Jul 8, 2024
7ccbaa4
Add test for aggregate flow
Rieven Jul 8, 2024
45a0581
Fix get oois
Rieven Jul 18, 2024
0dcbd4c
Fix oois selection for all oois
Rieven Jul 18, 2024
45ba11c
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Jul 18, 2024
d045e3f
Merge branch 'main' into feat/report-flow-post-request-part-1
TwistMeister Jul 18, 2024
c42ae28
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Jul 18, 2024
353bee5
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Jul 22, 2024
4f77c7b
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Jul 24, 2024
3680b09
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Aug 5, 2024
5c8e4d6
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Aug 5, 2024
b3e1041
Part 2: Change report flow to POST request for Setup Scan and Saving …
Rieven Aug 5, 2024
4387e10
Merge branch 'main' into feat/report-flow-post-request-part-1
Rieven Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions rocky/onboarding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ class OnboardingReportView(
current_step = 4
permission_required = "tools.can_scan_organization"

def get_oois_pk(self) -> list[str]:
"""
Gets the Hostname primary key out of the URL object specified by the ooi query parameter.
"""
ooi_pk = self.request.GET.get("ooi", "")
ooi = self.get_ooi(ooi_pk)

return [Hostname(name=ooi.web_url.tokenized["netloc"]["name"], network=ooi.network).primary_key]
def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
ooi = self.get_ooi(self.request.GET.get("ooi", ""))
self.oois = [Hostname(name=ooi.web_url.tokenized["netloc"]["name"], network=ooi.network)]
self.selected_oois = [self.oois[0].primary_key]

def get_report_type_selection(self) -> list[str]:
return [self.request.GET.get("report_type", "")]

def post(self, request, *args, **kwargs):
self.set_member_onboarded()
Expand Down
23 changes: 15 additions & 8 deletions rocky/reports/templates/partials/report_ooi_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load static %}

<section>
<div>
Expand All @@ -19,7 +20,7 @@ <h2>
{% for filter, value in active_filters.items %}<strong>{{ filter }}</strong>{{ value|title }}&nbsp;{% endfor %}
{% endif %}
</p>
{% if not object_list %}
{% if not ooi_list %}
<p>{% translate "No objects found." %}</p>
<div class="button-container">
<a class="button"
Expand All @@ -28,7 +29,7 @@ <h2>
href="{% url 'ooi_list' organization_code=organization.code %}">{% translate "Go to the object page" %}</a>
</div>
{% else %}
{% if "all" in request.GET.ooi %}
{% if "all" in selected_oois %}
<div class="horizontal-view horizontal-scroll toolbar start">
<p class="de-emphasized">{{ total_oois }} {% translate "objects selected" %}</p>
<a class="select_all_objects_element">{% translate "Deselect all objects" %}</a>
Expand All @@ -54,9 +55,11 @@ <h2>
</div>
</div>
{% endif %}
<form method="get"
<form novalidate
method="post"
action="{{ next }}"
class="inline layout-wide checkboxes_required">
class="inline layout-wide">
{% csrf_token %}
{% if "all" in selected_oois %}
{% include "forms/report_form_fields.html" %}

Expand All @@ -70,18 +73,22 @@ <h2>
<th>
<input class="select_all_objects_element"
type="checkbox"
{% if "all" in request.GET.ooi %}checked{% endif %}>
{% if "all" in selected_oois %}checked{% endif %}>
</th>
<th>{% translate "Object" %}</th>
<th>{% translate "Type" %}</th>
<th>{% translate "Clearance level" %}</th>
<th>{% translate "Clearance type" %}</th>
</thead>
<tbody>
{% for object in object_list %}
{% for object in ooi_list %}
<tr>
<td>
<input type="checkbox" id="submit-form" name="ooi" value={{ object.primary_key }} {% if object.primary_key in selected_oois or "all" in request.GET.ooi %}checked{% endif %} {% if "all" in request.GET.ooi %}disabled{% endif %}>
<input type="checkbox"
name="ooi"
value="{{ object.primary_key }}"
{% if object.primary_key in selected_oois or "all" in selected_oois %}checked{% endif %}
{% if "all" in selected_oois %}disabled{% endif %}>
</td>
<td>{{ object.human_readable }}</td>
<td>{{ object.ooi_type }}</td>
Expand All @@ -103,7 +110,7 @@ <h2>
{% endif %}
</div>
</section>
<form id="select_all_objects_form" class="inline" method="get">
<form novalidate id="select_all_objects_form" class="inline" method="get">
underdarknl marked this conversation as resolved.
Show resolved Hide resolved
{% include "forms/report_form_fields.html" with selected_oois=None %}

{% if "all" not in selected_oois %}<input type="hidden" name="ooi" value="all">{% endif %}
Expand Down
77 changes: 42 additions & 35 deletions rocky/reports/templates/partials/report_types_selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>{% translate "Choose report types" %}</h1>
improvements are needed.
{% endblocktranslate %}
</p>
{% if not oois %}
{% if not selected_oois %}
<a class="button ghost" href="{{ previous }}">
<span class="icon ti-chevron-left"></span>{% translate "Go back" %}
</a>
Expand All @@ -25,46 +25,53 @@ <h2>
Selected objects ({{ total_oois }})
{% endblocktranslate %}
</h2>
{% if 'all' in selected_oois %}
<p>
{% blocktranslate trimmed count counter=oois|length %}
You have selected {{ total_oois }} object in previous step.
{% plural %}
You have selected {{ total_oois }} objects in previous step.
{% endblocktranslate %}
</p>
{% else %}
<p>
{% blocktranslate trimmed count counter=oois|length %}
You have selected {{ total_oois }} object in previous step.
{% plural %}
You have selected {{ total_oois }} objects in previous step.
{% endblocktranslate %}
</p>
{% if not "all" in selected_oois %}
{% include "summary/ooi_selection.html" %}

{% endif %}
<a href="{{ previous }}" class="button ghost">
{% endif %}
<form novalidate
method="post"
action="{{ previous }}"
class="inline layout-wide">
{% csrf_token %}
{% include "forms/report_form_fields.html" %}

<button type="submit" class="button ghost">
<span class="icon ti-chevron-left"></span>{% translate "Change selection" %}
</a>
{% if available_report_types_aggregate %}
<h2>{% translate "Available report types" %} ({{ count_available_report_types_aggregate }})</h2>
{% else %}
<h2>{% translate "Available report types" %} ({{ available_report_types|length }})</h2>
{% endif %}
<p>{% translate "All report types that are available for your selection." %}</p>
<a class="toggle-all" data-toggle-target="report_type">{% translate "Toggle all report types" %}</a>
<form class="inline layout-wide checkboxes_required"
method="get"
action="{{ next }}">
{% include "forms/report_form_fields.html" %}
</button>
</form>
{% if available_report_types_aggregate %}
<h2>{% translate "Available report types" %} ({{ count_available_report_types_aggregate }})</h2>
{% else %}
<h2>{% translate "Available report types" %} ({{ available_report_types|length }})</h2>
{% endif %}
<p>{% translate "All report types that are available for your selection." %}</p>
<a class="toggle-all" data-toggle-target="report_type">{% translate "Toggle all report types" %}</a>
<form class="inline layout-wide checkboxes_required"
method="get"
action="{{ next }}">
{% include "forms/report_form_fields.html" %}

<div class="column-4 tiles">
{% if available_report_types_aggregate %}
{% include "partials/report_types_tiles_required_optional.html" with report_types=available_report_types_aggregate %}
<div class="column-4 tiles">
{% if available_report_types_aggregate %}
{% include "partials/report_types_tiles_required_optional.html" with report_types=available_report_types_aggregate %}

{% else %}
{% include "partials/report_types_tiles.html" with report_types=available_report_types %}
{% else %}
{% include "partials/report_types_tiles.html" with report_types=available_report_types %}

{% endif %}
</div>
<button type="submit">
{% translate "Continue with selection" %}<span class="icon ti-chevron-right"></span>
</button>
</form>
{% endif %}
{% endif %}
</div>
<button type="submit">
{% translate "Continue with selection" %}<span class="icon ti-chevron-right"></span>
</button>
</form>
</div>
</section>
35 changes: 17 additions & 18 deletions rocky/reports/views/aggregate_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Sequence
from datetime import datetime, timezone
from typing import Any

Expand All @@ -8,19 +7,18 @@
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from octopoes.models import ScanProfileType
from octopoes.models.ooi.reports import Report as ReportOOI
from reports.report_types.aggregate_organisation_report.report import AggregateOrganisationReport, aggregate_reports
from reports.report_types.definitions import Report
from reports.report_types.definitions import AggregateReport, MultiReport, Report
from reports.report_types.helpers import get_ooi_types_from_aggregate_report, get_report_types_from_aggregate_report
from reports.views.base import (
REPORTS_PRE_SELECTION,
OOISelectionView,
ReportBreadcrumbs,
ReportOOIView,
ReportPluginView,
ReportTypeView,
ReportTypeSelectionView,
get_selection,
)
from reports.views.view_helpers import AggregateReportStepsMixin
Expand Down Expand Up @@ -74,10 +72,7 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:


class OOISelectionAggregateReportView(
AggregateReportStepsMixin,
BreadcrumbsAggregateReportView,
ReportOOIView,
BaseOOIListView,
AggregateReportStepsMixin, BreadcrumbsAggregateReportView, BaseOOIListView, OOISelectionView
):
"""
Select Objects for the 'Aggregate Report' flow.
Expand All @@ -88,19 +83,22 @@ class OOISelectionAggregateReportView(
current_step = 1
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)

def post(self, request, *args, **kwargs):
if not self.selected_oois:
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return self.get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update(self.get_ooi_filter_forms(self.ooi_types))
context["channel"] = "aggregate_report"
return context


class ReportTypesSelectionAggregateReportView(
AggregateReportStepsMixin,
BreadcrumbsAggregateReportView,
ReportOOIView,
ReportTypeView,
TemplateView,
OOISelectionView,
ReportTypeSelectionView,
):
"""
Shows all possible report types from a list of Objects.
Expand All @@ -118,10 +116,11 @@ def setup(self, request, *args, **kwargs):
get_report_types_from_aggregate_report(AggregateOrganisationReport)
)

def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
if not self.selected_oois:
messages.error(self.request, _("Select at least one OOI to proceed."))
return super().get(request, *args, **kwargs)
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return redirect(self.get_previous())
return self.get(request, *args, **kwargs)

def get_report_types_for_aggregate_report(
self, reports_dict: dict[str, set[type[Report]]]
Expand Down Expand Up @@ -262,9 +261,9 @@ class SaveAggregateReportView(SaveAggregateReportMixin, BreadcrumbsAggregateRepo
Save the report and redirect to the saved report
"""

current_step = 5
current_step = 6
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)
report_types: Sequence[type[Report]]
report_types: list[type[Report] | type[MultiReport] | type[AggregateReport]]

def post(self, request, *args, **kwargs):
old_report_names = request.POST.getlist("old_report_name")
Expand Down
Loading