Skip to content

Commit 13671fa

Browse files
committed
Add infer_download_urls option to Scan all packages
Signed-off-by: tdruez <[email protected]>
1 parent 8d465a8 commit 13671fa

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

product_portfolio/forms.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,3 +1016,25 @@ def submit(self, product, user):
10161016
scancodeproject_uuid=scancode_project.uuid,
10171017
)
10181018
)
1019+
1020+
1021+
class ScanAllPackagesForm(forms.Form):
1022+
infer_download_urls = forms.BooleanField(
1023+
label=_("Infer missing download URLs"),
1024+
required=False,
1025+
initial=True,
1026+
help_text=_(
1027+
"When a download URL is missing for packages, attempt to infer it "
1028+
"from the Package URL (purl). "
1029+
"A download URL is required for package scanning."
1030+
),
1031+
)
1032+
1033+
@property
1034+
def helper(self):
1035+
helper = FormHelper()
1036+
helper.form_method = "post"
1037+
helper.form_id = "scan-all-packages-form"
1038+
helper.attrs = {"autocomplete": "off"}
1039+
helper.layout = Layout("infer_download_urls")
1040+
return helper
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1+
{% load crispy_forms_tags %}
12
<div class="modal" tabindex="-1" role="dialog" id="scan-all-packages-modal">
2-
<div class="modal-dialog" role="document">
3-
<div class="modal-content">
4-
<div class="modal-header">
5-
<h5 class="modal-title">Scan all Packages</h5>
6-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
7-
</div>
8-
<div class="modal-body bg-body-tertiary">
9-
You are about to initiate multiple scans on the ScanCode.io server for all the
10-
Packages assigned to your Product, either by direct assignment or by assignment to a
11-
Component assigned to your Product.<br><br>
12-
<strong>Note that this may take some time to complete.</strong><br><br>
13-
You can view the status of all the scans by selecting the
14-
<a target="_blank" href="{% url 'component_catalog:scan_list' %}">Scans</a> option
15-
from the DejaCode Tools dropdown menu, where you can also select each Package in the list
16-
to view scan results details in the "Scan" tab of that Package.
17-
</div>
18-
<div class="modal-footer">
19-
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
20-
<a id="scan_all_packages_submit" href="{{ object.get_scan_all_packages_url }}" class="btn btn-success">Submit Scan Request</a>
3+
<form autocomplete="off" method="{{ scan_all_packages_form.helper.form_method }}" action="{{ object.get_scan_all_packages_url }}" id="{{ scan_all_packages_form.helper.form_id }}">
4+
<div class="modal-dialog" role="document">
5+
<div class="modal-content">
6+
<div class="modal-header">
7+
<h5 class="modal-title">Scan all Packages</h5>
8+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
9+
</div>
10+
<div class="modal-body bg-body-tertiary">
11+
<p>
12+
You are about to initiate multiple scans on the ScanCode.io server for all the
13+
Packages assigned to your Product, either by direct assignment or by assignment to a
14+
Component assigned to your Product.
15+
</p>
16+
<p>
17+
<strong>Note that this may take some time to complete.</strong>
18+
</p>
19+
<p>
20+
You can view the status of all the scans by selecting the
21+
<a target="_blank" href="{% url 'component_catalog:scan_list' %}">Scans</a> option
22+
from the DejaCode Tools dropdown menu, where you can also select each Package in the list
23+
to view scan results details in the "Scan" tab of that Package.
24+
</p>
25+
<hr>
26+
{% crispy scan_all_packages_form %}
27+
</div>
28+
<div class="modal-footer">
29+
<input type="button" name="close" value="Close" class="btn btn-secondary" data-bs-dismiss="modal">
30+
<input type="submit" id="scan_all_packages_submit" value="Submit Scan Request" class="btn btn-primary btn-success">
31+
</div>
2132
</div>
2233
</div>
23-
</div>
34+
</form>
2435
</div>

product_portfolio/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
from product_portfolio.forms import ProductPackageForm
127127
from product_portfolio.forms import ProductPackageInlineForm
128128
from product_portfolio.forms import PullProjectDataForm
129+
from product_portfolio.forms import ScanAllPackagesForm
129130
from product_portfolio.forms import TableInlineFormSetHelper
130131
from product_portfolio.models import RELATION_LICENSE_EXPRESSION_HELP_TEXT
131132
from product_portfolio.models import CodebaseResource
@@ -715,6 +716,7 @@ def get_context_data(self, **kwargs):
715716
if include_scancodeio_features:
716717
context["pull_project_data_form"] = PullProjectDataForm()
717718
context["display_scan_features"] = True
719+
context["scan_all_packages_form"] = ScanAllPackagesForm()
718720

719721
context["purldb_enabled"] = all(
720722
[
@@ -1961,6 +1963,7 @@ class ProductExportOpenVEXView(BaseProductViewMixin, ExportOpenVEXView):
19611963
pass
19621964

19631965

1966+
@require_POST
19641967
@login_required
19651968
def scan_all_packages_view(request, dataspace, name, version=""):
19661969
user = request.user
@@ -1981,7 +1984,13 @@ def scan_all_packages_view(request, dataspace, name, version=""):
19811984
if not product.all_packages:
19821985
raise Http404("No packages available for this product.")
19831986

1984-
transaction.on_commit(lambda: product.scan_all_packages_task(user))
1987+
scan_all_packages_form = ScanAllPackagesForm(data=request.POST)
1988+
if not scan_all_packages_form.is_valid():
1989+
raise Http404
1990+
1991+
infer_download_urls = scan_all_packages_form.cleaned_data.get("infer_download_urls")
1992+
1993+
transaction.on_commit(lambda: product.scan_all_packages_task(user, infer_download_urls))
19851994

19861995
scan_list_url = reverse("component_catalog:scan_list")
19871996
scancode_msg = format_html(

0 commit comments

Comments
 (0)